eslint-plugin-lit 1.12.0 → 1.13.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.
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Disallows class fields with same name as
|
|
1
|
+
# Disallows class fields with same name as reactive properties
|
|
2
2
|
|
|
3
|
-
Class fields set with same names as
|
|
3
|
+
Class fields set with same names as reactive properties will not trigger updates as expected. They will overwrite
|
|
4
4
|
accessors used for detecting changes. See https://lit.dev/msg/class-field-shadowing for more information.
|
|
5
5
|
|
|
6
6
|
## Rule Details
|
|
7
7
|
|
|
8
|
-
This rule disallows class fields with same name as
|
|
8
|
+
This rule disallows class fields with same name as reactive properties.
|
|
9
9
|
|
|
10
10
|
The following patterns are considered warnings:
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ const rule = {
|
|
|
17
17
|
schema: [],
|
|
18
18
|
messages: {
|
|
19
19
|
noClassfieldShadowing: 'The {{ prop }} property is a class field which has the same name as ' +
|
|
20
|
-
'
|
|
20
|
+
'a reactive property which could have unintended side-effects.'
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
create(context) {
|
|
@@ -27,7 +27,8 @@ const rule = {
|
|
|
27
27
|
const propertyMap = (0, util_1.getPropertyMap)(node);
|
|
28
28
|
const classMembers = (0, util_1.getClassFields)(node);
|
|
29
29
|
for (const [prop, { key }] of propertyMap.entries()) {
|
|
30
|
-
|
|
30
|
+
const member = classMembers.get(prop);
|
|
31
|
+
if (member && !(0, util_1.hasLitPropertyDecorator)(member)) {
|
|
31
32
|
context.report({
|
|
32
33
|
node: key,
|
|
33
34
|
messageId: 'noClassfieldShadowing',
|
package/lib/util.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export interface BabelDecorator extends ESTree.BaseNode {
|
|
|
6
6
|
export interface BabelProperty extends ESTree.MethodDefinition {
|
|
7
7
|
decorators?: BabelDecorator[];
|
|
8
8
|
}
|
|
9
|
+
export type DecoratedNode = ESTree.Node & {
|
|
10
|
+
decorators?: BabelDecorator[];
|
|
11
|
+
};
|
|
9
12
|
/**
|
|
10
13
|
* Returns if the given node is a lit class
|
|
11
14
|
* @param {ESTree.Class} clazz
|
|
@@ -46,6 +49,12 @@ export declare function getClassFields(node: ESTree.Class): ReadonlyMap<string,
|
|
|
46
49
|
* @return {ReadonlyMap<string, ESTreeObjectExpression>}
|
|
47
50
|
*/
|
|
48
51
|
export declare function getPropertyMap(node: ESTree.Class): ReadonlyMap<string, PropertyMapEntry>;
|
|
52
|
+
/**
|
|
53
|
+
* Determines if a node has a lit property decorator
|
|
54
|
+
* @param {ESTree.Node} node Node to test
|
|
55
|
+
* @return {boolean}
|
|
56
|
+
*/
|
|
57
|
+
export declare function hasLitPropertyDecorator(node: ESTree.Node): boolean;
|
|
49
58
|
/**
|
|
50
59
|
* Generates a placeholder string for a given quasi
|
|
51
60
|
*
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.templateExpressionToHtml = exports.isExpressionPlaceholder = exports.getExpressionPlaceholder = exports.getPropertyMap = exports.getClassFields = exports.extractPropertyEntry = exports.getIdentifierName = exports.isLitClass = void 0;
|
|
3
|
+
exports.templateExpressionToHtml = exports.isExpressionPlaceholder = exports.getExpressionPlaceholder = exports.hasLitPropertyDecorator = exports.getPropertyMap = exports.getClassFields = exports.extractPropertyEntry = exports.getIdentifierName = exports.isLitClass = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Returns if given node has a lit identifier
|
|
6
6
|
* @param {ESTree.Node} node
|
|
@@ -107,6 +107,8 @@ function getClassFields(node) {
|
|
|
107
107
|
return result;
|
|
108
108
|
}
|
|
109
109
|
exports.getClassFields = getClassFields;
|
|
110
|
+
const propertyDecorators = ['state', 'property', 'internalProperty'];
|
|
111
|
+
const internalDecorators = ['state', 'internalProperty'];
|
|
110
112
|
/**
|
|
111
113
|
* Get the properties object of an element class
|
|
112
114
|
*
|
|
@@ -116,8 +118,6 @@ exports.getClassFields = getClassFields;
|
|
|
116
118
|
function getPropertyMap(node) {
|
|
117
119
|
var _a;
|
|
118
120
|
const result = new Map();
|
|
119
|
-
const propertyDecorators = ['state', 'property', 'internalProperty'];
|
|
120
|
-
const internalDecorators = ['state', 'internalProperty'];
|
|
121
121
|
for (const member of node.body.body) {
|
|
122
122
|
if (member.type === 'PropertyDefinition' &&
|
|
123
123
|
member.static &&
|
|
@@ -192,6 +192,26 @@ function getPropertyMap(node) {
|
|
|
192
192
|
return result;
|
|
193
193
|
}
|
|
194
194
|
exports.getPropertyMap = getPropertyMap;
|
|
195
|
+
/**
|
|
196
|
+
* Determines if a node has a lit property decorator
|
|
197
|
+
* @param {ESTree.Node} node Node to test
|
|
198
|
+
* @return {boolean}
|
|
199
|
+
*/
|
|
200
|
+
function hasLitPropertyDecorator(node) {
|
|
201
|
+
const decoratedNode = node;
|
|
202
|
+
if (!decoratedNode.decorators || !Array.isArray(decoratedNode.decorators)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
for (const decorator of decoratedNode.decorators) {
|
|
206
|
+
if (decorator.expression.type === 'CallExpression' &&
|
|
207
|
+
decorator.expression.callee.type === 'Identifier' &&
|
|
208
|
+
propertyDecorators.includes(decorator.expression.callee.name)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
exports.hasLitPropertyDecorator = hasLitPropertyDecorator;
|
|
195
215
|
/**
|
|
196
216
|
* Generates a placeholder string for a given quasi
|
|
197
217
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-lit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "lit-html support for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"eslint": ">= 5"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@babel/eslint-parser": "^7.
|
|
53
|
-
"@babel/plugin-proposal-decorators": "^7.
|
|
52
|
+
"@babel/eslint-parser": "^7.24.5",
|
|
53
|
+
"@babel/plugin-proposal-decorators": "^7.24.1",
|
|
54
54
|
"@types/chai": "^4.2.16",
|
|
55
55
|
"@types/eslint": "^8.4.6",
|
|
56
56
|
"@types/estree": "^1.0.0",
|