@html-eslint/eslint-plugin 0.9.0-alpha.0 → 0.11.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 (38) hide show
  1. package/lib/configs/recommended.js +1 -0
  2. package/lib/constants/node-types.js +0 -5
  3. package/lib/constants/obsolete-tags.js +1 -1
  4. package/lib/constants/rule-category.js +0 -5
  5. package/lib/constants/void-elements.js +1 -1
  6. package/lib/rules/element-newline.js +29 -9
  7. package/lib/rules/id-naming-convention.js +16 -9
  8. package/lib/rules/indent.js +19 -7
  9. package/lib/rules/index.js +14 -2
  10. package/lib/rules/no-abstract-roles.js +62 -0
  11. package/lib/rules/no-accesskey-attrs.js +45 -0
  12. package/lib/rules/no-aria-hidden-body.js +46 -0
  13. package/lib/rules/no-duplicate-attrs.js +54 -0
  14. package/lib/rules/no-duplicate-id.js +7 -0
  15. package/lib/rules/no-extra-spacing-attrs.js +27 -5
  16. package/lib/rules/no-inline-styles.js +7 -0
  17. package/lib/rules/no-multiple-empty-lines.js +90 -0
  18. package/lib/rules/no-multiple-h1.js +7 -0
  19. package/lib/rules/no-non-scalable-viewport.js +7 -0
  20. package/lib/rules/no-obsolete-tags.js +7 -0
  21. package/lib/rules/no-positive-tabindex.js +7 -0
  22. package/lib/rules/no-skip-heading-levels.js +7 -0
  23. package/lib/rules/no-target-blank.js +7 -0
  24. package/lib/rules/quotes.js +30 -2
  25. package/lib/rules/require-button-type.js +58 -0
  26. package/lib/rules/require-closing-tags.js +11 -4
  27. package/lib/rules/require-doctype.js +7 -0
  28. package/lib/rules/require-frame-title.js +7 -0
  29. package/lib/rules/require-img-alt.js +13 -0
  30. package/lib/rules/require-lang.js +10 -4
  31. package/lib/rules/require-li-container.js +13 -1
  32. package/lib/rules/require-meta-charset.js +12 -1
  33. package/lib/rules/require-meta-description.js +15 -4
  34. package/lib/rules/require-meta-viewport.js +12 -8
  35. package/lib/rules/require-title.js +9 -3
  36. package/lib/rules/utils/node-utils.js +27 -5
  37. package/lib/types.d.ts +104 -33
  38. package/package.json +8 -4
@@ -1,13 +1,17 @@
1
- // @ts-check
2
1
  /**
3
- * @typedef {import("../../types").HTMLNode} HTMLNode
2
+ * @typedef {import("../../types").ElementNode} ElementNode
4
3
  * @typedef {import("../../types").AttrNode} AttrNode
4
+ * @typedef {import("../../types").AnyNode} AnyNode
5
+ * @typedef {import("../../types").TextNode} TextNode
6
+ * @typedef {import("../../types").BaseNode} BaseNode
7
+ * @typedef {import("../../types").TextLineNode} TextLineNode
8
+ * @typedef {import("../../types").CommentNode} CommentNode
5
9
  */
6
10
 
7
11
  module.exports = {
8
12
  /**
9
13
  * Find attribute by name in the given node
10
- * @param {HTMLNode} node node
14
+ * @param {ElementNode} node node
11
15
  * @param {string} name attribute name
12
16
  * @return {AttrNode | void}
13
17
  */
@@ -20,7 +24,7 @@ module.exports = {
20
24
  },
21
25
  /**
22
26
  * Checks a node has attribute with the given name or not.
23
- * @param {HTMLNode} node node
27
+ * @param {ElementNode} node node
24
28
  * @param {string} name attribute name
25
29
  * @return {boolean} `true` if the node has a attribute, otherwise `false`.
26
30
  */
@@ -29,10 +33,28 @@ module.exports = {
29
33
  },
30
34
  /**
31
35
  * Checks whether a node's all tokens are on the same line or not.
32
- * @param {HTMLNode} node A node to check
36
+ * @param {ElementNode} node A node to check
33
37
  * @returns {boolean} `true` if a node's tokens are on the same line, otherwise `false`.
34
38
  */
35
39
  isNodeTokensOnSameLine(node) {
36
40
  return node.loc.start.line === node.loc.end.line;
37
41
  },
42
+
43
+ /**
44
+ * Checks whether a node is a TextNode or not.
45
+ * @param {Object} node A node to check
46
+ * @returns {node is TextNode} `true` if a node is `TextNode`, otherwise `false`.
47
+ */
48
+ isTextNode(node) {
49
+ return !!(node && node.type === "text" && typeof node.value === "string");
50
+ },
51
+
52
+ /**
53
+ * Checks whether a node is a CommentNode or not.
54
+ * @param {Object} node A node to check
55
+ * @returns {node is CommentNode} `true` if a node is `CommentNode`, otherwise `false`.
56
+ */
57
+ isCommentNode(node) {
58
+ return !!(node && node.type === "comment");
59
+ },
38
60
  };
package/lib/types.d.ts CHANGED
@@ -1,49 +1,120 @@
1
- export type RuleCategory = {
2
- BEST_PRACTICE: "Best Practice";
3
- SEO: "SEO";
4
- ACCESSIBILITY: "Accessibility";
5
- STYLE: "Style";
6
- };
1
+ import ESTree from "estree";
2
+ import ESLint from "eslint";
3
+
4
+ type Fix = ESLint.Rule.Fix;
5
+ type Token = ESLint.AST.Token;
6
+ export type Range = ESLint.AST.Range;
7
+
8
+ interface RuleListener {
9
+ [key: string]: (node: ElementNode) => void;
10
+ }
11
+
12
+ export interface Rule {
13
+ create(context: Context): RuleListener;
14
+ meta?: ESLint.Rule.RuleMetaData;
15
+ }
16
+
17
+ interface RuleFixer {
18
+ insertTextAfter(nodeOrToken: AnyNode | Token, text: string): Fix;
19
+
20
+ insertTextAfterRange(range: Range, text: string): Fix;
21
+
22
+ insertTextBefore(nodeOrToken: AnyNode | Token, text: string): Fix;
23
+
24
+ insertTextBeforeRange(range: Range, text: string): Fix;
25
+
26
+ remove(nodeOrToken: AnyNode | Token): Fix;
27
+
28
+ removeRange(range: Range): Fix;
29
+
30
+ replaceText(nodeOrToken: AnyNode | Token, text: string): Fix;
31
+
32
+ replaceTextRange(range: Range, text: string): Fix;
33
+ }
34
+
35
+ interface ReportDescriptorOptionsBase {
36
+ data?: { [key: string]: string };
37
+
38
+ fix?:
39
+ | null
40
+ | ((fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[]);
41
+ }
7
42
 
8
- export type NodeTypes = {
9
- PROGRAM: "Program";
10
- TEXT: "text";
11
- TITLE: "Title";
12
- PRE: "Pre";
13
- MENU: "Menu";
14
- OL: "Ol";
15
- UL: "Ul";
16
- SCRIPT: "Script";
17
- XMP: "Xmp";
18
- META: "Meta";
19
- STYLE: "Style";
43
+ type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
44
+ type SuggestionReportDescriptor = SuggestionDescriptorMessage &
45
+ ReportDescriptorOptionsBase;
46
+
47
+ interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
48
+ suggest?: SuggestionReportDescriptor[] | null;
49
+ }
50
+
51
+ type ReportDescriptor = ReportDescriptorMessage &
52
+ ReportDescriptorLocation &
53
+ ReportDescriptorOptions;
54
+ type ReportDescriptorMessage = { message: string } | { messageId: string };
55
+ type ReportDescriptorLocation = {
56
+ node?: BaseNode;
57
+ loc?: ESLint.AST.SourceLocation;
58
+ line?: number;
59
+ column?: number;
20
60
  };
21
61
 
22
- interface BaseNode {
62
+ export interface Context extends Omit<ESLint.Rule.RuleContext, "report"> {
63
+ report(descriptor: ReportDescriptor): void;
64
+ }
65
+
66
+ export interface BaseNode {
67
+ parent?: null | AnyNode;
68
+ range: [number, number];
23
69
  start: number;
24
70
  end: number;
25
- range: [number, number];
26
71
  loc: {
27
- end: {
28
- line: number;
29
- column: number;
30
- };
31
- start: {
32
- line: number;
33
- column: number;
34
- };
72
+ start: ESTree.Position;
73
+ end: ESTree.Position;
35
74
  };
75
+ type?: string;
76
+ }
77
+
78
+ export interface TagNode extends BaseNode {
79
+ type: undefined;
36
80
  }
37
81
 
38
- export interface HTMLNode extends BaseNode {
39
- childNodes?: HTMLNode[];
40
- startTag?: BaseNode;
41
- endTag?: BaseNode;
82
+ export interface TextLineNode extends BaseNode {
83
+ textLine: string;
84
+ }
85
+
86
+ export interface TextNode extends BaseNode {
87
+ type: "text";
88
+ value: string;
89
+ lineNodes: TextLineNode[];
90
+ }
91
+
92
+ export interface ElementNode extends BaseNode {
42
93
  type: string;
43
- attrs?: AttrNode[];
94
+ tagName: string;
95
+ attrs: AttrNode[];
96
+ childNodes: ElementNode[];
97
+ startTag?: TagNode;
98
+ endTag?: TagNode;
44
99
  }
45
100
 
46
101
  export interface AttrNode extends BaseNode {
47
102
  name: string;
48
103
  value: string;
49
104
  }
105
+
106
+ export interface CommentNode extends BaseNode {
107
+ type: "comment";
108
+ value: string;
109
+ startTag?: TagNode;
110
+ endTag?: TagNode;
111
+ lineNodes: TextLineNode[];
112
+ }
113
+
114
+ export type AnyNode =
115
+ | AttrNode
116
+ | ElementNode
117
+ | TextNode
118
+ | TextLineNode
119
+ | TagNode
120
+ | CommentNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-eslint/eslint-plugin",
3
- "version": "0.9.0-alpha.0",
3
+ "version": "0.11.0",
4
4
  "description": "ESLint plugin for html",
5
5
  "author": "yeonjuan",
6
6
  "homepage": "https://github.com/yeonjuan/html-eslint#readme",
@@ -21,7 +21,8 @@
21
21
  "url": "git+https://github.com/yeonjuan/html-eslint.git"
22
22
  },
23
23
  "scripts": {
24
- "test": "jest --coverage"
24
+ "test": "jest --coverage",
25
+ "check:ts": "tsc"
25
26
  },
26
27
  "bugs": {
27
28
  "url": "https://github.com/yeonjuan/html-eslint/issues"
@@ -39,7 +40,10 @@
39
40
  "accessibility"
40
41
  ],
41
42
  "devDependencies": {
42
- "@html-eslint/parser": "^0.9.0-alpha.0"
43
+ "@html-eslint/parser": "^0.11.0",
44
+ "@types/eslint": "^7.2.10",
45
+ "@types/estree": "^0.0.47",
46
+ "typescript": "^4.2.4"
43
47
  },
44
- "gitHead": "442c5d402ce891b088b1548fe8a27fe9fadc91c3"
48
+ "gitHead": "a3873ecefae3b9306a5e98985cf4ccdbde95299a"
45
49
  }