@discourse/lint-configs 2.32.0 → 2.34.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/.prettierrc.cjs
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "suggestion",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "Disallow RouteTemplate wrapper for route templates.",
|
|
6
|
+
},
|
|
7
|
+
fixable: "code",
|
|
8
|
+
schema: [],
|
|
9
|
+
messages: {
|
|
10
|
+
removeRouteTemplate: "Remove RouteTemplate wrapper for route templates.",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
create(context) {
|
|
15
|
+
return {
|
|
16
|
+
ExportDefaultDeclaration(node) {
|
|
17
|
+
if (
|
|
18
|
+
node.declaration &&
|
|
19
|
+
node.declaration.type === "CallExpression" &&
|
|
20
|
+
node.declaration.callee.name === "RouteTemplate" &&
|
|
21
|
+
node.declaration.arguments.length === 1
|
|
22
|
+
) {
|
|
23
|
+
context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: "removeRouteTemplate",
|
|
26
|
+
fix(fixer) {
|
|
27
|
+
const sourceCode = context.getSourceCode();
|
|
28
|
+
const arg = node.declaration.arguments[0];
|
|
29
|
+
// Find import of RouteTemplate
|
|
30
|
+
const importDecl = sourceCode.ast.body.find(
|
|
31
|
+
(n) =>
|
|
32
|
+
n.type === "ImportDeclaration" &&
|
|
33
|
+
n.specifiers.some(
|
|
34
|
+
(s) =>
|
|
35
|
+
s.type === "ImportDefaultSpecifier" &&
|
|
36
|
+
s.local.name === "RouteTemplate"
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Only remove the import and replace the export, do not touch whitespace/indentation
|
|
41
|
+
const fixes = [];
|
|
42
|
+
if (importDecl) {
|
|
43
|
+
fixes.push(fixer.remove(importDecl));
|
|
44
|
+
}
|
|
45
|
+
fixes.push(
|
|
46
|
+
fixer.replaceText(node.declaration, sourceCode.getText(arg))
|
|
47
|
+
);
|
|
48
|
+
return fixes;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -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
|
@@ -24,10 +24,12 @@ import lineBeforeDefaultExport from "./eslint-rules/line-before-default-export.m
|
|
|
24
24
|
import linesBetweenClassMembers from "./eslint-rules/lines-between-class-members.mjs";
|
|
25
25
|
import noCurlyComponents from "./eslint-rules/no-curly-components.mjs";
|
|
26
26
|
import noOnclick from "./eslint-rules/no-onclick.mjs";
|
|
27
|
+
import noRouteTemplate from "./eslint-rules/no-route-template.mjs";
|
|
27
28
|
import noSimpleQuerySelector from "./eslint-rules/no-simple-query-selector.mjs";
|
|
28
29
|
import noUnusedServices from "./eslint-rules/no-unused-services.mjs";
|
|
29
30
|
import pluginApiNoVersion from "./eslint-rules/plugin-api-no-version.mjs";
|
|
30
31
|
import serviceInjectImport from "./eslint-rules/service-inject-import.mjs";
|
|
32
|
+
import templateTagNoSelfThis from "./eslint-rules/template-tag-no-self-this.mjs";
|
|
31
33
|
import themeImports from "./eslint-rules/theme-imports.mjs";
|
|
32
34
|
import truthHelpersImports from "./eslint-rules/truth-helpers-imports.mjs";
|
|
33
35
|
|
|
@@ -136,6 +138,8 @@ export default [
|
|
|
136
138
|
"no-curly-components": noCurlyComponents,
|
|
137
139
|
"capital-components": capitalComponents,
|
|
138
140
|
"no-onclick": noOnclick,
|
|
141
|
+
"no-route-template": noRouteTemplate,
|
|
142
|
+
"template-tag-no-self-this": templateTagNoSelfThis,
|
|
139
143
|
},
|
|
140
144
|
},
|
|
141
145
|
},
|
|
@@ -312,6 +316,8 @@ export default [
|
|
|
312
316
|
"discourse/no-curly-components": ["error"],
|
|
313
317
|
"discourse/capital-components": ["error"],
|
|
314
318
|
"discourse/no-onclick": ["error"],
|
|
319
|
+
"discourse/template-tag-no-self-this": ["error"],
|
|
320
|
+
// "discourse/no-route-template": ["error"], // Enable by default once Ember 6.6 is on stable
|
|
315
321
|
},
|
|
316
322
|
},
|
|
317
323
|
{
|