@discourse/lint-configs 2.21.0 → 2.23.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/eslint-rules/theme-imports.mjs +96 -0
- package/eslint.mjs +3 -2
- package/package.json +7 -7
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "Do not use themeSetting or themeI18n helpers.",
|
|
6
|
+
},
|
|
7
|
+
fixable: "code",
|
|
8
|
+
schema: [], // no options
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
create(context) {
|
|
12
|
+
return {
|
|
13
|
+
ImportDeclaration(node) {
|
|
14
|
+
const modulePath = node.source.value.toLowerCase();
|
|
15
|
+
const moduleScope = context.sourceCode.scopeManager.scopes.find(
|
|
16
|
+
(s) => s.type === "module"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (modulePath === "discourse/helpers/theme-setting") {
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
message: `Importing themeSetting is not allowed.`,
|
|
23
|
+
fix(fixer) {
|
|
24
|
+
const fixes = [fixer.remove(node)];
|
|
25
|
+
|
|
26
|
+
const importName = node.specifiers[0].local.name;
|
|
27
|
+
const themeSetting = moduleScope.variables.find(
|
|
28
|
+
(v) => v.name === importName
|
|
29
|
+
);
|
|
30
|
+
themeSetting.references.forEach((ref) => {
|
|
31
|
+
const expression = ref.identifier.parent.parent;
|
|
32
|
+
const param = expression?.params[0];
|
|
33
|
+
|
|
34
|
+
if (expression?.type === "GlimmerMustacheStatement") {
|
|
35
|
+
fixes.push(
|
|
36
|
+
fixer.replaceText(expression, `{{settings.${param.value}}}`)
|
|
37
|
+
);
|
|
38
|
+
} else if (expression?.type === "GlimmerSubExpression") {
|
|
39
|
+
fixes.push(
|
|
40
|
+
fixer.replaceText(expression, `settings.${param.value}`)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return fixes;
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
} else if (modulePath === "discourse/helpers/theme-i18n") {
|
|
49
|
+
context.report({
|
|
50
|
+
node,
|
|
51
|
+
message: `Importing themeI18n is not allowed.`,
|
|
52
|
+
fix(fixer) {
|
|
53
|
+
const fixes = [];
|
|
54
|
+
|
|
55
|
+
const i18nImport = moduleScope.variables.find(
|
|
56
|
+
(v) => v.name === "i18n"
|
|
57
|
+
);
|
|
58
|
+
if (i18nImport) {
|
|
59
|
+
fixes.push(fixer.remove(node));
|
|
60
|
+
} else {
|
|
61
|
+
fixes.push(
|
|
62
|
+
fixer.replaceText(
|
|
63
|
+
node,
|
|
64
|
+
`import { i18n } from "discourse-i18n";`
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const importName = node.specifiers[0].local.name;
|
|
70
|
+
const themeI18n = moduleScope.variables.find(
|
|
71
|
+
(v) => v.name === importName
|
|
72
|
+
);
|
|
73
|
+
themeI18n.references.forEach((ref) => {
|
|
74
|
+
const expression = ref.identifier.parent.parent;
|
|
75
|
+
if (
|
|
76
|
+
["GlimmerMustacheStatement", "GlimmerSubExpression"].includes(
|
|
77
|
+
expression?.type
|
|
78
|
+
)
|
|
79
|
+
) {
|
|
80
|
+
const param = expression.params[0];
|
|
81
|
+
if (param) {
|
|
82
|
+
fixes.push(fixer.replaceText(ref.identifier, "i18n"));
|
|
83
|
+
fixes.push(fixer.insertTextBefore(param, "(themePrefix "));
|
|
84
|
+
fixes.push(fixer.insertTextAfter(param, ")"));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return fixes;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
package/eslint.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import linesBetweenClassMembers from "./eslint-rules/lines-between-class-members
|
|
|
24
24
|
import noCurlyComponents from "./eslint-rules/no-curly-components.mjs";
|
|
25
25
|
import noSimpleQuerySelector from "./eslint-rules/no-simple-query-selector.mjs";
|
|
26
26
|
import serviceInjectImport from "./eslint-rules/service-inject-import.mjs";
|
|
27
|
+
import themeImports from "./eslint-rules/theme-imports.mjs";
|
|
27
28
|
import truthHelpersImports from "./eslint-rules/truth-helpers-imports.mjs";
|
|
28
29
|
|
|
29
30
|
// Copied from "ember-template-imports/lib/utils"
|
|
@@ -117,6 +118,7 @@ export default [
|
|
|
117
118
|
"i18n-t": i18nT,
|
|
118
119
|
"service-inject-import": serviceInjectImport,
|
|
119
120
|
"truth-helpers-imports": truthHelpersImports,
|
|
121
|
+
"theme-imports": themeImports,
|
|
120
122
|
"no-simple-query-selector": noSimpleQuerySelector,
|
|
121
123
|
"deprecated-lookups": deprecatedLookups,
|
|
122
124
|
"discourse-common-imports": discourseCommonImports,
|
|
@@ -190,8 +192,6 @@ export default [
|
|
|
190
192
|
"ember/avoid-leaking-state-in-ember-objects": "off",
|
|
191
193
|
"ember/no-get": "off",
|
|
192
194
|
"ember/no-observers": "off",
|
|
193
|
-
"ember/no-mixins": "off",
|
|
194
|
-
"ember/no-new-mixins": "off",
|
|
195
195
|
"ember/no-implicit-injections": "off", // this rule is broken
|
|
196
196
|
"ember/no-array-prototype-extensions": "off",
|
|
197
197
|
"ember/no-at-ember-render-modifiers": "off",
|
|
@@ -294,6 +294,7 @@ export default [
|
|
|
294
294
|
"discourse/i18n-t": ["error"],
|
|
295
295
|
"discourse/service-inject-import": ["error"],
|
|
296
296
|
"discourse/truth-helpers-imports": ["error"],
|
|
297
|
+
"discourse/theme-imports": ["error"],
|
|
297
298
|
"discourse/no-simple-query-selector": ["error"],
|
|
298
299
|
"discourse/deprecated-lookups": ["error"],
|
|
299
300
|
"discourse/discourse-common-imports": ["error"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discourse/lint-configs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.23.0",
|
|
4
4
|
"description": "Shareable lint configs for Discourse core, plugins, and themes",
|
|
5
5
|
"author": "Discourse",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,21 +30,21 @@
|
|
|
30
30
|
"test": "cd ../test && node test.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@babel/core": "^7.27.
|
|
33
|
+
"@babel/core": "^7.27.4",
|
|
34
34
|
"@babel/eslint-parser": "^7.27.1",
|
|
35
35
|
"@babel/plugin-proposal-decorators": "^7.27.1",
|
|
36
36
|
"ember-template-lint": "^7.7.0",
|
|
37
|
-
"eslint": "^9.
|
|
37
|
+
"eslint": "^9.28.0",
|
|
38
38
|
"eslint-plugin-decorator-position": "^6.0.0",
|
|
39
39
|
"eslint-plugin-ember": "^12.5.0",
|
|
40
40
|
"eslint-plugin-import": "^2.31.0",
|
|
41
41
|
"eslint-plugin-qunit": "^8.1.2",
|
|
42
42
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
43
43
|
"eslint-plugin-sort-class-members": "^1.21.0",
|
|
44
|
-
"globals": "^16.
|
|
44
|
+
"globals": "^16.2.0",
|
|
45
45
|
"prettier": "^3.5.3",
|
|
46
46
|
"prettier-plugin-ember-template-tag": "^2.0.5",
|
|
47
|
-
"stylelint": "^16.
|
|
47
|
+
"stylelint": "^16.20.0",
|
|
48
48
|
"stylelint-config-standard": "^38.0.0",
|
|
49
49
|
"stylelint-config-standard-scss": "^15.0.1",
|
|
50
50
|
"stylelint-scss": "^6.12.0",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"ember-template-lint": "7.7.0",
|
|
55
|
-
"eslint": "9.
|
|
55
|
+
"eslint": "9.28.0",
|
|
56
56
|
"prettier": "3.5.3",
|
|
57
|
-
"stylelint": "16.
|
|
57
|
+
"stylelint": "16.20.0"
|
|
58
58
|
}
|
|
59
59
|
}
|