Skip to content

Commit

Permalink
Fix --report-invalid-scope-disables crash when no rules specified (#4498
Browse files Browse the repository at this point in the history
)
  • Loading branch information
webschik authored and hudochenkov committed Dec 29, 2019
1 parent 1dfaee8 commit 0e2439d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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
* @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

0 comments on commit 0e2439d

Please sign in to comment.