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

Fix stylelint config usage #4498

Merged
merged 2 commits into from Dec 29, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/__tests__/invalidScopeDisables.test.js
Expand Up @@ -91,3 +91,15 @@ it('invalidScopeDisables ignored case', () => {
]);
});
});

it('invalidScopeDisables without config', () => {
return standalone({
config: {
rules: {},
},
code: 'a {}',
ignoreDisables: true,
}).then((linted) => {
expect(invalidScopeDisables(linted.results)).toEqual([]);
});
});
4 changes: 2 additions & 2 deletions lib/invalidScopeDisables.js
Expand Up @@ -6,10 +6,10 @@

/**
* @param {import('stylelint').StylelintResult[]} results
* @param {import('stylelint').StylelintConfig} config
* @param {import('stylelint').StylelintConfig|undefined} config
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param {import('stylelint').StylelintConfig|undefined} config
* @param {import('stylelint').StylelintConfig} config

It works without undefined.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

By default null and undefined are subtypes of all other types. That means you can assign null and undefined to something like number.

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.

* @returns {StylelintDisableOptionsReport}
*/
module.exports = function(results, config) {
module.exports = function(results, config = {}) {
/** @type {StylelintDisableOptionsReport} */
const report = [];
const usedRules = new Set(Object.keys(config.rules || {}));
Expand Down
3 changes: 1 addition & 2 deletions lib/standalone.js
Expand Up @@ -306,8 +306,7 @@ module.exports = function(options) {
if (reportInvalidScopeDisables) {
returnValue.invalidScopeDisables = invalidScopeDisables(
stylelintResults,
// TODO TYPES possible undefined
/** @type {import('stylelint').StylelintConfig} */ (stylelint._options.config),
stylelint._options.config,
);
}

Expand Down