@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.
- package/lib/configs/recommended.js +1 -0
- package/lib/constants/node-types.js +0 -5
- package/lib/constants/obsolete-tags.js +1 -1
- package/lib/constants/rule-category.js +0 -5
- package/lib/constants/void-elements.js +1 -1
- package/lib/rules/element-newline.js +29 -9
- package/lib/rules/id-naming-convention.js +16 -9
- package/lib/rules/indent.js +19 -7
- package/lib/rules/index.js +14 -2
- package/lib/rules/no-abstract-roles.js +62 -0
- package/lib/rules/no-accesskey-attrs.js +45 -0
- package/lib/rules/no-aria-hidden-body.js +46 -0
- package/lib/rules/no-duplicate-attrs.js +54 -0
- package/lib/rules/no-duplicate-id.js +7 -0
- package/lib/rules/no-extra-spacing-attrs.js +27 -5
- package/lib/rules/no-inline-styles.js +7 -0
- package/lib/rules/no-multiple-empty-lines.js +90 -0
- package/lib/rules/no-multiple-h1.js +7 -0
- package/lib/rules/no-non-scalable-viewport.js +7 -0
- package/lib/rules/no-obsolete-tags.js +7 -0
- package/lib/rules/no-positive-tabindex.js +7 -0
- package/lib/rules/no-skip-heading-levels.js +7 -0
- package/lib/rules/no-target-blank.js +7 -0
- package/lib/rules/quotes.js +30 -2
- package/lib/rules/require-button-type.js +58 -0
- package/lib/rules/require-closing-tags.js +11 -4
- package/lib/rules/require-doctype.js +7 -0
- package/lib/rules/require-frame-title.js +7 -0
- package/lib/rules/require-img-alt.js +13 -0
- package/lib/rules/require-lang.js +10 -4
- package/lib/rules/require-li-container.js +13 -1
- package/lib/rules/require-meta-charset.js +12 -1
- package/lib/rules/require-meta-description.js +15 -4
- package/lib/rules/require-meta-viewport.js +12 -8
- package/lib/rules/require-title.js +9 -3
- package/lib/rules/utils/node-utils.js +27 -5
- package/lib/types.d.ts +104 -33
- package/package.json +8 -4
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
/**
|
|
3
|
-
* @typedef {import("../../types").
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
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
|
-
|
|
28
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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": "
|
|
48
|
+
"gitHead": "a3873ecefae3b9306a5e98985cf4ccdbde95299a"
|
|
45
49
|
}
|