@discourse/lint-configs 2.33.0 → 2.34.1
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.
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "suggestion",
|
|
4
|
+
docs: {
|
|
5
|
+
description:
|
|
6
|
+
"Avoid using `const self = this`. Use `this` directly inside template tags.",
|
|
7
|
+
},
|
|
8
|
+
fixable: "code",
|
|
9
|
+
schema: [], // no options
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
create(context) {
|
|
13
|
+
return {
|
|
14
|
+
VariableDeclarator(node) {
|
|
15
|
+
if (
|
|
16
|
+
node.id.type !== "Identifier" ||
|
|
17
|
+
node.init?.type !== "ThisExpression"
|
|
18
|
+
) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const variable = context.sourceCode.getDeclaredVariables(node)[0];
|
|
23
|
+
const references = variable.references.filter(
|
|
24
|
+
(ref) => ref.identifier.parent !== node
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const referencedOnlyInAdjacentTemplateTag = references.every((ref) => {
|
|
28
|
+
if (ref.identifier.type !== "VarHead") {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const hasSameVariableScope =
|
|
33
|
+
context.sourceCode.getScope(ref.identifier).variableScope ===
|
|
34
|
+
context.sourceCode.getScope(node).variableScope;
|
|
35
|
+
|
|
36
|
+
return hasSameVariableScope;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (referencedOnlyInAdjacentTemplateTag) {
|
|
40
|
+
context.report({
|
|
41
|
+
node,
|
|
42
|
+
message:
|
|
43
|
+
"Remove `self = this` and use `this` directly inside template tags.",
|
|
44
|
+
fix(fixer) {
|
|
45
|
+
const fixes = [];
|
|
46
|
+
|
|
47
|
+
// Replace all references to `self` with `this`
|
|
48
|
+
references.forEach((ref) => {
|
|
49
|
+
fixes.push(fixer.replaceText(ref.identifier, "this"));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Remove the original variable declaration
|
|
53
|
+
fixes.push(fixer.remove(node.parent));
|
|
54
|
+
|
|
55
|
+
return fixes;
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
package/eslint.mjs
CHANGED
|
@@ -29,6 +29,7 @@ import noSimpleQuerySelector from "./eslint-rules/no-simple-query-selector.mjs";
|
|
|
29
29
|
import noUnusedServices from "./eslint-rules/no-unused-services.mjs";
|
|
30
30
|
import pluginApiNoVersion from "./eslint-rules/plugin-api-no-version.mjs";
|
|
31
31
|
import serviceInjectImport from "./eslint-rules/service-inject-import.mjs";
|
|
32
|
+
import templateTagNoSelfThis from "./eslint-rules/template-tag-no-self-this.mjs";
|
|
32
33
|
import themeImports from "./eslint-rules/theme-imports.mjs";
|
|
33
34
|
import truthHelpersImports from "./eslint-rules/truth-helpers-imports.mjs";
|
|
34
35
|
|
|
@@ -138,6 +139,7 @@ export default [
|
|
|
138
139
|
"capital-components": capitalComponents,
|
|
139
140
|
"no-onclick": noOnclick,
|
|
140
141
|
"no-route-template": noRouteTemplate,
|
|
142
|
+
"template-tag-no-self-this": templateTagNoSelfThis,
|
|
141
143
|
},
|
|
142
144
|
},
|
|
143
145
|
},
|
|
@@ -314,6 +316,7 @@ export default [
|
|
|
314
316
|
"discourse/no-curly-components": ["error"],
|
|
315
317
|
"discourse/capital-components": ["error"],
|
|
316
318
|
"discourse/no-onclick": ["error"],
|
|
319
|
+
"discourse/template-tag-no-self-this": ["error"],
|
|
317
320
|
// "discourse/no-route-template": ["error"], // Enable by default once Ember 6.6 is on stable
|
|
318
321
|
},
|
|
319
322
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discourse/lint-configs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.34.1",
|
|
4
4
|
"description": "Shareable lint configs for Discourse core, plugins, and themes",
|
|
5
5
|
"author": "Discourse",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"url": "git+https://github.com/discourse/lint-configs.git"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/discourse/lint-configs#readme",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
15
18
|
"type": "module",
|
|
16
19
|
"exports": {
|
|
17
20
|
"./eslint": "./eslint.mjs",
|