eslint-plugin-lit 1.7.1 → 1.8.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.
Files changed (77) hide show
  1. package/README.md +1 -0
  2. package/custom_types/espree.d.ts +0 -0
  3. package/custom_types/requireindex.d.ts +0 -0
  4. package/docs/rules/attribute-value-entities.md +0 -0
  5. package/docs/rules/ban-attributes.md +0 -0
  6. package/docs/rules/binding-positions.md +0 -0
  7. package/docs/rules/no-duplicate-template-bindings.md +0 -0
  8. package/docs/rules/no-invalid-escape-sequences.md +0 -0
  9. package/docs/rules/no-invalid-html.md +0 -0
  10. package/docs/rules/no-legacy-imports.md +0 -0
  11. package/docs/rules/no-legacy-template-syntax.md +0 -0
  12. package/docs/rules/no-native-attributes.md +39 -0
  13. package/docs/rules/no-private-properties.md +0 -0
  14. package/docs/rules/no-property-change-update.md +0 -0
  15. package/docs/rules/no-template-arrow.md +0 -0
  16. package/docs/rules/no-template-bind.md +0 -0
  17. package/docs/rules/no-template-map.md +0 -0
  18. package/docs/rules/no-this-assign-in-render.md +0 -0
  19. package/docs/rules/no-useless-template-literals.md +0 -0
  20. package/docs/rules/no-value-attribute.md +0 -0
  21. package/docs/rules/prefer-nothing.md +0 -0
  22. package/docs/rules/prefer-static-styles.md +0 -0
  23. package/docs/rules/quoted-expressions.md +0 -0
  24. package/docs/rules/value-after-constraints.md +0 -0
  25. package/lib/configs/all.d.ts +1 -0
  26. package/lib/configs/all.js +1 -0
  27. package/lib/configs/recommended.d.ts +0 -0
  28. package/lib/configs/recommended.js +0 -0
  29. package/lib/index.d.ts +1 -0
  30. package/lib/index.js +0 -0
  31. package/lib/rules/attribute-value-entities.d.ts +0 -0
  32. package/lib/rules/attribute-value-entities.js +0 -0
  33. package/lib/rules/ban-attributes.d.ts +0 -0
  34. package/lib/rules/ban-attributes.js +0 -0
  35. package/lib/rules/binding-positions.d.ts +0 -0
  36. package/lib/rules/binding-positions.js +0 -0
  37. package/lib/rules/no-duplicate-template-bindings.d.ts +0 -0
  38. package/lib/rules/no-duplicate-template-bindings.js +0 -0
  39. package/lib/rules/no-invalid-escape-sequences.d.ts +0 -0
  40. package/lib/rules/no-invalid-escape-sequences.js +0 -0
  41. package/lib/rules/no-invalid-html.d.ts +0 -0
  42. package/lib/rules/no-invalid-html.js +0 -0
  43. package/lib/rules/no-legacy-imports.d.ts +0 -0
  44. package/lib/rules/no-legacy-imports.js +0 -0
  45. package/lib/rules/no-legacy-template-syntax.d.ts +0 -0
  46. package/lib/rules/no-legacy-template-syntax.js +0 -0
  47. package/lib/rules/no-native-attributes.d.ts +7 -0
  48. package/lib/rules/no-native-attributes.js +78 -0
  49. package/lib/rules/no-private-properties.d.ts +0 -0
  50. package/lib/rules/no-private-properties.js +0 -0
  51. package/lib/rules/no-property-change-update.d.ts +0 -0
  52. package/lib/rules/no-property-change-update.js +0 -0
  53. package/lib/rules/no-template-arrow.d.ts +0 -0
  54. package/lib/rules/no-template-arrow.js +0 -0
  55. package/lib/rules/no-template-bind.d.ts +0 -0
  56. package/lib/rules/no-template-bind.js +0 -0
  57. package/lib/rules/no-template-map.d.ts +0 -0
  58. package/lib/rules/no-template-map.js +0 -0
  59. package/lib/rules/no-this-assign-in-render.d.ts +0 -0
  60. package/lib/rules/no-this-assign-in-render.js +0 -0
  61. package/lib/rules/no-useless-template-literals.d.ts +0 -0
  62. package/lib/rules/no-useless-template-literals.js +0 -0
  63. package/lib/rules/no-value-attribute.d.ts +0 -0
  64. package/lib/rules/no-value-attribute.js +0 -0
  65. package/lib/rules/prefer-nothing.d.ts +0 -0
  66. package/lib/rules/prefer-nothing.js +0 -0
  67. package/lib/rules/prefer-static-styles.d.ts +0 -0
  68. package/lib/rules/prefer-static-styles.js +0 -0
  69. package/lib/rules/quoted-expressions.d.ts +0 -0
  70. package/lib/rules/quoted-expressions.js +0 -0
  71. package/lib/rules/value-after-constraints.d.ts +0 -0
  72. package/lib/rules/value-after-constraints.js +3 -1
  73. package/lib/template-analyzer.d.ts +0 -0
  74. package/lib/template-analyzer.js +0 -0
  75. package/lib/util.d.ts +0 -0
  76. package/lib/util.js +15 -0
  77. package/package.json +1 -1
package/README.md CHANGED
@@ -64,6 +64,7 @@ If you want more fine-grained configuration, you can instead add a snippet like
64
64
  - [lit/no-invalid-html](docs/rules/no-invalid-html.md)
65
65
  - [lit/no-legacy-imports](docs/rules/no-legacy-imports.md)
66
66
  - [lit/no-legacy-template-syntax](docs/rules/no-legacy-template-syntax.md)
67
+ - [lit/no-native-attributes](docs/rules/no-native-attributes.md)
67
68
  - [lit/no-private-properties](docs/rules/no-private-properties.md)
68
69
  - [lit/no-property-change-update](docs/rules/no-property-change-update.md)
69
70
  - [lit/no-template-arrow](docs/rules/no-template-arrow.md)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ # Disallows use of native attributes as properties (no-native-attributes)
2
+
3
+ Using global native attributes as lit properties can have unintended effects,
4
+ like for example the native `title` attribute will display a tooltip on hover
5
+ over your custom element, and and may affect the accessibility of your component
6
+ unintentionally.
7
+
8
+ ## Rule Details
9
+
10
+ This rule disallows using global native attributes as lit properties.
11
+
12
+ The following patterns are considered warnings:
13
+
14
+ ```ts
15
+ class MyEl extends LitElement {
16
+ static get properties() {
17
+ return {
18
+ title: { type: String },
19
+ role: { type: String }
20
+ };
21
+ }
22
+ }
23
+ ```
24
+
25
+ The following patterns are not warnings:
26
+
27
+ ```ts
28
+ class MyEl extends LitElement {
29
+ static get properties() {
30
+ return {
31
+ foo: { type: String }
32
+ };
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## When Not To Use It
38
+
39
+ If you don't care about overriding global native attributes.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -12,6 +12,7 @@ declare const config: {
12
12
  'lit/no-property-change-update': string;
13
13
  'lit/no-template-arrow': string;
14
14
  'lit/no-template-bind': string;
15
+ 'lit/no-native-attributes': string;
15
16
  'lit/no-template-map': string;
16
17
  'lit/no-this-assign-in-render': string;
17
18
  'lit/no-useless-template-literals': string;
@@ -14,6 +14,7 @@ const config = {
14
14
  'lit/no-property-change-update': 'error',
15
15
  'lit/no-template-arrow': 'error',
16
16
  'lit/no-template-bind': 'error',
17
+ 'lit/no-native-attributes': 'error',
17
18
  'lit/no-template-map': 'error',
18
19
  'lit/no-this-assign-in-render': 'error',
19
20
  'lit/no-useless-template-literals': 'error',
File without changes
File without changes
package/lib/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export declare const configs: {
14
14
  'lit/no-property-change-update': string;
15
15
  'lit/no-template-arrow': string;
16
16
  'lit/no-template-bind': string;
17
+ 'lit/no-native-attributes': string;
17
18
  'lit/no-template-map': string;
18
19
  'lit/no-this-assign-in-render': string;
19
20
  'lit/no-useless-template-literals': string;
package/lib/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @fileoverview Disallows use of native attributes as properties
3
+ * @author Pascal Schilp <https://github.com/thepassle>
4
+ */
5
+ import { Rule } from 'eslint';
6
+ declare const rule: Rule.RuleModule;
7
+ export = rule;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Disallows use of native attributes as properties
4
+ * @author Pascal Schilp <https://github.com/thepassle>
5
+ */
6
+ const util_1 = require("../util");
7
+ // Taken from https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
8
+ const NATIVE_ATTRS = [
9
+ 'accesskey',
10
+ 'autocapitalize',
11
+ 'autofocus',
12
+ 'class',
13
+ 'contenteditable',
14
+ 'contextmenu',
15
+ 'dir',
16
+ 'draggable',
17
+ 'enterkeyhint',
18
+ 'exportparts',
19
+ 'hidden',
20
+ 'id',
21
+ 'inert',
22
+ 'inputmode',
23
+ 'is',
24
+ 'itemid',
25
+ 'itemprop',
26
+ 'itemref',
27
+ 'itemscope',
28
+ 'itemtype',
29
+ 'lang',
30
+ 'nonce',
31
+ 'part',
32
+ 'role',
33
+ 'slot',
34
+ 'spellcheck',
35
+ 'style',
36
+ 'tabindex',
37
+ 'title',
38
+ 'translate',
39
+ 'virtualkeyboardpolicy'
40
+ ];
41
+ //------------------------------------------------------------------------------
42
+ // Rule Definition
43
+ //------------------------------------------------------------------------------
44
+ const rule = {
45
+ meta: {
46
+ docs: {
47
+ description: 'Disallows use of native attributes as properties',
48
+ recommended: false,
49
+ url: 'https://github.com/43081j/eslint-plugin-lit/blob/master/docs/rules/no-native-attributes.md'
50
+ },
51
+ schema: [],
52
+ messages: {
53
+ noNativeAttributes: 'The {{ prop }} attribute is a native global attribute. ' +
54
+ 'Using it as a property could have unintended side-effects.'
55
+ }
56
+ },
57
+ create(context) {
58
+ // variables should be defined here
59
+ //----------------------------------------------------------------------
60
+ // Public
61
+ //----------------------------------------------------------------------
62
+ return {
63
+ 'ClassExpression,ClassDeclaration': (node) => {
64
+ const propertyMap = (0, util_1.getPropertyMap)(node);
65
+ for (const [prop] of propertyMap.entries()) {
66
+ if (NATIVE_ATTRS.includes(prop)) {
67
+ context.report({
68
+ node: node,
69
+ messageId: 'noNativeAttributes',
70
+ data: { prop }
71
+ });
72
+ }
73
+ }
74
+ }
75
+ };
76
+ }
77
+ };
78
+ module.exports = rule;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -39,7 +39,9 @@ const rule = {
39
39
  const analyzer = template_analyzer_1.TemplateAnalyzer.create(node);
40
40
  analyzer.traverse({
41
41
  enterElement: (element) => {
42
- if (element.tagName !== 'input' || !element.sourceCodeLocation) {
42
+ var _a;
43
+ if (element.tagName !== 'input' ||
44
+ !((_a = element.sourceCodeLocation) === null || _a === void 0 ? void 0 : _a.attrs)) {
43
45
  return;
44
46
  }
45
47
  const valueName = element.attribs['.value'] ? '.value' : 'value';
File without changes
File without changes
package/lib/util.d.ts CHANGED
File without changes
package/lib/util.js CHANGED
@@ -51,10 +51,25 @@ exports.extractPropertyEntry = extractPropertyEntry;
51
51
  * @return {ReadonlyMap<string, ESTreeObjectExpression>}
52
52
  */
53
53
  function getPropertyMap(node) {
54
+ var _a;
54
55
  const result = new Map();
55
56
  const propertyDecorators = ['state', 'property', 'internalProperty'];
56
57
  const internalDecorators = ['state', 'internalProperty'];
57
58
  for (const member of node.body.body) {
59
+ if (member.type === 'PropertyDefinition' &&
60
+ member.static &&
61
+ member.key.type === 'Identifier' &&
62
+ member.key.name === 'properties' &&
63
+ ((_a = member.value) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
64
+ for (const prop of member.value.properties) {
65
+ if (prop.type === 'Property') {
66
+ const name = getIdentifierName(prop.key);
67
+ if (name && prop.value.type === 'ObjectExpression') {
68
+ result.set(name, extractPropertyEntry(prop.value));
69
+ }
70
+ }
71
+ }
72
+ }
58
73
  if (member.type === 'MethodDefinition' &&
59
74
  member.static &&
60
75
  member.kind === 'get' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-lit",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "lit-html support for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "files": [