@fluid-topics/ft-eslint 2.0.23 → 2.0.25
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/plugin.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare const plugin: {
|
|
|
12
12
|
"ft-css-variable-names": import("eslint").Rule.RuleModule;
|
|
13
13
|
"custom-elements": import("eslint").Rule.RuleModule;
|
|
14
14
|
"index-define-imports": import("eslint").Rule.RuleModule;
|
|
15
|
+
"lit-async-lifecycle": import("eslint").Rule.RuleModule;
|
|
15
16
|
};
|
|
16
17
|
configs: {
|
|
17
18
|
recommended: {};
|
package/build/plugin.js
CHANGED
|
@@ -6,6 +6,7 @@ import { lowerCaseFtCssVariables } from "./rules/lower-case-ft-css-variables";
|
|
|
6
6
|
import { ftCssVariableNames } from "./rules/ft-css-variable-names";
|
|
7
7
|
import { customElementsRule } from "./rules/custom-elements";
|
|
8
8
|
import { indexDefineImportRule } from "./rules/index-define-import";
|
|
9
|
+
import { litAsyncLifecycleRule } from "./rules/lit-async-lifecycle";
|
|
9
10
|
const plugin = {
|
|
10
11
|
meta: {
|
|
11
12
|
name: "eslint-plugin-fluid-topics",
|
|
@@ -20,6 +21,7 @@ const plugin = {
|
|
|
20
21
|
"ft-css-variable-names": ftCssVariableNames,
|
|
21
22
|
"custom-elements": customElementsRule,
|
|
22
23
|
"index-define-imports": indexDefineImportRule,
|
|
24
|
+
"lit-async-lifecycle": litAsyncLifecycleRule,
|
|
23
25
|
},
|
|
24
26
|
configs: {
|
|
25
27
|
recommended: {},
|
|
@@ -37,6 +39,7 @@ const flatConfigs = {
|
|
|
37
39
|
"ft/number-property": "error",
|
|
38
40
|
"ft/lower-case-ft-css-variables": "error",
|
|
39
41
|
"ft/ft-css-variable-names": "error",
|
|
42
|
+
"ft/lit-async-lifecycle": "warn",
|
|
40
43
|
},
|
|
41
44
|
},
|
|
42
45
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const LIT_LIFECYCLE_METHODS = [
|
|
2
|
+
"willUpdate",
|
|
3
|
+
"willRender",
|
|
4
|
+
"updated",
|
|
5
|
+
"render",
|
|
6
|
+
"firstUpdated",
|
|
7
|
+
"update",
|
|
8
|
+
];
|
|
9
|
+
export const litAsyncLifecycleRule = {
|
|
10
|
+
meta: {
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Warns when LIT lifecycle methods are marked as async, as LIT does not await them",
|
|
13
|
+
recommended: true,
|
|
14
|
+
},
|
|
15
|
+
fixable: "code",
|
|
16
|
+
hasSuggestions: false,
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: {
|
|
19
|
+
asyncLifecycleMethod: "LIT lifecycle method '{{ methodName }}' should not be marked as async. LIT does not await this method, so any returned promise will be ignored.",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
create(context) {
|
|
23
|
+
return {
|
|
24
|
+
"MethodDefinition": (node) => {
|
|
25
|
+
const tsMethod = node;
|
|
26
|
+
if (tsMethod.kind === "get" || tsMethod.kind === "set") {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const methodName = tsMethod.key.type === "Identifier"
|
|
30
|
+
? tsMethod.key.name
|
|
31
|
+
: tsMethod.key.type === "Literal"
|
|
32
|
+
? String(tsMethod.key.value)
|
|
33
|
+
: null;
|
|
34
|
+
if (!methodName || !LIT_LIFECYCLE_METHODS.includes(methodName)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const tsFunction = tsMethod.value;
|
|
38
|
+
if (tsFunction.async) {
|
|
39
|
+
context.report({
|
|
40
|
+
loc: tsMethod.loc,
|
|
41
|
+
messageId: "asyncLifecycleMethod",
|
|
42
|
+
data: {
|
|
43
|
+
methodName,
|
|
44
|
+
},
|
|
45
|
+
fix: (fixer) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const sourceCode = context.sourceCode;
|
|
48
|
+
let token = sourceCode.getFirstToken(tsMethod);
|
|
49
|
+
while (token && token.value !== "async") {
|
|
50
|
+
token = sourceCode.getTokenAfter(token);
|
|
51
|
+
}
|
|
52
|
+
if (!token) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const blankTokenAfterAsync = sourceCode.getTokenAfter(token);
|
|
56
|
+
return fixer.removeRange([token.range[0], (_a = blankTokenAfterAsync === null || blankTokenAfterAsync === void 0 ? void 0 : blankTokenAfterAsync.range[0]) !== null && _a !== void 0 ? _a : token.range[1]]);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-eslint",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.25",
|
|
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": "f7582c9f28ac8fb59807834b4cbdcf09144478cf"
|
|
25
25
|
}
|