-
-
Notifications
You must be signed in to change notification settings - Fork 289
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: apply .ignores
to lintText
#169
Conversation
- add multimatch-powered short-circuit to `lintText` - add supporting test cases - closes #168
}] | ||
}; | ||
} | ||
} |
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 needs to take into account the overrides logic and should be after the below overrides logic. Right now it wouldn't work if you used config overrides that enabled it again. Should also have a test for that to ensure it works.
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. Amounts to another breaking change as the default ignores now take effect
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.
const optionsManager = require('./options-manager'); | ||
|
||
exports.lintText = (str, opts) => { | ||
opts = optionsManager.preprocess(opts); | ||
|
||
if (opts.cwd && opts.filename) { |
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.
To be user-friendly, I think we should throw an error if the user of lintText
tries to specify the ignore
option, but didn't supply cwd
and filename
.
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! Guess this is a breaking change as passing ignores
before these changes did nothing.
* merge applicable overrides before ignoring files * throw for opts.ignores without opts.filename * use default ignores when opts.filename is given * add test case for default ignores BREAKING CHANGES: * lintText now uses the same default ignores as lintFiles with opts.filename * **/node_modules/** * **/bower_components/** * coverage/** * {tmp,temp}/** * **/*.min.js * **/bundle.js * fixtures{-*,}.{js,jsx} * fixture{s,}/** * {test,tests,spec,__tests__}/fixture{s,}/** * vendor/** * dist/** * lintText now throws when providing opts.ignores without opts.filename
182f941
to
cbead57
Compare
t.is(result.warningCount, 0); | ||
}); | ||
|
||
test('.lintText() - respect overrides', t => { |
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.
const foundOverrides = optionsManager.findApplicableOverrides(filename, overrides); | ||
opts = optionsManager.mergeApplicableOverrides(opts, foundOverrides.applicable); | ||
} | ||
|
||
opts = optionsManager.buildConfig(opts); | ||
const defaultIgnores = optionsManager.getIgnores({}).ignores; | ||
|
||
if (opts.ignores && !arrayEqual(defaultIgnores, opts.ignores) && typeof opts.filename !== 'string') { |
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 don't really understand the purpose of the !arrayEqual(defaultIgnores, opts.ignores)
check. ?
I would also prefer using lodash.isequal
instead as it's more general and could be used for other deep checks.
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.
-
array-equal
=>lodash.isequal
- the check is there to test if the user provided ignores via
.ignores
or.overrides[index].ignores
.opts.ignores
is always defined
const defaultIgnores = optionsManager.getIgnores({}).ignores; | ||
|
||
if (opts.ignores && !arrayEqual(defaultIgnores, opts.ignores) && typeof opts.filename !== 'string') { | ||
throw new Error(`xo: opts.filename must be string when providing opts.ignores. Received value "${opts.filename}" of type "${typeof opts.filename}" for opts.filename.`); |
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 is a bit too verbose. People will most likely never hit this as we're the only ones using the API. I also don't see the point of the xo:
prefix. It's clear from the stack trace where the error is coming from.
I'd prefer something like:
> The `ignores` option requires the `filename` option to be defined.
overrides: [ | ||
{ | ||
files: ['ignored/**/*.js'], | ||
ignores: [] |
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.
In addition, can you also do an overrides test that has overridden ignores
?
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
@sindresorhus Could you have another look? |
Feels a bit overkill. How about just putting a variable at the top with: const hasIgnores = Array.isArray(opts.ignores); And using that further down. |
const hasIgnores = Array.isArray(opts.ignores);
And using that further down. That would not handle ignores in |
Right, forgot about the |
Not sure if the current approach is good enough if it is hard to grasp. Let's defer this until tomorrow and have some sleep 💤 |
Coming back to this: Given there was a case with two empty array this would do the right thing and skip the error-producing code, right? |
@sindresorhus Can we move forward? |
Yes, sorry about the delay. Looks great. Thank you :) |
lintText
BREAKING CHANGES: