@fluid-topics/ft-eslint 1.4.4 → 2.0.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/build/external-rules.js +1 -0
- package/build/plugin.d.ts +2 -0
- package/build/plugin.js +4 -0
- package/build/rules/custom-elements.d.ts +2 -0
- package/build/rules/custom-elements.js +50 -0
- package/build/rules/index-define-import.d.ts +2 -0
- package/build/rules/index-define-import.js +33 -0
- package/package.json +2 -2
package/build/external-rules.js
CHANGED
package/build/plugin.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ declare const plugin: {
|
|
|
10
10
|
"number-property": import("eslint").Rule.RuleModule;
|
|
11
11
|
"lower-case-ft-css-variables": import("eslint").Rule.RuleModule;
|
|
12
12
|
"ft-css-variable-names": import("eslint").Rule.RuleModule;
|
|
13
|
+
"custom-elements": import("eslint").Rule.RuleModule;
|
|
14
|
+
"index-define-imports": import("eslint").Rule.RuleModule;
|
|
13
15
|
};
|
|
14
16
|
configs: {
|
|
15
17
|
recommended: {};
|
package/build/plugin.js
CHANGED
|
@@ -4,6 +4,8 @@ import { interfaceNoCommaRule } from "./rules/interface-no-commas";
|
|
|
4
4
|
import { numberPropertyRule } from "./rules/number-property";
|
|
5
5
|
import { lowerCaseFtCssVariables } from "./rules/lower-case-ft-css-variables";
|
|
6
6
|
import { ftCssVariableNames } from "./rules/ft-css-variable-names";
|
|
7
|
+
import { customElementsRule } from "./rules/custom-elements";
|
|
8
|
+
import { indexDefineImportRule } from "./rules/index-define-import";
|
|
7
9
|
const plugin = {
|
|
8
10
|
meta: {
|
|
9
11
|
name: "eslint-plugin-fluid-topics",
|
|
@@ -16,6 +18,8 @@ const plugin = {
|
|
|
16
18
|
"number-property": numberPropertyRule,
|
|
17
19
|
"lower-case-ft-css-variables": lowerCaseFtCssVariables,
|
|
18
20
|
"ft-css-variable-names": ftCssVariableNames,
|
|
21
|
+
"custom-elements": customElementsRule,
|
|
22
|
+
"index-define-imports": indexDefineImportRule,
|
|
19
23
|
},
|
|
20
24
|
configs: {
|
|
21
25
|
recommended: {},
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const customElementsRule = {
|
|
2
|
+
meta: {
|
|
3
|
+
docs: {
|
|
4
|
+
description: "Enforces that customElement definitions are in define.ts",
|
|
5
|
+
recommended: false,
|
|
6
|
+
},
|
|
7
|
+
fixable: "code",
|
|
8
|
+
hasSuggestions: true,
|
|
9
|
+
schema: [],
|
|
10
|
+
messages: {
|
|
11
|
+
forbiddenDecorator: "@customElement decorator is not allowed, define the element in a define.ts file.",
|
|
12
|
+
wrongFilename: "customElement calls must be in a define.ts file.",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
return {
|
|
17
|
+
"ClassDeclaration": (node) => {
|
|
18
|
+
var _a;
|
|
19
|
+
const tsClass = node;
|
|
20
|
+
for (const decorator of (_a = tsClass.decorators) !== null && _a !== void 0 ? _a : []) {
|
|
21
|
+
if (decorator.expression.type !== "CallExpression") {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const expression = decorator.expression;
|
|
25
|
+
if (expression.callee.type !== "Identifier") {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const callee = expression.callee;
|
|
29
|
+
if (callee.name === "customElement") {
|
|
30
|
+
context.report({
|
|
31
|
+
loc: decorator.loc,
|
|
32
|
+
messageId: "forbiddenDecorator",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"CallExpression[callee.name='customElement']": (node) => {
|
|
38
|
+
if (node.parent.type === "Decorator") {
|
|
39
|
+
return; // handled by above case
|
|
40
|
+
}
|
|
41
|
+
if (!context.filename.endsWith("define.ts")) {
|
|
42
|
+
context.report({
|
|
43
|
+
loc: node.loc,
|
|
44
|
+
messageId: "wrongFilename",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const indexDefineImportRule = {
|
|
2
|
+
meta: {
|
|
3
|
+
docs: {
|
|
4
|
+
description: "Enforces full imports in the form \"@fluid-topics/ft-component/build/define\"",
|
|
5
|
+
recommended: false,
|
|
6
|
+
},
|
|
7
|
+
fixable: "code",
|
|
8
|
+
hasSuggestions: true,
|
|
9
|
+
schema: [],
|
|
10
|
+
messages: {
|
|
11
|
+
forbiddenImport: "Using imports in the form `import \"@fluid-topics/ft-component\"` does not work, you need to import define file.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
create(context) {
|
|
15
|
+
return {
|
|
16
|
+
"ImportDeclaration": (node) => {
|
|
17
|
+
if (node.specifiers.length !== 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const packageName = node.source.value;
|
|
21
|
+
console.log(packageName);
|
|
22
|
+
if (packageName.startsWith("@fluid-topics/ft") && !packageName.endsWith("/build/define")) {
|
|
23
|
+
const cleanName = packageName.replace(/\/$/, "");
|
|
24
|
+
context.report({
|
|
25
|
+
loc: node.loc,
|
|
26
|
+
messageId: "forbiddenImport",
|
|
27
|
+
fix: (fixer) => fixer.replaceTextRange(node.source.range, `"${cleanName}/build/define"`),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-eslint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "ESlint rules for web components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit"
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"lit": "3.1.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "139801842483cdd25e6c0d850431dfb2b930f394"
|
|
25
25
|
}
|