Skip to content

Commit 3882e0c

Browse files
authored
refactor: refactor jsdoc to use @import (#379)
* refactor: update type imports * refactor type imports * refactor import types * fix * refactor import * refactor * refactor * refactor * Update attrs-newline.js
1 parent 30e536d commit 3882e0c

File tree

81 files changed

+253
-396
lines changed

Some content is hidden

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

81 files changed

+253
-396
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
],
77
"editor.codeActionsOnSave": {
88
"source.fixAll.eslint": "never"
9-
}
9+
},
10+
"typescript.tsdk": "node_modules/typescript/lib"
1011
}

packages/eslint-plugin/lib/languages/html-language.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { visitorKeys, parseForESLint } = require("@html-eslint/parser");
2-
const { HTMLSourceCode } = require("./html-source-code");
3-
41
/**
52
* @import { Language, ParseResult, File, FileError, OkParseResult } from "@eslint/core";
63
* @import { ParserOptions } from "@html-eslint/parser";
74
* @import { AST } from "eslint";
85
*/
96

7+
const { visitorKeys, parseForESLint } = require("@html-eslint/parser");
8+
const { HTMLSourceCode } = require("./html-source-code");
9+
1010
/**
1111
* @implements {Language<{ LangOptions: ParserOptions; Code: HTMLSourceCode; RootNode: AST.Program; Node: {}}>}
1212
*/

packages/eslint-plugin/lib/languages/html-source-code.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/**
2-
* @typedef {import("eslint").AST.Program} Program
3-
* @typedef {import("@eslint/plugin-kit").SourceLocation} SourceLocation
4-
* @typedef {import("@eslint/plugin-kit").DirectiveType} DirectiveType
5-
* @typedef {import("@eslint/core").TraversalStep} TraversalStep
6-
* @typedef {import("@html-eslint/types").CommentContent} CommentContent
7-
* @typedef {import("@html-eslint/types").AnyHTMLNode} AnyHTMLNode
8-
* @typedef {import("@eslint/core").Position} Position
9-
* @typedef {import("../types").BaseNode} BaseNode
2+
* @import {AST} from 'eslint';
3+
* @import {SourceLocation, DirectiveType} from '@eslint/plugin-kit';
4+
* @import {TraversalStep, Position} from '@eslint/core';
5+
* @import {CommentContent, AnyHTMLNode} from '@html-eslint/types';
6+
* @import {BaseNode} from '../types';
107
*/
8+
119
const {
1210
TextSourceCodeBase,
1311
ConfigCommentParser,
@@ -29,7 +27,7 @@ const commentParser = new ConfigCommentParser();
2927

3028
class HTMLSourceCode extends TextSourceCodeBase {
3129
/**
32-
* @param {{ast: Program, text: string, comments: CommentContent[]}} config
30+
* @param {{ast: AST.Program, text: string, comments: CommentContent[]}} config
3331
*/
3432
constructor({ ast, text, comments }) {
3533
super({ ast, text });
@@ -219,8 +217,8 @@ class HTMLSourceCode extends TextSourceCodeBase {
219217

220218
/**
221219
*
222-
* @param {AnyHTMLNode | Program} node
223-
* @param {AnyHTMLNode | Program | null} parent
220+
* @param {AnyHTMLNode | AST.Program} node
221+
* @param {AnyHTMLNode | AST.Program | null} parent
224222
*/
225223
const visit = (node, parent) => {
226224
this.parentsMap.set(node, parent);

packages/eslint-plugin/lib/languages/html-traversal-step.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
2-
* @typedef {import("eslint").AST.Program} Program
3-
* @typedef {import('@html-eslint/types').AnyHTMLNode} AnyHTMLNode
2+
* @import {AST} from 'eslint';
3+
* @import {AnyHTMLNode} from '@html-eslint/types';
44
*/
5+
56
const { VisitNodeStep } = require("@eslint/plugin-kit");
67

78
const STEP_PHASE = {
@@ -18,7 +19,7 @@ const STEP_PHASE = {
1819
class HTMLTraversalStep extends VisitNodeStep {
1920
/**
2021
* @param {Object} options
21-
* @param {AnyHTMLNode | Program} options.target
22+
* @param {AnyHTMLNode | AST.Program} options.target
2223
* @param {1|2} options.phase
2324
* @param {Array<any>} options.args
2425
*/

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef { import("../types").RuleFixer } RuleFixer
2+
* @import { RuleFixer, RuleModule } from '../types';
33
*
44
* @typedef {Object} MessageId
55
* @property {"closeStyleWrong"} CLOSE_STYLE_WRONG
@@ -8,8 +8,6 @@
88
* @typedef {Object} Option
99
* @property {"sameline" | "newline"} [option.closeStyle]
1010
* @property {number} [options.ifAttrsMoreThan]
11-
*
12-
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
1311
*/
1412

1513
const { RULE_CATEGORY } = require("../constants");
@@ -25,7 +23,7 @@ const MESSAGE_ID = {
2523
};
2624

2725
/**
28-
* @type {RuleModule}
26+
* @type {RuleModule<[Option]>}
2927
*/
3028
module.exports = {
3129
meta: {

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
/**
2-
* @typedef { import("@html-eslint/types").Tag } Tag
3-
* @typedef { import("@html-eslint/types").Comment } Comment
4-
* @typedef { import("@html-eslint/types").Doctype } Doctype
5-
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
6-
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
7-
* @typedef { import("@html-eslint/types").Text } Text
8-
* @typedef { import("@html-eslint/types").AnyNode } AnyNode
9-
* @typedef { import("@html-eslint/types").OpenTagEnd } OpenTagEnd
10-
* @typedef { import("@html-eslint/types").CloseTag } CloseTag
11-
* @typedef { import("../types").Line } Line
2+
* @import { Text, AnyNode, OpenTagEnd, CloseTag } from '@html-eslint/types';
3+
* @import { Line, RuleModule } from '../types';
124
* @typedef { AnyNode | Line } AnyNodeOrLine
13-
*
145
* @typedef {Object} Option
156
* @property {string[]} [Option.skip]
167
* @property {string[]} [Option.inline]
17-
*
18-
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
198
*/
209

2110
const { RULE_CATEGORY } = require("../constants");
@@ -76,7 +65,7 @@ wbr
7665
};
7766

7867
/**
79-
* @type {RuleModule}
68+
* @type {RuleModule<[Option]>}
8069
*/
8170
module.exports = {
8271
meta: {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
/**
2-
* @typedef { import("@html-eslint/types").Tag } Tag
3-
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
4-
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
2+
* @import {Tag, ScriptTag, StyleTag} from "@html-eslint/types";
3+
* @import {RuleModule} from "../types";
54
*
65
* @typedef {"camelCase" | "snake_case" | "PascalCase" | "kebab-case" | "regex"} Option1
76
* @typedef {Object} Option2
87
* @property {string} pattern
98
* @property {string} [flags]
10-
*
11-
* @typedef { import("../types").RuleModule<[Option1, Option2]> } RuleModule
129
*/
1310

1411
const { RULE_CATEGORY } = require("../constants");
@@ -42,7 +39,7 @@ const CONVENTION_CHECKERS = {
4239
};
4340

4441
/**
45-
* @type {RuleModule}
42+
* @type {RuleModule<[Option1, Option2]>}
4643
*/
4744
module.exports = {
4845
meta: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import("@html-eslint/types").AnyNode} AnyNode
2+
* @import {AnyNode} from "@html-eslint/types";
33
* @typedef {{ [key in AnyNode['type']]?: number}} IncLevelOptions
44
* @typedef {(node: AnyNode) => number} GetIncreasingLevel
55
*/

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
/**
2-
* @typedef { import("@html-eslint/types").AnyNode } AnyNode
3-
* @typedef { import("../../types").Line } Line
4-
* @typedef { import("@html-eslint/types").Tag } Tag
5-
* @typedef { import("../../types").RuleListener } RuleListener
6-
* @typedef { import("../../types").Context<any[]> } Context
7-
* @typedef { import("@html-eslint/types").TemplateText } TemplateText
8-
* @typedef { import("eslint").AST.Token } Token
9-
* @typedef { import("eslint").SourceCode } SourceCode
10-
* @typedef { import("eslint").AST.Range } Range
11-
* @typedef { import("eslint").AST.SourceLocation } SourceLocation
12-
* @typedef { import("@html-eslint/types").TemplateLiteral } TemplateLiteral
13-
* @typedef { import("@html-eslint/types").OpenTemplate } OpenTemplate
14-
* @typedef { import("@html-eslint/types").CloseTemplate } CloseTemplate
15-
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
16-
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
2+
* @import {AnyNode, Tag, TemplateText, TemplateLiteral, OpenTemplate, CloseTemplate, ScriptTag, StyleTag} from "@html-eslint/types";
3+
* @import {Line, RuleListener, Context, RuleModule} from "../../types";
4+
* @import {AST} from "eslint";
175
*
186
* @typedef {AnyNode | Line} AnyNodeOrLine
197
* @typedef {Object} IndentType
@@ -30,8 +18,6 @@
3018
* @typedef {Object} Option2
3119
* @property {number} [Option2.Attribute]
3220
* @property {Record<string, number>} [Option2.tagChildrenIndent]
33-
*
34-
* @typedef { import("../../types").RuleModule<[Option1, Option2]> } RuleModule
3521
*/
3622

3723
const { parse } = require("@html-eslint/template-parser");
@@ -66,7 +52,7 @@ const INDENT_TYPES = {
6652
const IGNORING_NODES = ["pre", "xmp"];
6753

6854
/**
69-
* @type {RuleModule}
55+
* @type {RuleModule<[Option1, Option2]>}
7056
*/
7157
module.exports = {
7258
meta: {
@@ -415,7 +401,7 @@ module.exports = {
415401
/**
416402
* @param {AnyNodeOrLine | TemplateText | OpenTemplate | CloseTemplate} node
417403
* @param {string} actualIndent
418-
* @return {{range: Range; loc: SourceLocation}}
404+
* @return {{range: AST.Range; loc: AST.SourceLocation}}
419405
*/
420406
function getIndentNodeToReport(node, actualIndent) {
421407
let rangeStart = node.range[0];
@@ -448,7 +434,7 @@ function countLeftPadding(str) {
448434
}
449435

450436
/**
451-
* @param {Context} context
437+
* @param {Context<any[]>} context
452438
* @return {IndentOptionInfo}
453439
*/
454440
function getIndentOptionInfo(context) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
2-
* @typedef { import("@html-eslint/types").Tag } Tag
3-
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
4-
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
5-
* @typedef { import("../types").RuleModule<[]> } RuleModule
2+
* @import {Tag, StyleTag, ScriptTag} from "@html-eslint/types";
3+
* @import {RuleModule} from "../types";
64
*/
75

86
const { RULE_CATEGORY } = require("../constants");
@@ -16,7 +14,7 @@ const MESSAGE_IDS = {
1614
};
1715

1816
/**
19-
* @type {RuleModule}
17+
* @type {RuleModule<[]>}
2018
*/
2119
module.exports = {
2220
meta: {

0 commit comments

Comments
 (0)