-
-
Notifications
You must be signed in to change notification settings - Fork 423
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): add ignore
config option
#385
Conversation
This allows users to prevent some files from being processed by lint-staged ever. This is useful if your project contains generated files that you commit to the repository, but don't want to process.
Codecov Report
@@ Coverage Diff @@
## master #385 +/- ##
==========================================
+ Coverage 98.1% 98.13% +0.03%
==========================================
Files 10 10
Lines 211 215 +4
Branches 23 26 +3
==========================================
+ Hits 207 211 +4
Misses 4 4
Continue to review full report at Codecov.
|
Hey @kentcdodds, thanks for the PR 😄. I think overall, the feature addition makes sense. I have a minor suggestion. Instead of the multiple filter steps, how about we switch over to |
Sounds fine. What would the API look like to add an ignore? The same? Should we maybe do it in a different pull request in that case? |
I was thinking the API would be the same. We can just concat the ignore patterns(with |
I don't mind making the change. Is this the only place minimatch is used in the codebase? |
Yes, it is only used in However, looks like there are very minor differences in the options for
So we might need to do this change in a separate PR and make a major release to denote the breaking change. I personally do not think these options would be used by anybody so it should be okay to make this change in a minor version. @okonet Could you take a call on this? |
Yes, I'd prefer to do that in a separate PR. Seems unrelated to the core feature I want to add here :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kentcdodds, thanks for the PR 🎉
I have a small suggestion...
README.md
Outdated
@@ -129,6 +129,7 @@ To set options and keep lint-staged extensible, advanced format can be used. Thi | |||
* `chunkSize` — Max allowed chunk size based on number of files for glob pattern. This is important on windows based systems to avoid command length limitations. See [#147](https://github.com/okonet/lint-staged/issues/147) | |||
* `subTaskConcurrency` — `1` — Controls concurrency for processing chunks generated for each linter. Execution is **not** concurrent by default(see [#225](https://github.com/okonet/lint-staged/issues/225)) | |||
* `globOptions` — `{ matchBase: true, dot: true }` — [minimatch options](https://github.com/isaacs/minimatch#options) to customize how glob patterns match files. | |||
* `ignore` - `['**/docs/**/*.js']` - array of glob patterns to entirely ignore from any task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now it makes sense to sort items in options
section alphabetically. So users can find what they need easier.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@kentcdodds thanks for your PR. We have a stalled (my fault!) PR that should be able to make the whole setup more flexible here #273 As @sudo-suhas mentioned we want to transition to micromatch and introduce array syntax to |
@okonet While having the option to include multiple file filter patterns would satisfy the requirement, I think the feature addition of global ignore is still justified. I think one of the good things is that it doesn't require any changes for existing configuration format. Also, do you think the |
Not sure about global ignore tbh if we want to have arrays anyways. Wouldn’t it just add more frustration to have both? Switching glob engine shouldn’t be a major release unless it’s a breaking change. |
Wasn't the use-case of being able to ignore files our strongest motivation for introducing the multiple glob patterns option? Also, cascading rules are quite common(ex:
Please see #385 (comment) |
@sudo-suhas regarding mircomatch: we should do a major release then. No need to take any risks here. Regarding the But again, I'm leaving towards solving one problem at the time and it seems like @kentcdodds solution is good enough for now so let's go ahead with it. |
Requested changes were done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* `concurrent` — *true* — runs linters for each glob pattern simultaneously. If you don’t want this, you can set `concurrent: false` | ||
* `chunkSize` — Max allowed chunk size based on number of files for glob pattern. This is important on windows based systems to avoid command length limitations. See [#147](https://github.com/okonet/lint-staged/issues/147) | ||
* `globOptions` — `{ matchBase: true, dot: true }` — [minimatch options](https://github.com/isaacs/minimatch#options) to | ||
customize how glob patterns match files. | ||
* `ignore` - `['**/docs/**/*.js']` - array of glob patterns to entirely ignore from any task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add something like. Useful to skip linting of generated files.
Closes #310 (I guess?) |
The only thing that just popped in my head is that this PR will prevent us from doing #277 which I'd really love to do since I never was a fan of having multiple config formats. |
#277 might make this obsolete in which case, we can drop it from the global options. Since it will be a breaking change, we can just ask users to move the ignore to each linter's options. |
Not sure if this is a more desired approach in this case. I'd prefer to pull off the #273 instead, TBH. I'm wondering what @kentcdodds has to say if proposed changes would solve his use case. |
Looks like #273 was closed? |
I will need to create a new PR but the discussion is still relevant. |
That looks like it would work fine for me. I just need a way to specify a glob of files I don't want processed. |
What's the status on this? Could we merge it as-is and then iterate to the improvements? |
I still didn’t find to work on it yet. Sorry. |
I second this. Moreover, I have come to have reservations about 'Get rid of advanced config options'. We would be writing ourselves into a corner where every option would have to be at the linters level. This would restrict us in adding options which might make sense to have at the global level. To clarify, I support removing config options like |
Okay let’s go forward with this PR then. @sudo-suhas please go ahead and merge it. |
Merged and released in |
Super! Thank you! |
Thanks @kentcdodds and @sudo-suhas for taking care of this! |
@@ -14,6 +14,12 @@ module.exports = function generateTasks(config, relFiles) { | |||
const normalizedConfig = getConfig(config) // Ensure we have a normalized config | |||
const linters = normalizedConfig.linters | |||
const globOptions = normalizedConfig.globOptions | |||
const ignoreFilters = normalizedConfig.ignore.map(pattern => minimatch.filter(pattern)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This minimatch.filter()
call isn't being passed globOptions
. Is this intentional?
I'm also unable to ignore '.vscode/*.json'
(whereas 'package.json'
in the same ignores
array works fine).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably pass globOptions
I guess 🤔
If we did, then your problem with .vscode
would probably be resolved because you could specify the dot
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not able to reproduce this issue locally:
λ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .vscode/settings.json
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .lintstagedrc
λ cat .lintstagedrc
{
"linters": {
"*.js": [
"eslint --fix",
"git add"
],
".*rc": "jsonlint",
"*.json": "jsonlint"
},
"ignore": [".vscode/*.json"]
}
λ node . --debug
lint-staged:bin Running `[email protected]` +0ms
lint-staged Loading config using `cosmiconfig` +0ms
lint-staged Successfully loaded config from `E:\Projects\repos\lint-staged\.lintstagedrc`:
lint-staged { linters:
lint-staged { '*.js': [ 'eslint --fix', 'git add' ],
lint-staged '.*rc': 'jsonlint',
lint-staged '*.json': 'jsonlint' },
lint-staged ignore: [ '.vscode/*.json' ] } +16ms
lint-staged:cfg Normalizing config +0ms
lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
linters: {
'*.js': [
'eslint --fix',
'git add'
],
'.*rc': 'jsonlint',
'*.json': 'jsonlint'
},
ignore: [
'.vscode/*.json'
],
concurrent: true,
chunkSize: 9007199254740991,
globOptions: {
matchBase: true,
dot: true
},
subTaskConcurrency: 1,
renderer: 'verbose'
}
lint-staged Loaded scripts from package.json:
lint-staged { precommit: 'node index.js',
lint-staged cz: 'git-cz',
lint-staged lint: 'eslint .',
lint-staged 'lint:fix': 'yarn lint --fix',
lint-staged pretest: 'yarn lint',
lint-staged test: 'jest --coverage',
lint-staged 'test:watch': 'jest --watch' } +16ms
lint-staged:run Running all linter scripts +0ms
lint-staged:run Resolved git directory to be `E:\Projects\repos\lint-staged` +15ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [ '.vscode/settings.json' ] +241ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:cfg Normalizing config +272ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '*.js',
lint-staged:gen-tasks commands: [ 'eslint --fix', 'git add' ],
lint-staged:gen-tasks fileList: [] } +0ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '.*rc', commands: 'jsonlint', fileList: [] } +0ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '*.json', commands: 'jsonlint', fileList: [] } +0ms
Running tasks for *.js [started]
Running tasks for .*rc [started]
Running tasks for *.json [started]
Running tasks for *.js [skipped]
→ No staged files match *.js
Running tasks for .*rc [skipped]
→ No staged files match .*rc
Running tasks for *.json [skipped]
→ No staged files match *.json
lint-staged linters were executed successfully! +271ms
Please take a look at your debug logs. It could be a configuration issue. If you continue to face the issue, please do create a new issue.
This allows users to prevent some files from being processed by lint-staged ever. This is useful if your project contains generated files that you commit to the repository, but don't want to process.
I know it's not great to commit generated files, but in this case it's really the best solution for me.
I didn't open an issue for this because I really need this anyway so if it's not merged then I'll just use my own fork.