@discourse/lint-configs 2.16.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discourse/lint-configs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "Shareable lint configs for Discourse core, plugins, and themes",
|
|
5
5
|
"author": "Discourse",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"stylelint": "^16.19.1",
|
|
48
48
|
"stylelint-config-standard": "^38.0.0",
|
|
49
49
|
"stylelint-config-standard-scss": "^14.0.0",
|
|
50
|
+
"stylelint-scss": "^6.12.0",
|
|
50
51
|
"typescript": "^5.8.3"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import stylelint from "stylelint";
|
|
2
|
+
|
|
3
|
+
const ruleName = "discourse/no-breakpoint-mixin";
|
|
4
|
+
const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
5
|
+
rejected:
|
|
6
|
+
'Replace "@include breakpoint(...)" with "@include viewport.until(...)"',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const breakpointMappings = {
|
|
10
|
+
"mobile-small": "sm",
|
|
11
|
+
"mobile-medium": "sm",
|
|
12
|
+
"mobile-large": "sm",
|
|
13
|
+
"mobile-extra-large": "sm",
|
|
14
|
+
tablet: "md",
|
|
15
|
+
medium: "lg",
|
|
16
|
+
large: "lg",
|
|
17
|
+
"extra-large": "xl",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const ruleFunction = (primaryOption) => {
|
|
21
|
+
return (root, result) => {
|
|
22
|
+
if (!primaryOption) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
root.walkAtRules("include", (atRule) => {
|
|
27
|
+
if (atRule.params.startsWith("breakpoint(")) {
|
|
28
|
+
// Report the issue
|
|
29
|
+
stylelint.utils.report({
|
|
30
|
+
message: messages.rejected,
|
|
31
|
+
node: atRule,
|
|
32
|
+
result,
|
|
33
|
+
ruleName,
|
|
34
|
+
fix: () => {
|
|
35
|
+
const fixableRegex = /breakpoint\("?([^,]+?)"?(, min-width)?\)/;
|
|
36
|
+
const match = atRule.params.match(fixableRegex);
|
|
37
|
+
if (!match) {
|
|
38
|
+
// Not autofixable
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const oldBreakpoint = match[1].trim();
|
|
43
|
+
const newBreakpoint = breakpointMappings[oldBreakpoint];
|
|
44
|
+
const isMinWidth = match[2] === ", min-width";
|
|
45
|
+
|
|
46
|
+
if (!newBreakpoint) {
|
|
47
|
+
// Not autofixable
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Apply autofix
|
|
52
|
+
if (isMinWidth) {
|
|
53
|
+
atRule.params = atRule.params.replace(
|
|
54
|
+
fixableRegex,
|
|
55
|
+
`viewport.from(${newBreakpoint})`
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
atRule.params = atRule.params.replace(
|
|
59
|
+
fixableRegex,
|
|
60
|
+
`viewport.until(${newBreakpoint})`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Ensure the `@use "lib/viewport";` is added at the top of the file
|
|
65
|
+
const hasViewportImport = root.nodes.some(
|
|
66
|
+
(node) =>
|
|
67
|
+
node.type === "atrule" &&
|
|
68
|
+
node.name === "use" &&
|
|
69
|
+
node.params.includes('"lib/viewport"')
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!hasViewportImport) {
|
|
73
|
+
root.prepend(`@use "lib/viewport";\n`);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
ruleFunction.ruleName = ruleName;
|
|
83
|
+
ruleFunction.messages = messages;
|
|
84
|
+
ruleFunction.meta = {
|
|
85
|
+
fixable: true,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default stylelint.createPlugin(ruleName, ruleFunction);
|
package/stylelint.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import DiscourseRules from "./stylelint-rules/index.js";
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
extends: ["stylelint-config-standard-scss"],
|
|
5
|
+
plugins: [DiscourseRules],
|
|
3
6
|
rules: {
|
|
4
7
|
"color-no-invalid-hex": true,
|
|
5
8
|
"unit-no-unknown": true,
|
|
@@ -26,5 +29,7 @@ export default {
|
|
|
26
29
|
"scss/at-function-pattern": null,
|
|
27
30
|
"scss/comment-no-empty": null,
|
|
28
31
|
"scss/at-mixin-pattern": null,
|
|
32
|
+
|
|
33
|
+
"discourse/no-breakpoint-mixin": true,
|
|
29
34
|
},
|
|
30
35
|
};
|