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
Fix stylelint config usage #4498
Conversation
I think test should look like this: it('invalidScopeDisables without config', () => {
return standalone({
config: {},
code: 'a {}',
ignoreDisables: true,
}).then((linted) => {
expect(invalidScopeDisables(linted.results)).toEqual([]);
});
}); Because we want to test when config is empty, and code doesn't have any |
Make sense, but then it should look like return standalone({
config: {
rules: {}
},
code: 'a {}',
ignoreDisables: true,
}).then((linted) => {
expect(invalidScopeDisables(linted.results)).toEqual([]);
}); because there is a check for |
@@ -6,10 +6,10 @@ | |||
|
|||
/** | |||
* @param {import('stylelint').StylelintResult[]} results | |||
* @param {import('stylelint').StylelintConfig} config | |||
* @param {import('stylelint').StylelintConfig|undefined} config |
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.
* @param {import('stylelint').StylelintConfig|undefined} config | |
* @param {import('stylelint').StylelintConfig} config |
It works without undefined
.
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 this case type annotation in JSDoc is not correct, it means the function accepts config
only with StylelintConfig
type, but it's not true. I think it's more correct to specify in type that function may accept undefined
. Also, we can describe config
as optional - https://jsdoc.app/tags-param.html#optional-parameters-and-default-values, but I think it's a worse approach.
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.
By default
null
andundefined
are subtypes of all other types. That means you can assignnull
andundefined
to something likenumber
.
http://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined
While explicitly specifying undefined
is correct, it's not necessary.
If you want to keep, it's ok.
|
There was a comment in
lib/standalone.js:312
thatstylelint._options.config
might beundefined
, butinvalidScopeDisables.js
function always expected an object as 2nd parameter.For me there were 2 ways to fix that:
stylelint._options.config || {}
forinvalidScopeDisables
call, orinvalidScopeDisables
interface to acceptundefined
as 2nd parameter.I've chosen 2nd option, to prevent adding more conditions in the future in we need to call
invalidScopeDisables
somewhere else with the optional config param.Closes #4479