Skip to content

Commit 0751c65

Browse files
committed
feat(config): allow defining files via flag
1 parent 951cd46 commit 0751c65

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,21 @@ index.js es-check <ecmaVersion> [files...]
133133
**Not**
134134

135135
```sh
136-
--not=folderName1,folderName2 An array of file/folder names or globs that you would like to ignore. Defaults to `[]`.
136+
137+
--not=target1,target2 An array of file/folder names or globs that you would like to ignore. Defaults to `[]`.
138+
137139
```
138140

141+
**Files**
142+
143+
```sh
144+
145+
--files=target1,target2 An array of file/folder names or globs to test the ECMAScript version against. Alias of [...files] argument.
146+
147+
```
148+
149+
⚠️ **NOTE:** This is primarily intended as a way to override the `files` setting in the `.escheckrc` file for specific invocations. Setting both the `[...files]` argument and `--files` flag is an error.
150+
139151
### Global Options
140152

141153
```sh

index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ program
3030
.argument('[files...]', 'a glob of files to to test the EcmaScript version against')
3131
.option('--module', 'use ES modules')
3232
.option('--allow-hash-bang', 'if the code starts with #! treat it as a comment')
33+
.option('--files <files>', 'a glob of files to to test the EcmaScript version against (alias for [files...])')
3334
.option('--not <files>', 'folder or file names to skip')
3435
.option('--no-color', 'disable use of colors in output')
3536
.option('-v, --verbose', 'verbose mode: will also output debug messages')
@@ -53,6 +54,11 @@ program
5354

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

57+
if (filesArg && filesArg.length && options.files) {
58+
logger.error('Cannot pass in both [files...] argument and --files flag at the same time!')
59+
process.exit(1)
60+
}
61+
5662
/**
5763
* @note
5864
* Check for a configuration file.
@@ -61,7 +67,8 @@ program
6167
*/
6268
const config = fs.existsSync(configFilePath) ? JSON.parse(fs.readFileSync(configFilePath)) : {}
6369
const expectedEcmaVersion = ecmaVersionArg ? ecmaVersionArg : config.ecmaVersion
64-
const files = filesArg && filesArg.length ? filesArg : [].concat(config.files)
70+
const files =
71+
filesArg && filesArg.length ? filesArg : options.files ? options.files.split(',') : [].concat(config.files)
6572
const esmodule = options.module ? options.module : config.module
6673
const allowHashBang = options.allowHashBang ? options.allowHashBang : config.allowHashBang
6774
const pathsToIgnore = options.not ? options.not.split(',') : [].concat(config.not || [])

test.js

+32
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,35 @@ describe('Es Check skips folders and files included in the not flag', () => {
201201
})
202202
})
203203
})
204+
205+
describe('Es Check supports the --files flag', () => {
206+
it('🎉 Es Check should pass when checking a glob with es6 modules as es6 using the --files flag', (done) => {
207+
exec('node index.js es6 --files=./tests/*.js', (err, stdout, stderr) => {
208+
assert(stdout)
209+
if (err) {
210+
console.error(err.stack)
211+
console.error(stdout.toString())
212+
console.error(stderr.toString())
213+
done(err)
214+
return
215+
}
216+
done()
217+
})
218+
})
219+
220+
it('👌 Es Check should fail when checking a glob with es6 modules as es5 using the --files flag', (done) => {
221+
exec('node index.js es5 --files=./tests/*.js', (err, stdout, stderr) => {
222+
assert(err)
223+
console.log(stdout)
224+
done()
225+
})
226+
})
227+
228+
it('👌 Es Check should fail when given both spread files and --files flag', (done) => {
229+
exec('node index.js es6 ./tests/*.js --files=./tests/*.js', (err, stdout, stderr) => {
230+
assert(err)
231+
console.log(stdout)
232+
done()
233+
})
234+
})
235+
})

0 commit comments

Comments
 (0)