Skip to content

build: switch to newer stylelint types and remove workaround #23543

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

Merged
merged 1 commit into from
Sep 10, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"@types/selenium-webdriver": "^3.0.17",
"@types/semver": "^7.3.4",
"@types/send": "^0.14.5",
"@types/stylelint": "^9.10.1",
"@types/stylelint": "^13.13.2",
"@types/yaml": "^1.9.7",
"autoprefixer": "^10.2.5",
"browser-sync": "2.26.13",
Expand Down
12 changes: 7 additions & 5 deletions tools/stylelint/no-unused-import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createPlugin, Plugin, utils} from 'stylelint';
import {basename, join} from 'path';
import {Result, Root} from './stylelint-postcss-types';
import {Result, Root} from 'postcss';

const ruleName = 'material/no-unused-import';
const messages = utils.ruleMessages(ruleName, {
Expand All @@ -25,20 +25,22 @@ const factory = (isEnabled: boolean, _options: never, context: {fix: boolean}) =
// Flag namespaces we didn't manage to parse so that we can fix the parsing logic.
if (!namespace) {
utils.report({
result,
// We need these `as any` casts, because Stylelint uses an older version
// of the postcss typings that don't match up with our anymore.
result: result as any,
ruleName,
message: messages.invalid(rule.params),
node: rule
node: rule as any
});
} else if (!fileContent.includes(namespace + '.')) {
if (context.fix) {
rule.remove();
} else {
utils.report({
result,
result: result as any,
ruleName,
message: messages.expected(namespace),
node: rule
node: rule as any
});
}
}
Expand Down
14 changes: 0 additions & 14 deletions tools/stylelint/stylelint-postcss-types.ts

This file was deleted.

8 changes: 5 additions & 3 deletions tools/stylelint/theme-mixin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Node,
Result,
Root
} from './stylelint-postcss-types';
} from 'postcss';

/** Name of this stylelint rule. */
const ruleName = 'material/theme-mixin-api';
Expand Down Expand Up @@ -198,7 +198,9 @@ const plugin = (isEnabled: boolean, _options: never, context: {fix: boolean}) =>
}

function reportError(node: Node, message: string) {
utils.report({result, ruleName, node, message});
// We need these `as any` casts, because Stylelint uses an older version
// of the postcss typings that don't match up with our anymore.
utils.report({result: result as any, ruleName, node: node as any, message});
}
};
};
Expand Down Expand Up @@ -229,4 +231,4 @@ function stripNewlinesAndIndentation(value: string): string {

// Note: We need to cast the value explicitly to `Plugin` because the stylelint types
// do not type the context parameter. https://stylelint.io/developer-guide/rules#add-autofix
module.exports = createPlugin(ruleName, plugin as Plugin);
module.exports = createPlugin(ruleName, plugin as unknown as Plugin);
11 changes: 6 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2252,11 +2252,12 @@
"@types/glob" "*"
"@types/node" "*"

"@types/stylelint@^9.10.1":
version "9.10.1"
resolved "https://registry.yarnpkg.com/@types/stylelint/-/stylelint-9.10.1.tgz#211832381e43fd0774217b59f02ab389d82643ea"
integrity sha512-au+n/CjGixNopJmh51GeZSkqf/ahwOBkzcvizHPe3flfwWag0T+/L7uHD0Hjx7ZhmXGFSEwOCqEybD4domcyRw==
"@types/stylelint@^13.13.2":
version "13.13.2"
resolved "https://registry.yarnpkg.com/@types/stylelint/-/stylelint-13.13.2.tgz#7a8a99bdbe19187b973a290dd3f821cfe5caff6e"
integrity sha512-5Yt1LQenR7uk+efCydQmN7ubOtO2qJ8Z9K/qqnlW87X1zkIQ8RkMCZbaOgZj/aBrR/h5Q738mJU6CYhXOj9sEg==
dependencies:
globby "11.x.x"
postcss "7.x.x"

"@types/through@*":
Expand Down Expand Up @@ -6982,7 +6983,7 @@ globalthis@^1.0.1:
dependencies:
define-properties "^1.1.3"

globby@^11.0.3:
globby@11.x.x, globby@^11.0.3:
version "11.0.4"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==
Expand Down