Skip to content

Commit

Permalink
[stylelint-polaris][coverage] Grouped rules by category
Browse files Browse the repository at this point in the history
Co-authored by: Sophie Schneider <thesophieschneider@gmail.com>
Co-authored by: Chloe Rice <chloe.rice@shopify.com>

More categorization: added shape, breakpoints, and button categories
>
>
Co-authored by: Sophie Schneider <thesophieschneider@gmail.com>

finished sorting stylelint-polaris/at-rule-disallowed-list

sorted stylelint-polaris/global-disallowed-list

Patch to stylelint to enable custom rule severities and calling checkAgainstRule with custom rules

Update coverage rule to set custom rule severities and normalize rule settings

Replace isObject with isPlainObject

Add test case for stylelint patch to ensure checkAgainstRule calls custom rules

Update select layout errors to warnings

Add changeset entry

Dedupe legacySass coverage rules

Add stylelint --fix support

Remove extraneous fix check

Delete coverage.scss

Update custom severity reporting to leverage the config.defaultSeverity setting
  • Loading branch information
aaronccasanova authored and chloerice committed Nov 11, 2022
1 parent bdf6fd3 commit 2d11e99
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 286 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-knives-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/stylelint-polaris': minor
---

Categorize coverage rules
67 changes: 67 additions & 0 deletions patches/stylelint+14.8.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/node_modules/stylelint/lib/utils/checkAgainstRule.js b/node_modules/stylelint/lib/utils/checkAgainstRule.js
index 83706c5..feda9b8 100644
--- a/node_modules/stylelint/lib/utils/checkAgainstRule.js
+++ b/node_modules/stylelint/lib/utils/checkAgainstRule.js
@@ -27,7 +27,9 @@ function checkAgainstRule(options, callback) {

if (!options.ruleName) throw new Error("checkAgainstRule requires a 'ruleName' option");

- const rule = rules[options.ruleName];
+ const pluginFunction = options?.result?.stylelint?.config?.pluginFunctions?.[options.ruleName];
+
+ const rule = typeof pluginFunction === 'function' ? pluginFunction : rules[options.ruleName];

if (!rule) throw new Error(`Rule '${options.ruleName}' does not exist`);

@@ -44,7 +46,7 @@ function checkAgainstRule(options, callback) {
// @ts-expect-error - this error should not occur with PostCSS 8
const tmpPostcssResult = new Result();

- rule(settings[0], /** @type {O} */ (settings[1]), {})(options.root, tmpPostcssResult);
+ rule(settings[0], /** @type {O} */(settings[1]), {fix: options.fix})(options.root, tmpPostcssResult);

for (const warning of tmpPostcssResult.warnings()) callback(warning);
}
diff --git a/node_modules/stylelint/lib/utils/report.js b/node_modules/stylelint/lib/utils/report.js
index 02a3c3c..5573371 100644
--- a/node_modules/stylelint/lib/utils/report.js
+++ b/node_modules/stylelint/lib/utils/report.js
@@ -15,7 +15,7 @@
* @type {typeof import('stylelint').utils.report}
*/
module.exports = function report(problem) {
- const { ruleName, result, message, line, node, index, endIndex, word } = problem;
+ const { ruleName, result, message, line, node, index, endIndex, word, severity: customSeverity } = problem;

result.stylelint = result.stylelint || {
ruleSeverities: {},
@@ -72,7 +72,7 @@ module.exports = function report(problem) {
}
}

- const severity = result.stylelint.ruleSeverities && result.stylelint.ruleSeverities[ruleName];
+ const severity = customSeverity || result.stylelint.ruleSeverities && result.stylelint.ruleSeverities[ruleName];

if (!result.stylelint.stylelintError && severity === 'error') {
result.stylelint.stylelintError = true;
diff --git a/node_modules/stylelint/types/stylelint/index.d.ts b/node_modules/stylelint/types/stylelint/index.d.ts
index b6ec792..fa1b3b9 100644
--- a/node_modules/stylelint/types/stylelint/index.d.ts
+++ b/node_modules/stylelint/types/stylelint/index.d.ts
@@ -362,6 +362,7 @@ declare module 'stylelint' {
};
word?: string;
line?: number;
+ severity?: Severity;
};

export type PublicApi = PostCSS.PluginCreator<PostcssPluginOptions> & {
@@ -436,7 +437,7 @@ declare module 'stylelint' {
* against a specific rule and do something with the warnings
*/
checkAgainstRule: <T, O extends Object>(
- options: { ruleName: string; ruleSettings: ConfigRuleSettings<T, O>; root: PostCSS.Root },
+ options: { ruleName: string; ruleSettings: ConfigRuleSettings<T, O>; root: PostCSS.Root, result?: PostcssResult },
callback: (warning: PostCSS.Warning) => void,
) => void;
};

0 comments on commit 2d11e99

Please sign in to comment.