Skip to content

Commit ff8fed5

Browse files
authored
fix: fix type errors (#298)
* fix: fix type errors * fix types * fix type errors
1 parent 1370e7f commit ff8fed5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+286
-194
lines changed

docs/rules/require-open-graph-protocol.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ module.exports = {
1616

1717
### Options
1818

19-
- `ogp` (default: ['og:title', 'og:type', 'og:url', 'og:image']): enforce to use specified open graph protocol meta tags
19+
You can specify an array of ogp names to enforce.
2020

21-
Examples of **incorrect** code for this rule with the default `{ "ogp": ['og:title', 'og:type', 'og:url', 'og:image'] }` options:
21+
Examples of **incorrect** code for this rule with the default `['og:title', 'og:type', 'og:url', 'og:image']` options:
2222

2323
```html,incorrect
2424
<html>

packages/eslint-plugin/lib/rules/attrs-newline.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/**
2-
* @typedef { import("eslint").Rule.RuleFixer } RuleFixer
3-
* @typedef { import("../types").RuleModule } RuleModule
2+
* @typedef { import("../types").RuleFixer } RuleFixer
43
*
5-
* @typedef {Object } MessageId
4+
* @typedef {Object} MessageId
65
* @property {"closeStyleWrong"} CLOSE_STYLE_WRONG
76
* @property {"newlineMissing"} NEWLINE_MISSING
87
* @property {"newlineUnexpected"} NEWLINE_UNEXPECTED
8+
*
9+
* @typedef {Object} Option
10+
* @property {"sameline" | "newline"} [option.closeStyle]
11+
* @property {number} [options.ifAttrsMoreThan]
12+
*
13+
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
914
*/
1015

1116
const { RULE_CATEGORY } = require("../constants");
@@ -58,9 +63,8 @@ module.exports = {
5863

5964
create(context) {
6065
const options = context.options[0] || {};
61-
const attrMin = isNaN(options.ifAttrsMoreThan)
62-
? 2
63-
: options.ifAttrsMoreThan;
66+
const attrMin =
67+
typeof options.ifAttrsMoreThan !== "number" ? 2 : options.ifAttrsMoreThan;
6468
const closeStyle = options.closeStyle || "newline";
6569

6670
return createVisitors(context, {
@@ -147,7 +151,7 @@ module.exports = {
147151
return context.report({
148152
node,
149153
data: {
150-
attrMin,
154+
attrMin: `${attrMin}`,
151155
},
152156
fix,
153157
messageId: MESSAGE_ID.NEWLINE_UNEXPECTED,

packages/eslint-plugin/lib/rules/element-newline.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").Tag } Tag
43
* @typedef { import("@html-eslint/types").Comment } Comment
54
* @typedef { import("@html-eslint/types").Doctype } Doctype
@@ -11,6 +10,12 @@
1110
* @typedef { import("@html-eslint/types").CloseTag } CloseTag
1211
* @typedef { import("../types").Line } Line
1312
* @typedef { AnyNode | Line } AnyNodeOrLine
13+
*
14+
* @typedef {Object} Option
15+
* @property {string[]} [Option.skip]
16+
* @property {string[]} [Option.inline]
17+
*
18+
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
1419
*/
1520

1621
const { RULE_CATEGORY } = require("../constants");

packages/eslint-plugin/lib/rules/id-naming-convention.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").Tag } Tag
43
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
54
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
5+
*
6+
* @typedef {"camelCase" | "snake_case" | "PascalCase" | "kebab-case" | "regex"} Option1
7+
* @typedef {Object} Option2
8+
* @property {string} pattern
9+
* @property {string} [flags]
10+
*
11+
* @typedef { import("../types").RuleModule<[Option1, Option2]> } RuleModule
612
*/
713

814
const { RULE_CATEGORY } = require("../constants");

packages/eslint-plugin/lib/rules/indent/indent.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
2-
* @typedef { import("../../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").AnyNode } AnyNode
43
* @typedef { import("../../types").Line } Line
54
* @typedef { import("@html-eslint/types").Tag } Tag
65
* @typedef { import("../../types").RuleListener } RuleListener
7-
* @typedef { import("../../types").Context } Context
6+
* @typedef { import("../../types").Context<any[]> } Context
87
* @typedef { import("@html-eslint/types").TemplateText } TemplateText
98
* @typedef { import("eslint").AST.Token } Token
109
* @typedef { import("eslint").SourceCode } SourceCode
@@ -24,6 +23,13 @@
2423
* @property {IndentType["TAB"] | IndentType["SPACE"]} indentType
2524
* @property {number} indentSize
2625
* @property {string} indentChar
26+
*
27+
* @typedef {"tab" | number} Option1
28+
* @typedef {Object} Option2
29+
* @property {number} [Option2.Attribute]
30+
* @property {Record<string, number>} [Option2.tagChildrenIndent]
31+
*
32+
* @typedef { import("../../types").RuleModule<[Option1, Option2]> } RuleModule
2733
*/
2834

2935
const { parse } = require("@html-eslint/template-parser");
@@ -147,9 +153,14 @@ module.exports = {
147153
if (isTag(node)) {
148154
return getTagIncreasingLevel(node);
149155
}
150-
return typeof indentLevelOptions[node.type] === "number"
151-
? indentLevelOptions[node.type]
152-
: 1;
156+
const type = node.type;
157+
if (type === NodeTypes.Attribute) {
158+
const optionIndent = indentLevelOptions[type];
159+
if (typeof optionIndent === "number") {
160+
return optionIndent;
161+
}
162+
}
163+
return 1;
153164
}
154165

155166
/**
@@ -252,11 +263,11 @@ module.exports = {
252263
if (actualIndent !== expectedIndent) {
253264
const targetNode = getIndentNodeToReport(node, actualIndent);
254265
context.report({
255-
node: targetNode,
266+
loc: targetNode.loc,
256267
messageId: MESSAGE_ID.WRONG_INDENT,
257268
data: getMessageData(actualIndent, indentLevel.value()),
258269
fix(fixer) {
259-
return fixer.replaceText(targetNode, expectedIndent);
270+
return fixer.replaceTextRange(targetNode.range, expectedIndent);
260271
},
261272
});
262273
}

packages/eslint-plugin/lib/rules/lowercase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").Tag } Tag
43
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
54
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
5+
* @typedef { import("../types").RuleModule<[]> } RuleModule
66
*/
77

88
const { NODE_TYPES } = require("@html-eslint/parser");

packages/eslint-plugin/lib/rules/max-element-depth.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").Tag } Tag
43
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
54
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
5+
*
6+
* @typedef {Object} Option
7+
* @property {number} [Option.max]
8+
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
69
*/
710

811
const { RULE_CATEGORY } = require("../constants");
@@ -71,7 +74,7 @@ module.exports = {
7174
node,
7275
messageId: MESSAGE_IDS.MAX_DEPTH_EXCEEDED,
7376
data: {
74-
needed: maxDepth,
77+
needed: `${maxDepth}`,
7578
found: String(depth),
7679
},
7780
});

packages/eslint-plugin/lib/rules/no-abstract-roles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").Tag } Tag
43
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
54
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
5+
* @typedef { import("../types").RuleModule<[]> } RuleModule
66
*/
77

88
const { RULE_CATEGORY } = require("../constants");

packages/eslint-plugin/lib/rules/no-accesskey-attrs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
32
* @typedef { import("@html-eslint/types").Tag } Tag
43
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
54
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
5+
* @typedef { import("../types").RuleModule<[]> } RuleModule
66
*/
77

88
const { RULE_CATEGORY } = require("../constants");

packages/eslint-plugin/lib/rules/no-aria-hidden-body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef { import("../types").RuleModule } RuleModule
2+
* @typedef { import("../types").RuleModule<[]> } RuleModule
33
*/
44

55
const { RULE_CATEGORY } = require("../constants");

0 commit comments

Comments
 (0)