Skip to content

Commit 5f11a3d

Browse files
authored
feat: Create type definitions for rules (#324)
* fix: make `RuleModule` language specific * patch for deprecated `RuleContext` methods * extend `MarkdownRuleVisitor` * fix `IMarkdownSourceCode` * export generic type `MarkdownRuleDefinition` * remove patch for deprecated `RuleContext` methods * update ESLint * remove `MarkdownRuleDefinition` export
1 parent 49b33bb commit 5f11a3d

13 files changed

+190
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"c8": "^10.1.2",
6767
"chai": "^5.1.1",
6868
"dedent": "^1.5.3",
69-
"eslint": "^9.15.0",
69+
"eslint": "^9.23.0",
7070
"eslint-config-eslint": "^11.0.0",
7171
"eslint-plugin-eslint-plugin": "^6.3.2",
7272
"globals": "^15.1.0",

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import rules from "./build/rules.js";
1919
/** @typedef {import("eslint").Linter.RulesRecord} RulesRecord*/
2020
/** @typedef {import("eslint").Linter.Config} Config*/
2121
/** @typedef {import("eslint").ESLint.Plugin} Plugin */
22-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
22+
/** @typedef {import("./types.ts").MarkdownRuleDefinition} RuleModule */
23+
/** @typedef {import("./types.ts").MarkdownRuleVisitor} MarkdownRuleVisitor */
2324
/** @typedef {import("@eslint/core").Language} Language */
2425

2526
//-----------------------------------------------------------------------------

src/language/markdown-source-code.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { findOffsets } from "../util.js";
3232
/** @typedef {import("@eslint/core").SourceRange} SourceRange */
3333
/** @typedef {import("@eslint/core").FileProblem} FileProblem */
3434
/** @typedef {import("@eslint/core").DirectiveType} DirectiveType */
35+
/** @typedef {import("../types.ts").IMarkdownSourceCode} IMarkdownSourceCode */
3536

3637
//-----------------------------------------------------------------------------
3738
// Helpers
@@ -135,6 +136,7 @@ function extractInlineConfigCommentsFromHTML(node) {
135136

136137
/**
137138
* Markdown Source Code Object
139+
* @implements {IMarkdownSourceCode}
138140
*/
139141
export class MarkdownSourceCode extends TextSourceCodeBase {
140142
/**

src/rules/fenced-code-language.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
// Type Definitions
88
//-----------------------------------------------------------------------------
99

10-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
10+
/**
11+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: [{ required?: string[]; }]; }>}
12+
* FencedCodeLanguageRuleDefinition
13+
*/
1114

1215
//-----------------------------------------------------------------------------
1316
// Rule Definition
1417
//-----------------------------------------------------------------------------
1518

16-
/** @type {RuleModule} */
19+
/** @type {FencedCodeLanguageRuleDefinition} */
1720
export default {
1821
meta: {
1922
type: "problem",

src/rules/heading-increment.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
// Type Definitions
88
//-----------------------------------------------------------------------------
99

10-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
10+
/**
11+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
12+
* HeadingIncrementRuleDefinition
13+
*/
1114

1215
//-----------------------------------------------------------------------------
1316
// Rule Definition
1417
//-----------------------------------------------------------------------------
1518

16-
/** @type {RuleModule} */
19+
/** @type {HeadingIncrementRuleDefinition} */
1720
export default {
1821
meta: {
1922
type: "problem",
@@ -40,7 +43,7 @@ export default {
4043
messageId: "skippedHeading",
4144
data: {
4245
fromLevel: lastHeadingDepth.toString(),
43-
toLevel: node.depth,
46+
toLevel: node.depth.toString(),
4447
},
4548
});
4649
}

src/rules/no-duplicate-headings.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
// Type Definitions
88
//-----------------------------------------------------------------------------
99

10-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
10+
/**
11+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
12+
* NoDuplicateHeadingsRuleDefinition
13+
*/
1114

1215
//-----------------------------------------------------------------------------
1316
// Rule Definition
1417
//-----------------------------------------------------------------------------
1518

16-
/** @type {RuleModule} */
19+
/** @type {NoDuplicateHeadingsRuleDefinition} */
1720
export default {
1821
meta: {
1922
type: "problem",

src/rules/no-empty-links.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
// Type Definitions
77
//-----------------------------------------------------------------------------
88

9-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
9+
/**
10+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
11+
* NoEmptyLinksRuleDefinition
12+
*/
1013

1114
//-----------------------------------------------------------------------------
1215
// Rule Definition
1316
//-----------------------------------------------------------------------------
1417

15-
/** @type {RuleModule} */
18+
/** @type {NoEmptyLinksRuleDefinition} */
1619
export default {
1720
meta: {
1821
type: "problem",

src/rules/no-html.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { findOffsets } from "../util.js";
1313
// Type Definitions
1414
//-----------------------------------------------------------------------------
1515

16-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
16+
/**
17+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: [{ allowed?: string[]; }]; }>}
18+
* NoHtmlRuleDefinition
19+
*/
1720

1821
//-----------------------------------------------------------------------------
1922
// Helpers
@@ -25,7 +28,7 @@ const htmlTagPattern = /<([a-z0-9]+(?:-[a-z0-9]+)*)/giu;
2528
// Rule Definition
2629
//-----------------------------------------------------------------------------
2730

28-
/** @type {RuleModule} */
31+
/** @type {NoHtmlRuleDefinition} */
2932
export default {
3033
meta: {
3134
type: "problem",

src/rules/no-invalid-label-refs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { findOffsets, illegalShorthandTailPattern } from "../util.js";
1515

1616
/** @typedef {import("unist").Position} Position */
1717
/** @typedef {import("mdast").Text} TextNode */
18-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
18+
/**
19+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
20+
* NoInvalidLabelRuleDefinition
21+
*/
1922

2023
//-----------------------------------------------------------------------------
2124
// Helpers
@@ -120,7 +123,7 @@ function findInvalidLabelReferences(node, docText) {
120123
// Rule Definition
121124
//-----------------------------------------------------------------------------
122125

123-
/** @type {RuleModule} */
126+
/** @type {NoInvalidLabelRuleDefinition} */
124127
export default {
125128
meta: {
126129
type: "problem",

src/rules/no-missing-label-refs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { findOffsets, illegalShorthandTailPattern } from "../util.js";
1515

1616
/** @typedef {import("unist").Position} Position */
1717
/** @typedef {import("mdast").Text} TextNode */
18-
/** @typedef {import("eslint").Rule.RuleModule} RuleModule */
18+
/**
19+
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
20+
* NoMissingLabelRuleDefinition
21+
*/
1922

2023
//-----------------------------------------------------------------------------
2124
// Helpers
@@ -101,7 +104,7 @@ function findMissingReferences(node, nodeText) {
101104
// Rule Definition
102105
//-----------------------------------------------------------------------------
103106

104-
/** @type {RuleModule} */
107+
/** @type {NoMissingLabelRuleDefinition} */
105108
export default {
106109
meta: {
107110
type: "problem",

0 commit comments

Comments
 (0)