Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): allow defining files via flag #201

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,21 @@ index.js es-check <ecmaVersion> [files...]
**Not**

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

--not=target1,target2 An array of file/folder names or globs that you would like to ignore. Defaults to `[]`.

Comment on lines +136 to +138
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added surrounding newlines to match pattern elsewhere

```

**Files**

```sh

--files=target1,target2 An array of file/folder names or globs to test the ECMAScript version against. Alias of [...files] argument.

```

⚠️ **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.

### Global Options

```sh
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ program
.argument('[files...]', 'a glob of files to to test the EcmaScript version against')
.option('--module', 'use ES modules')
.option('--allow-hash-bang', 'if the code starts with #! treat it as a comment')
.option('--files <files>', 'a glob of files to to test the EcmaScript version against (alias for [files...])')
Copy link
Author

@merrywhether merrywhether May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't include the -f short flag from the original proposal since it didn't seem to fit with the style of the other flags.

.option('--not <files>', 'folder or file names to skip')
.option('--no-color', 'disable use of colors in output')
.option('-v, --verbose', 'verbose mode: will also output debug messages')
Expand All @@ -53,6 +54,11 @@ program

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

if (filesArg && filesArg.length && options.files) {
logger.error('Cannot pass in both [files...] argument and --files flag at the same time!')
process.exit(1)
}
Comment on lines +57 to +60
Copy link
Author

@merrywhether merrywhether May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd originally thought to have the argument override the flag, but then I could see someone misunderstanding that maybe they got concatenated and it seemed like erroring is the only safe option. Totally open to feedback on this idea or the error message text.


/**
* @note
* Check for a configuration file.
Expand All @@ -61,7 +67,8 @@ program
*/
const config = fs.existsSync(configFilePath) ? JSON.parse(fs.readFileSync(configFilePath)) : {}
const expectedEcmaVersion = ecmaVersionArg ? ecmaVersionArg : config.ecmaVersion
const files = filesArg && filesArg.length ? filesArg : [].concat(config.files)
const files =
filesArg && filesArg.length ? filesArg : options.files ? options.files.split(',') : [].concat(config.files)
const esmodule = options.module ? options.module : config.module
const allowHashBang = options.allowHashBang ? options.allowHashBang : config.allowHashBang
const pathsToIgnore = options.not ? options.not.split(',') : [].concat(config.not || [])
Expand Down
32 changes: 32 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,35 @@ describe('Es Check skips folders and files included in the not flag', () => {
})
})
})

describe('Es Check supports the --files flag', () => {
it('🎉 Es Check should pass when checking a glob with es6 modules as es6 using the --files flag', (done) => {
exec('node index.js es6 --files=./tests/*.js', (err, stdout, stderr) => {
assert(stdout)
if (err) {
console.error(err.stack)
console.error(stdout.toString())
console.error(stderr.toString())
done(err)
return
}
done()
})
})

it('👌 Es Check should fail when checking a glob with es6 modules as es5 using the --files flag', (done) => {
exec('node index.js es5 --files=./tests/*.js', (err, stdout, stderr) => {
assert(err)
console.log(stdout)
done()
})
})

it('👌 Es Check should fail when given both spread files and --files flag', (done) => {
exec('node index.js es6 ./tests/*.js --files=./tests/*.js', (err, stdout, stderr) => {
assert(err)
console.log(stdout)
done()
})
})
})
Loading