Skip to content

Commit

Permalink
feat(index): Add not option to filter files (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisispaul authored and yowainwright committed Nov 13, 2019
1 parent f137c6a commit f709c3b
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 1,013 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ index.js es-check <ecmaVersion> [files...]

```

**Not**
```sh
--not=folderName1,folderName2 An array of file/folder names that you would like to ignore. Defaults to `[]`.
```

### Global Options

```sh
Expand Down
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ prog
)
.option('--module', 'use ES modules')
.option('--allow-hash-bang', 'if the code starts with #! treat it as a comment')
.option('--not', 'folder or file names to skip', prog.LIST)
.action((args, options, logger) => {

const configFilePath = path.resolve(process.cwd(), '.escheckrc')

let v, files, e, esmodule, allowHashBang
let v, files, e, esmodule, allowHashBang, pathsToIgnore
let config = {}

/**
Expand All @@ -61,6 +62,10 @@ prog
? options.allowHashBang
: config.allowHashBang

pathsToIgnore = options.not
? options.not
: config.not

if (!v) {
logger.error(
'No ecmaScript version passed in or found in .escheckrc. Please set your ecmaScript version in the CLI or in .escheckrc'
Expand Down Expand Up @@ -128,6 +133,14 @@ prog
const errArray = []
const globOpts = { nodir: true }
const acornOpts = { ecmaVersion: e, silent: true }
const filterForIgnore = (globbedFiles) => {
if (pathsToIgnore && pathsToIgnore.length > 0) {
const filtered = globbedFiles.filter((filePath) => !pathsToIgnore
.some(ignoreValue => filePath.includes(ignoreValue)))
return filtered;
}
return globbedFiles;
}

logger.debug(`ES-Check: Going to check files using version ${e}`)

Expand All @@ -152,7 +165,9 @@ prog
process.exit(1);
}

globbedFiles.forEach((file) => {
const filteredFiles = filterForIgnore(globbedFiles);

filteredFiles.forEach((file) => {
const code = fs.readFileSync(file, 'utf8')

logger.debug(`ES-Check: checking ${file}`)
Expand Down
Loading

0 comments on commit f709c3b

Please sign in to comment.