eslint-plugin-lit 1.8.3 → 1.9.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.
package/README.md CHANGED
@@ -59,6 +59,7 @@ If you want more fine-grained configuration, you can instead add a snippet like
59
59
  - [lit/attribute-value-entities](docs/rules/attribute-value-entities.md)
60
60
  - [lit/ban-attributes](docs/rules/ban-attributes.md)
61
61
  - [lit/binding-positions](docs/rules/binding-positions.md)
62
+ - [lit/lifecycle-super](docs/rules/lifecycle-super.md)
62
63
  - [lit/no-duplicate-template-bindings](docs/rules/no-duplicate-template-bindings.md)
63
64
  - [lit/no-invalid-escape-sequences](docs/rules/no-invalid-escape-sequences.md)
64
65
  - [lit/no-invalid-html](docs/rules/no-invalid-html.md)
@@ -0,0 +1,40 @@
1
+ # Enforces calling `super` in lifecycle methods (lifecycle-super)
2
+
3
+ Enforces that `super` is called in lifecycle methods which require it.
4
+
5
+ For example, the `connectedCallback` should call `super.connectedCallback()` to
6
+ avoid interrupting lit's rendering.
7
+
8
+ ## Rule Details
9
+
10
+ This rule enforces calling of `super` in the following lifecycle methods:
11
+
12
+ - `update`
13
+ - `connectedCallback`
14
+ - `disconnectedCallback`
15
+
16
+ The following patterns are considered warnings:
17
+
18
+ ```ts
19
+ class Foo extends LitElement {
20
+ connectedCallback() {
21
+ doSomething();
22
+ }
23
+ }
24
+ ```
25
+
26
+ The following patterns are not warnings:
27
+
28
+ ```ts
29
+ class Foo extends LitElement {
30
+ connectedCallback() {
31
+ super.connectedCallback();
32
+ doSomething();
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## When Not To Use It
38
+
39
+ If you want to override lit's default implementation of a lifecycle method,
40
+ you should disable this rule.
@@ -3,16 +3,17 @@ declare const config: {
3
3
  rules: {
4
4
  'lit/attribute-value-entities': string;
5
5
  'lit/binding-positions': string;
6
+ 'lit/lifecycle-super': string;
6
7
  'lit/no-duplicate-template-bindings': string;
7
8
  'lit/no-invalid-escape-sequences': string;
8
9
  'lit/no-invalid-html': string;
9
10
  'lit/no-legacy-imports': string;
10
11
  'lit/no-legacy-template-syntax': string;
12
+ 'lit/no-native-attributes': string;
11
13
  'lit/no-private-properties': string;
12
14
  'lit/no-property-change-update': string;
13
15
  'lit/no-template-arrow': string;
14
16
  'lit/no-template-bind': string;
15
- 'lit/no-native-attributes': string;
16
17
  'lit/no-template-map': string;
17
18
  'lit/no-this-assign-in-render': string;
18
19
  'lit/no-useless-template-literals': string;
@@ -5,16 +5,17 @@ const config = {
5
5
  rules: {
6
6
  'lit/attribute-value-entities': 'error',
7
7
  'lit/binding-positions': 'error',
8
+ 'lit/lifecycle-super': 'error',
8
9
  'lit/no-duplicate-template-bindings': 'error',
9
10
  'lit/no-invalid-escape-sequences': 'error',
10
11
  'lit/no-invalid-html': 'error',
11
12
  'lit/no-legacy-imports': 'error',
12
13
  'lit/no-legacy-template-syntax': 'error',
14
+ 'lit/no-native-attributes': 'error',
13
15
  'lit/no-private-properties': 'error',
14
16
  'lit/no-property-change-update': 'error',
15
17
  'lit/no-template-arrow': 'error',
16
18
  'lit/no-template-bind': 'error',
17
- 'lit/no-native-attributes': 'error',
18
19
  'lit/no-template-map': 'error',
19
20
  'lit/no-this-assign-in-render': 'error',
20
21
  'lit/no-useless-template-literals': 'error',
package/lib/index.d.ts CHANGED
@@ -5,16 +5,17 @@ export declare const configs: {
5
5
  rules: {
6
6
  'lit/attribute-value-entities': string;
7
7
  'lit/binding-positions': string;
8
+ 'lit/lifecycle-super': string;
8
9
  'lit/no-duplicate-template-bindings': string;
9
10
  'lit/no-invalid-escape-sequences': string;
10
11
  'lit/no-invalid-html': string;
11
12
  'lit/no-legacy-imports': string;
12
13
  'lit/no-legacy-template-syntax': string;
14
+ 'lit/no-native-attributes': string;
13
15
  'lit/no-private-properties': string;
14
16
  'lit/no-property-change-update': string;
15
17
  'lit/no-template-arrow': string;
16
18
  'lit/no-template-bind': string;
17
- 'lit/no-native-attributes': string;
18
19
  'lit/no-template-map': string;
19
20
  'lit/no-this-assign-in-render': string;
20
21
  'lit/no-useless-template-literals': string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @fileoverview Enforces calling `super` in lifecycle methods
3
+ * @author James Garbutt <https://github.com/43081j>
4
+ */
5
+ import { Rule } from 'eslint';
6
+ declare const rule: Rule.RuleModule;
7
+ export = rule;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Enforces calling `super` in lifecycle methods
4
+ * @author James Garbutt <https://github.com/43081j>
5
+ */
6
+ const methodNames = ['connectedCallback', 'disconnectedCallback', 'update'];
7
+ //------------------------------------------------------------------------------
8
+ // Rule Definition
9
+ //------------------------------------------------------------------------------
10
+ const rule = {
11
+ meta: {
12
+ docs: {
13
+ description: 'Enforces calling `super` in lifecycle methods',
14
+ recommended: false,
15
+ url: 'https://github.com/43081j/eslint-plugin-lit/blob/master/docs/rules/lifecycle-super.md'
16
+ },
17
+ schema: [],
18
+ messages: {
19
+ callSuper: 'You must call `super.{{method}}` to avoid interrupting ' +
20
+ 'the lit rendering lifecycle'
21
+ }
22
+ },
23
+ create(context) {
24
+ // variables should be defined here
25
+ let inElement = false;
26
+ let currentMethod = null;
27
+ let superSeen = false;
28
+ //----------------------------------------------------------------------
29
+ // Helpers
30
+ //----------------------------------------------------------------------
31
+ /**
32
+ * Class entered
33
+ *
34
+ * @param {ESTree.Class} node Node entered
35
+ * @return {void}
36
+ */
37
+ function classEnter(node) {
38
+ if (!node.superClass ||
39
+ node.superClass.type !== 'Identifier' ||
40
+ node.superClass.name !== 'LitElement') {
41
+ return;
42
+ }
43
+ inElement = true;
44
+ }
45
+ /**
46
+ * Class exited
47
+ *
48
+ * @return {void}
49
+ */
50
+ function classExit() {
51
+ inElement = false;
52
+ }
53
+ /**
54
+ * Method entered
55
+ *
56
+ * @param {ESTree.MethodDefinition} node Node entered
57
+ * @return {void}
58
+ */
59
+ function methodEnter(node) {
60
+ if (!inElement ||
61
+ node.static === true ||
62
+ node.kind !== 'method' ||
63
+ node.key.type !== 'Identifier' ||
64
+ !methodNames.includes(node.key.name)) {
65
+ return;
66
+ }
67
+ currentMethod = node.key.name;
68
+ }
69
+ /**
70
+ * Method exited
71
+ *
72
+ * @param {ESTree.MethodDefinition} node Node entered
73
+ * @return {void}
74
+ */
75
+ function methodExit(node) {
76
+ if (currentMethod !== null && !superSeen) {
77
+ context.report({
78
+ node,
79
+ messageId: 'callSuper',
80
+ data: {
81
+ method: currentMethod
82
+ }
83
+ });
84
+ }
85
+ currentMethod = null;
86
+ superSeen = false;
87
+ }
88
+ /**
89
+ * Call expression entered
90
+ * @param {ESTree.CallExpression} node Node entered
91
+ * @return {void}
92
+ */
93
+ function callExpressionEnter(node) {
94
+ if (currentMethod === null) {
95
+ return;
96
+ }
97
+ if (node.callee.type === 'MemberExpression' &&
98
+ node.callee.object.type === 'Super' &&
99
+ node.callee.property.type === 'Identifier' &&
100
+ node.callee.property.name === currentMethod) {
101
+ superSeen = true;
102
+ }
103
+ }
104
+ //----------------------------------------------------------------------
105
+ // Public
106
+ //----------------------------------------------------------------------
107
+ return {
108
+ ClassExpression: (node) => classEnter(node),
109
+ ClassDeclaration: (node) => classEnter(node),
110
+ 'ClassExpression:exit': classExit,
111
+ 'ClassDeclaration:exit': classExit,
112
+ MethodDefinition: (node) => methodEnter(node),
113
+ 'MethodDefinition:exit': methodExit,
114
+ CallExpression: (node) => callExpressionEnter(node)
115
+ };
116
+ }
117
+ };
118
+ module.exports = rule;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "eslint-plugin-lit",
3
- "version": "1.8.3",
3
+ "version": "1.9.1",
4
4
  "description": "lit-html support for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
- "lib/!(test)",
7
+ "lib/",
8
+ "!lib/test",
8
9
  "docs",
9
10
  "custom_types"
10
11
  ],