Skip to content

Commit d5211de

Browse files
authored
build: update Stylelint and fix rule errors (#25820)
Updates to the latest version of Stylelint and fixes a bunch of errors that were the result of us not having set up the rules as it is recommended in https://stylelint.io/developer-guide/plugins/.
1 parent 8078eb8 commit d5211de

13 files changed

+125
-126
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
"moment": "^2.29.1",
198198
"node-fetch": "^2.6.0",
199199
"parse5": "^6.0.1",
200-
"postcss": "^8.4.14",
200+
"postcss": "^8.4.17",
201201
"postcss-scss": "^4.0.4",
202202
"protractor": "^7.0.0",
203203
"reflect-metadata": "^0.1.13",
@@ -209,7 +209,7 @@
209209
"semver": "^7.3.5",
210210
"send": "^0.17.2",
211211
"shelljs": "^0.8.5",
212-
"stylelint": "^14.9.1",
212+
"stylelint": "^14.14.0",
213213
"terser": "^5.10.0",
214214
"ts-node": "^10.8.1",
215215
"tsec": "0.2.2",

tools/stylelint/cross-package-import-validation.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import {dirname, relative, join} from 'path';
33

44
const ruleName = 'material/cross-package-import-validation';
@@ -15,7 +15,7 @@ const packageNameRegex = /^src\/([^/]+)/;
1515
const projectDir = join(__dirname, '../../');
1616

1717
/** Stylelint plugin that flags forbidden cross-package relative imports. */
18-
const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
18+
const ruleFn: Rule<boolean, unknown> = isEnabled => {
1919
return (root, result) => {
2020
if (!isEnabled) {
2121
return;
@@ -71,11 +71,14 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
7171
}
7272
});
7373
};
74-
});
74+
};
75+
76+
ruleFn.ruleName = ruleName;
77+
ruleFn.messages = messages;
7578

7679
/** Converts the specified absolute path to a project relative POSIX path. */
7780
function convertToProjectRelativePosixPath(fileName: string): string {
7881
return relative(projectDir, fileName).replace(/[/\\]/g, '/');
7982
}
8083

81-
export default plugin;
84+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-ampersand-beyond-selector-start.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import {basename} from 'path';
33

44
const isStandardSyntaxRule = require('stylelint/lib/utils/isStandardSyntaxRule');
@@ -9,19 +9,14 @@ const messages = utils.ruleMessages(ruleName, {
99
expected: () => 'Ampersand is only allowed at the beginning of a selector',
1010
});
1111

12-
/** Config options for the rule. */
13-
interface RuleOptions {
14-
filePattern?: string;
15-
}
16-
1712
/**
1813
* Stylelint rule that doesn't allow for an ampersand to be used anywhere
1914
* except at the start of a selector. Skips private mixins.
2015
*
2116
* Based off the `selector-nested-pattern` Stylelint rule.
2217
* Source: https://github.com/stylelint/stylelint/blob/master/lib/rules/selector-nested-pattern/
2318
*/
24-
const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions) => {
19+
const ruleFn: Rule<boolean, string> = (isEnabled, options) => {
2520
return (root, result) => {
2621
if (!isEnabled) {
2722
return;
@@ -50,10 +45,13 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions)
5045
}
5146
});
5247
};
53-
});
48+
};
49+
50+
ruleFn.ruleName = ruleName;
51+
ruleFn.messages = messages;
5452

5553
function hasInvalidAmpersandUsage(selector: string): boolean {
5654
return selector.split(',').some(part => part.trim().indexOf('&', 1) > -1);
5755
}
5856

59-
export default plugin;
57+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-concrete-rules.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, utils, Rule} from 'stylelint';
22
import {basename} from 'path';
33

44
const ruleName = 'material/no-concrete-rules';
@@ -8,16 +8,11 @@ const messages = utils.ruleMessages(ruleName, {
88
expectedAllFiles: () => `CSS rules must be placed inside a mixin for all files.`,
99
});
1010

11-
/** Config options for the rule. */
12-
interface RuleOptions {
13-
filePattern?: string;
14-
}
15-
1611
/**
1712
* Stylelint plugin that will log a warning for all top-level CSS rules.
1813
* Can be used in theme files to ensure that everything is inside a mixin.
1914
*/
20-
const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions) => {
15+
const ruleFn: Rule<boolean, string> = (isEnabled, options) => {
2116
return (root, result) => {
2217
if (!isEnabled) {
2318
return;
@@ -47,6 +42,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions)
4742
}
4843
});
4944
};
50-
});
45+
};
46+
47+
ruleFn.ruleName = ruleName;
48+
ruleFn.messages = messages;
5149

52-
export default plugin;
50+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-import.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import {basename} from 'path';
33

44
const ruleName = 'material/no-import';
@@ -7,7 +7,7 @@ const messages = utils.ruleMessages(ruleName, {
77
});
88

99
/** Stylelint plugin that doesn't allow `@import` to be used. */
10-
const plugin = createPlugin(ruleName, (isEnabled: boolean, options?: {exclude?: string}) => {
10+
const ruleFn: Rule<boolean, string> = (isEnabled, options) => {
1111
return (root, result) => {
1212
if (!isEnabled) {
1313
return;
@@ -30,6 +30,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options?: {exclude?:
3030
}
3131
});
3232
};
33-
});
33+
};
34+
35+
ruleFn.ruleName = ruleName;
36+
ruleFn.messages = messages;
3437

35-
export default plugin;
38+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-nested-mixin.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22

33
const ruleName = 'material/no-nested-mixin';
44
const messages = utils.ruleMessages(ruleName, {
@@ -8,7 +8,7 @@ const messages = utils.ruleMessages(ruleName, {
88
/**
99
* Stylelint plugin that prevents nesting Sass mixins.
1010
*/
11-
const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
11+
const ruleFn: Rule<boolean, unknown> = isEnabled => {
1212
return (root, result) => {
1313
if (!isEnabled) {
1414
return;
@@ -33,6 +33,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
3333
});
3434
});
3535
};
36-
});
36+
};
37+
38+
ruleFn.ruleName = ruleName;
39+
ruleFn.messages = messages;
3740

38-
export default plugin;
41+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-prefixes/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import minimatch from 'minimatch';
33
import {NeedsPrefix} from './needs-prefix';
44

@@ -14,17 +14,14 @@ const messages = utils.ruleMessages(ruleName, {
1414
selector: selector => `Unprefixed selector "${selector}".`,
1515
});
1616

17-
/** Config options for the rule. */
18-
interface Options {
19-
browsers?: string[];
20-
filePattern?: string;
21-
}
22-
2317
/**
2418
* Stylelint plugin that warns for unprefixed CSS.
2519
*/
26-
const plugin = createPlugin(ruleName, (isEnabled: boolean, {filePattern, browsers}: Options) => {
20+
const ruleFn: Rule<boolean, string[] | string> = (isEnabled, options) => {
2721
return (root, result) => {
22+
const browsers = options.browsers as string[] | undefined;
23+
const filePattern = options.filePattern as string | undefined;
24+
2825
if (
2926
!isEnabled ||
3027
!browsers ||
@@ -96,6 +93,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, {filePattern, browser
9693
});
9794
});
9895
};
99-
});
96+
};
97+
98+
ruleFn.ruleName = ruleName;
99+
ruleFn.messages = messages;
100100

101-
export default plugin;
101+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-top-level-ampersand-in-mixin.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import {basename} from 'path';
33

44
const ruleName = 'material/no-top-level-ampersand-in-mixin';
@@ -7,22 +7,16 @@ const messages = utils.ruleMessages(ruleName, {
77
`Selectors starting with an ampersand ` + `are not allowed inside top-level mixin rules`,
88
});
99

10-
/** Config options for the rule. */
11-
interface RuleOptions {
12-
filePattern: string;
13-
}
14-
1510
/**
1611
* Stylelint rule that doesn't allow for the top-level rules inside a
1712
* mixin to start with an ampersand. Does not apply to internal mixins.
1813
*/
19-
const plugin = createPlugin(ruleName, (isEnabled: boolean, _options?) => {
14+
const ruleFn: Rule<boolean, string> = (isEnabled, options) => {
2015
return (root, result) => {
2116
if (!isEnabled) {
2217
return;
2318
}
2419

25-
const options = _options as RuleOptions;
2620
const filePattern = new RegExp(options.filePattern);
2721
const fileName = basename(root.source!.input.file!);
2822

@@ -53,6 +47,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, _options?) => {
5347
});
5448
});
5549
};
56-
});
50+
};
51+
52+
ruleFn.ruleName = ruleName;
53+
ruleFn.messages = messages;
5754

58-
export default plugin;
55+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/no-unused-import.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import {basename, join} from 'path';
33

44
const ruleName = 'material/no-unused-import';
@@ -10,7 +10,7 @@ const messages = utils.ruleMessages(ruleName, {
1010
});
1111

1212
/** Stylelint plugin that flags unused `@use` statements. */
13-
const plugin = createPlugin(ruleName, (isEnabled: boolean, _options, context) => {
13+
const ruleFn: Rule<boolean, string> = (isEnabled, _options, context) => {
1414
return (root, result) => {
1515
if (!isEnabled) {
1616
return;
@@ -45,7 +45,10 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, _options, context) =>
4545
}
4646
});
4747
};
48-
});
48+
};
49+
50+
ruleFn.ruleName = ruleName;
51+
ruleFn.messages = messages;
4952

5053
/** Extracts the namespace of an `@use` rule from its parameters. */
5154
function extractNamespaceFromUseStatement(params: string): string | null {
@@ -85,4 +88,4 @@ function extractNamespaceFromUseStatement(params: string): string | null {
8588
return null;
8689
}
8790

88-
export default plugin;
91+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/selector-no-deep.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22

33
const isStandardSyntaxRule = require('stylelint/lib/utils/isStandardSyntaxRule');
44
const isStandardSyntaxSelector = require('stylelint/lib/utils/isStandardSyntaxSelector');
@@ -11,7 +11,7 @@ const messages = utils.ruleMessages(ruleName, {
1111
/**
1212
* Stylelint plugin that prevents uses of /deep/ in selectors.
1313
*/
14-
const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
14+
const ruleFn: Rule<boolean, unknown> = isEnabled => {
1515
return (root, result) => {
1616
if (!isEnabled) {
1717
return;
@@ -33,6 +33,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
3333
}
3434
});
3535
};
36-
});
36+
};
37+
38+
ruleFn.ruleName = ruleName;
39+
ruleFn.messages = messages;
3740

38-
export default plugin;
41+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/single-line-comment-only.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils} from 'stylelint';
1+
import {createPlugin, Rule, utils} from 'stylelint';
22
import {basename} from 'path';
33

44
const ruleName = 'material/single-line-comment-only';
@@ -11,7 +11,7 @@ const messages = utils.ruleMessages(ruleName, {
1111
* Stylelint plugin that doesn't allow multi-line comments to
1212
* be used, because they'll show up in the user's output.
1313
*/
14-
const plugin = createPlugin(ruleName, (isEnabled: boolean, options?: {filePattern?: string}) => {
14+
const ruleFn: Rule<boolean, string> = (isEnabled, options) => {
1515
return (root, result) => {
1616
if (!isEnabled) {
1717
return;
@@ -35,6 +35,9 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options?: {filePatter
3535
}
3636
});
3737
};
38-
});
38+
};
39+
40+
ruleFn.ruleName = ruleName;
41+
ruleFn.messages = messages;
3942

40-
export default plugin;
43+
export default createPlugin(ruleName, ruleFn);

tools/stylelint/theme-mixin-api.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createPlugin, utils, PostcssResult} from 'stylelint';
1+
import {createPlugin, utils, PostcssResult, Rule} from 'stylelint';
22
import {basename} from 'path';
33
import {AtRule, Declaration, Node} from 'postcss';
44

@@ -21,7 +21,7 @@ const themeMixinRegex = /^(density|color|typography|theme)\((.*)\)$/;
2121
* consistently check for duplicative theme styles so that we can warn consumers. The
2222
* plugin ensures that style-generating statements are nested inside the duplication check.
2323
*/
24-
const plugin = createPlugin(ruleName, (isEnabled: boolean, _options, context) => {
24+
const ruleFn: Rule<boolean, unknown> = (isEnabled, _options, context) => {
2525
return (root, result) => {
2626
const componentName = getComponentNameFromPath(root.source!.input.file!);
2727

@@ -55,7 +55,10 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, _options, context) =>
5555
}
5656
});
5757
};
58-
});
58+
};
59+
60+
ruleFn.ruleName = ruleName;
61+
ruleFn.messages = utils.ruleMessages(ruleName, {});
5962

6063
/** Validates a `theme` mixin. */
6164
function validateThemeMixin(
@@ -274,4 +277,4 @@ function sanitizeForRegularExpression(value: string): string {
274277
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
275278
}
276279

277-
export default plugin;
280+
export default createPlugin(ruleName, ruleFn);

0 commit comments

Comments
 (0)