eslint-markdown 0.10.0 → 0.11.1

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 (120) hide show
  1. package/README.md +1 -0
  2. package/build/configs/all.d.ts +5 -4
  3. package/build/configs/all.js +53 -0
  4. package/build/configs/base.d.ts +4 -4
  5. package/build/configs/base.js +27 -0
  6. package/{src → build}/configs/index.js +0 -2
  7. package/build/configs/recommended.d.ts +4 -4
  8. package/build/configs/recommended.js +36 -0
  9. package/build/configs/stylistic.d.ts +5 -4
  10. package/build/configs/stylistic.js +38 -0
  11. package/build/core/ast/escape-string-regexp.d.ts +2 -2
  12. package/{src → build}/core/ast/escape-string-regexp.js +6 -9
  13. package/build/core/ast/html.d.ts +6 -6
  14. package/build/core/ast/html.js +31 -0
  15. package/{src → build}/core/ast/index.js +0 -1
  16. package/build/core/ast/is-blank-line.d.ts +7 -3
  17. package/{src → build}/core/ast/is-blank-line.js +16 -24
  18. package/build/core/ast/skip-ranges.d.ts +6 -7
  19. package/build/core/ast/skip-ranges.js +33 -0
  20. package/build/core/constants.d.ts +6 -5
  21. package/{src → build}/core/constants.js +1 -8
  22. package/build/core/types.js +4 -0
  23. package/build/index.d.ts +1215 -16
  24. package/build/index.js +31 -0
  25. package/build/rules/allow-heading.d.ts +86 -114
  26. package/build/rules/allow-heading.js +162 -0
  27. package/build/rules/allow-image-url.d.ts +51 -45
  28. package/build/rules/allow-image-url.js +141 -0
  29. package/build/rules/allow-link-url.d.ts +51 -45
  30. package/build/rules/allow-link-url.js +141 -0
  31. package/build/rules/code-lang-shorthand.d.ts +39 -36
  32. package/build/rules/code-lang-shorthand.js +183 -0
  33. package/build/rules/consistent-code-style.d.ts +53 -53
  34. package/build/rules/consistent-code-style.js +198 -0
  35. package/build/rules/consistent-delete-style.d.ts +30 -27
  36. package/build/rules/consistent-delete-style.js +84 -0
  37. package/build/rules/consistent-emphasis-style.d.ts +30 -27
  38. package/build/rules/consistent-emphasis-style.js +82 -0
  39. package/build/rules/consistent-inline-code-style.d.ts +19 -16
  40. package/build/rules/consistent-inline-code-style.js +98 -0
  41. package/build/rules/consistent-strong-style.d.ts +30 -27
  42. package/build/rules/consistent-strong-style.js +82 -0
  43. package/build/rules/consistent-thematic-break-style.d.ts +30 -27
  44. package/build/rules/consistent-thematic-break-style.js +69 -0
  45. package/build/rules/consistent-unordered-list-style.d.ts +32 -29
  46. package/build/rules/consistent-unordered-list-style.js +110 -0
  47. package/build/rules/en-capitalization.d.ts +35 -33
  48. package/build/rules/en-capitalization.js +117 -0
  49. package/build/rules/endline-punctuation.js +2 -0
  50. package/{src → build}/rules/glossary.js +1 -0
  51. package/build/rules/index.d.ts +1197 -23
  52. package/{src → build}/rules/index.js +28 -29
  53. package/build/rules/no-bold-paragraph.d.ts +17 -15
  54. package/build/rules/no-bold-paragraph.js +48 -0
  55. package/build/rules/no-consecutive-blank-line.d.ts +62 -0
  56. package/build/rules/no-consecutive-blank-line.js +162 -0
  57. package/build/rules/no-control-character.d.ts +52 -48
  58. package/build/rules/no-control-character.js +123 -0
  59. package/build/rules/no-curly-quote.d.ts +44 -39
  60. package/build/rules/no-curly-quote.js +101 -0
  61. package/build/rules/no-double-punctuation.d.ts +40 -36
  62. package/build/rules/no-double-punctuation.js +125 -0
  63. package/build/rules/no-double-space.d.ts +32 -28
  64. package/build/rules/no-double-space.js +77 -0
  65. package/build/rules/no-emoji.d.ts +32 -29
  66. package/build/rules/no-emoji.js +75 -0
  67. package/build/rules/no-git-conflict-marker.d.ts +37 -36
  68. package/build/rules/no-git-conflict-marker.js +95 -0
  69. package/build/rules/no-irregular-dash.d.ts +49 -46
  70. package/build/rules/no-irregular-dash.js +108 -0
  71. package/build/rules/no-irregular-whitespace.d.ts +49 -46
  72. package/build/rules/no-irregular-whitespace.js +108 -0
  73. package/build/rules/no-tab.d.ts +48 -45
  74. package/build/rules/no-tab.js +104 -0
  75. package/build/rules/no-unmatched-pair.js +2 -0
  76. package/build/rules/no-url-trailing-slash.d.ts +18 -18
  77. package/build/rules/no-url-trailing-slash.js +131 -0
  78. package/build/rules/require-heading-id.d.ts +49 -46
  79. package/build/rules/require-heading-id.js +187 -0
  80. package/build/rules/require-image-title.d.ts +33 -30
  81. package/build/rules/require-image-title.js +99 -0
  82. package/build/rules/require-link-title.d.ts +33 -30
  83. package/build/rules/require-link-title.js +102 -0
  84. package/package.json +8 -11
  85. package/src/configs/all.js +0 -66
  86. package/src/configs/base.js +0 -41
  87. package/src/configs/recommended.js +0 -50
  88. package/src/configs/stylistic.js +0 -51
  89. package/src/core/ast/html.js +0 -53
  90. package/src/core/ast/skip-ranges.js +0 -51
  91. package/src/core/types.ts +0 -35
  92. package/src/index.js +0 -54
  93. package/src/rules/allow-heading.js +0 -193
  94. package/src/rules/allow-image-url.js +0 -191
  95. package/src/rules/allow-link-url.js +0 -191
  96. package/src/rules/code-lang-shorthand.js +0 -225
  97. package/src/rules/consistent-code-style.js +0 -260
  98. package/src/rules/consistent-delete-style.js +0 -118
  99. package/src/rules/consistent-emphasis-style.js +0 -118
  100. package/src/rules/consistent-inline-code-style.js +0 -152
  101. package/src/rules/consistent-strong-style.js +0 -115
  102. package/src/rules/consistent-thematic-break-style.js +0 -103
  103. package/src/rules/consistent-unordered-list-style.js +0 -156
  104. package/src/rules/en-capitalization.js +0 -162
  105. package/src/rules/endline-punctuation.js +0 -1
  106. package/src/rules/no-bold-paragraph.js +0 -72
  107. package/src/rules/no-control-character.js +0 -162
  108. package/src/rules/no-curly-quote.js +0 -144
  109. package/src/rules/no-double-punctuation.js +0 -171
  110. package/src/rules/no-double-space.js +0 -111
  111. package/src/rules/no-emoji.js +0 -104
  112. package/src/rules/no-git-conflict-marker.js +0 -133
  113. package/src/rules/no-irregular-dash.js +0 -143
  114. package/src/rules/no-irregular-whitespace.js +0 -144
  115. package/src/rules/no-tab.js +0 -142
  116. package/src/rules/no-unmatched-pair.js +0 -1
  117. package/src/rules/no-url-trailing-slash.js +0 -169
  118. package/src/rules/require-heading-id.js +0 -239
  119. package/src/rules/require-image-title.js +0 -145
  120. package/src/rules/require-link-title.js +0 -150
package/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  [![npm package eslint-markdown latest version](https://img.shields.io/npm/v/eslint-markdown?label=eslint-markdown@latest&color=6358d4&labelColor=333333&logo=npm)](https://www.npmjs.com/package/eslint-markdown)
9
9
  [![npm package eslint-markdown next version](https://img.shields.io/npm/v/eslint-markdown/next?label=eslint-markdown@next&color=6358d4&labelColor=333333&logo=npm)](https://www.npmjs.com/package/eslint-markdown)
10
+ [![npm package eslint-markdown downloads per month](https://img.shields.io/npm/dm/eslint-markdown?label=downloads&color=6358d4&labelColor=333333&logo=npm)](https://www.npmjs.com/package/eslint-markdown)
10
11
 
11
12
  > [!IMPORTANT]
12
13
  >
@@ -1,7 +1,9 @@
1
1
  /**
2
- * @import { ESLint, Linter } from "eslint";
2
+ * @fileoverview `all` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
3
4
  */
4
- /** @param {ESLint.Plugin} plugin */
5
+ import markdown from '@eslint/markdown';
6
+ import type { ESLint } from 'eslint';
5
7
  export default function all(plugin: ESLint.Plugin): {
6
8
  readonly name: "md/all";
7
9
  readonly files: ["**/*.md"];
@@ -24,6 +26,7 @@ export default function all(plugin: ESLint.Plugin): {
24
26
  readonly 'md/consistent-strong-style': "error";
25
27
  readonly 'md/consistent-thematic-break-style': "error";
26
28
  readonly 'md/consistent-unordered-list-style': "error";
29
+ readonly 'md/no-consecutive-blank-line': "error";
27
30
  readonly 'md/no-control-character': "error";
28
31
  readonly 'md/no-curly-quote': "error";
29
32
  readonly 'md/no-double-punctuation': "error";
@@ -39,5 +42,3 @@ export default function all(plugin: ESLint.Plugin): {
39
42
  readonly 'md/require-link-title': "error";
40
43
  };
41
44
  };
42
- import type { ESLint } from "eslint";
43
- import markdown from '@eslint/markdown';
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @fileoverview `all` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
+ */
5
+ // --------------------------------------------------------------------------------
6
+ // Import
7
+ // --------------------------------------------------------------------------------
8
+ import markdown from '@eslint/markdown';
9
+ // --------------------------------------------------------------------------------
10
+ // Export
11
+ // --------------------------------------------------------------------------------
12
+ export default function all(plugin) {
13
+ return {
14
+ name: 'md/all',
15
+ files: ['**/*.md'],
16
+ plugins: {
17
+ markdown,
18
+ get md() {
19
+ return plugin;
20
+ },
21
+ },
22
+ languageOptions: {
23
+ frontmatter: 'yaml',
24
+ },
25
+ language: 'markdown/gfm',
26
+ rules: {
27
+ 'md/allow-image-url': 'error',
28
+ 'md/allow-link-url': 'error',
29
+ 'md/code-lang-shorthand': 'error',
30
+ 'md/consistent-code-style': 'error',
31
+ 'md/consistent-delete-style': 'error',
32
+ 'md/consistent-emphasis-style': 'error',
33
+ 'md/consistent-inline-code-style': 'error',
34
+ 'md/consistent-strong-style': 'error',
35
+ 'md/consistent-thematic-break-style': 'error',
36
+ 'md/consistent-unordered-list-style': 'error',
37
+ 'md/no-consecutive-blank-line': 'error',
38
+ 'md/no-control-character': 'error',
39
+ 'md/no-curly-quote': 'error',
40
+ 'md/no-double-punctuation': 'error',
41
+ 'md/no-double-space': 'error',
42
+ 'md/no-emoji': 'error',
43
+ 'md/no-git-conflict-marker': 'error',
44
+ 'md/no-irregular-dash': 'error',
45
+ 'md/no-irregular-whitespace': 'error',
46
+ 'md/no-tab': 'error',
47
+ 'md/no-url-trailing-slash': 'error',
48
+ 'md/require-heading-id': 'error',
49
+ 'md/require-image-title': 'error',
50
+ 'md/require-link-title': 'error',
51
+ },
52
+ };
53
+ }
@@ -1,7 +1,9 @@
1
1
  /**
2
- * @import { ESLint, Linter } from "eslint";
2
+ * @fileoverview `base` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
3
4
  */
4
- /** @param {ESLint.Plugin} plugin */
5
+ import markdown from '@eslint/markdown';
6
+ import type { ESLint } from 'eslint';
5
7
  export default function base(plugin: ESLint.Plugin): {
6
8
  readonly name: "md/base";
7
9
  readonly files: ["**/*.md"];
@@ -14,5 +16,3 @@ export default function base(plugin: ESLint.Plugin): {
14
16
  };
15
17
  readonly language: "markdown/gfm";
16
18
  };
17
- import type { ESLint } from "eslint";
18
- import markdown from '@eslint/markdown';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview `base` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
+ */
5
+ // --------------------------------------------------------------------------------
6
+ // Import
7
+ // --------------------------------------------------------------------------------
8
+ import markdown from '@eslint/markdown';
9
+ // --------------------------------------------------------------------------------
10
+ // Export
11
+ // --------------------------------------------------------------------------------
12
+ export default function base(plugin) {
13
+ return {
14
+ name: 'md/base',
15
+ files: ['**/*.md'],
16
+ plugins: {
17
+ markdown,
18
+ get md() {
19
+ return plugin;
20
+ },
21
+ },
22
+ languageOptions: {
23
+ frontmatter: 'yaml',
24
+ },
25
+ language: 'markdown/gfm',
26
+ };
27
+ }
@@ -1,8 +1,6 @@
1
1
  /* eslint sort-imports: 'error', sort-keys: 'error' */
2
-
3
2
  import all from './all.js';
4
3
  import base from './base.js';
5
4
  import recommended from './recommended.js';
6
5
  import stylistic from './stylistic.js';
7
-
8
6
  export { all, base, recommended, stylistic };
@@ -1,7 +1,9 @@
1
1
  /**
2
- * @import { ESLint, Linter } from "eslint";
2
+ * @fileoverview `recommended` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
3
4
  */
4
- /** @param {ESLint.Plugin} plugin */
5
+ import markdown from '@eslint/markdown';
6
+ import type { ESLint } from 'eslint';
5
7
  export default function recommended(plugin: ESLint.Plugin): {
6
8
  readonly name: "md/recommended";
7
9
  readonly files: ["**/*.md"];
@@ -23,5 +25,3 @@ export default function recommended(plugin: ESLint.Plugin): {
23
25
  readonly 'md/no-irregular-whitespace': "error";
24
26
  };
25
27
  };
26
- import type { ESLint } from "eslint";
27
- import markdown from '@eslint/markdown';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @fileoverview `recommended` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
+ */
5
+ // --------------------------------------------------------------------------------
6
+ // Import
7
+ // --------------------------------------------------------------------------------
8
+ import markdown from '@eslint/markdown';
9
+ // --------------------------------------------------------------------------------
10
+ // Export
11
+ // --------------------------------------------------------------------------------
12
+ export default function recommended(plugin) {
13
+ return {
14
+ name: 'md/recommended',
15
+ files: ['**/*.md'],
16
+ plugins: {
17
+ markdown,
18
+ get md() {
19
+ return plugin;
20
+ },
21
+ },
22
+ languageOptions: {
23
+ frontmatter: 'yaml',
24
+ },
25
+ language: 'markdown/gfm',
26
+ rules: {
27
+ 'md/code-lang-shorthand': 'error',
28
+ 'md/no-control-character': 'error',
29
+ 'md/no-curly-quote': 'error',
30
+ 'md/no-double-space': 'error',
31
+ 'md/no-git-conflict-marker': 'error',
32
+ 'md/no-irregular-dash': 'error',
33
+ 'md/no-irregular-whitespace': 'error',
34
+ },
35
+ };
36
+ }
@@ -1,7 +1,9 @@
1
1
  /**
2
- * @import { ESLint, Linter } from "eslint";
2
+ * @fileoverview `stylistic` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
3
4
  */
4
- /** @param {ESLint.Plugin} plugin */
5
+ import markdown from '@eslint/markdown';
6
+ import type { ESLint } from 'eslint';
5
7
  export default function stylistic(plugin: ESLint.Plugin): {
6
8
  readonly name: "md/stylistic";
7
9
  readonly files: ["**/*.md"];
@@ -21,8 +23,7 @@ export default function stylistic(plugin: ESLint.Plugin): {
21
23
  readonly 'md/consistent-strong-style': "error";
22
24
  readonly 'md/consistent-thematic-break-style': "error";
23
25
  readonly 'md/consistent-unordered-list-style': "error";
26
+ readonly 'md/no-consecutive-blank-line': "error";
24
27
  readonly 'md/no-tab': "error";
25
28
  };
26
29
  };
27
- import type { ESLint } from "eslint";
28
- import markdown from '@eslint/markdown';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @fileoverview `stylistic` configuration.
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
+ */
5
+ // --------------------------------------------------------------------------------
6
+ // Import
7
+ // --------------------------------------------------------------------------------
8
+ import markdown from '@eslint/markdown';
9
+ // --------------------------------------------------------------------------------
10
+ // Export
11
+ // --------------------------------------------------------------------------------
12
+ export default function stylistic(plugin) {
13
+ return {
14
+ name: 'md/stylistic',
15
+ files: ['**/*.md'],
16
+ plugins: {
17
+ markdown,
18
+ get md() {
19
+ return plugin;
20
+ },
21
+ },
22
+ languageOptions: {
23
+ frontmatter: 'yaml',
24
+ },
25
+ language: 'markdown/gfm',
26
+ rules: {
27
+ 'md/consistent-code-style': 'error',
28
+ 'md/consistent-delete-style': 'error',
29
+ 'md/consistent-emphasis-style': 'error',
30
+ 'md/consistent-inline-code-style': 'error',
31
+ 'md/consistent-strong-style': 'error',
32
+ 'md/consistent-thematic-break-style': 'error',
33
+ 'md/consistent-unordered-list-style': 'error',
34
+ 'md/no-consecutive-blank-line': 'error',
35
+ 'md/no-tab': 'error',
36
+ },
37
+ };
38
+ }
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
9
9
  *
10
- * @param {string} string A string to escape.
11
- * @returns {string} An escaped string.
10
+ * @param string A string to escape.
11
+ * @returns An escaped string.
12
12
  * @example
13
13
  * ```js
14
14
  * import escapeStringRegexp from 'path/to/escape-string-regexp.js';
@@ -2,7 +2,6 @@
2
2
  * @fileoverview Utility to escape `RegExp` special characters.
3
3
  * @see https://github.com/sindresorhus/escape-string-regexp/tree/v5.0.0
4
4
  */
5
-
6
5
  /*
7
6
  * MIT License
8
7
  *
@@ -26,18 +25,16 @@
26
25
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
26
  * SOFTWARE.
28
27
  */
29
-
30
28
  // --------------------------------------------------------------------------------
31
29
  // Export
32
30
  // --------------------------------------------------------------------------------
33
-
34
31
  /**
35
32
  * Escape `RegExp` special characters.
36
33
  *
37
34
  * You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
38
35
  *
39
- * @param {string} string A string to escape.
40
- * @returns {string} An escaped string.
36
+ * @param string A string to escape.
37
+ * @returns An escaped string.
41
38
  * @example
42
39
  * ```js
43
40
  * import escapeStringRegexp from 'path/to/escape-string-regexp.js';
@@ -49,8 +46,8 @@
49
46
  * ```
50
47
  */
51
48
  export default function escapeStringRegexp(string) {
52
- // Escape characters with special meaning either inside or outside character sets.
53
- // Use a simple backslash escape when it's always valid, and a `\xnn` escape
54
- // when the simpler form would be disallowed by Unicode patterns' stricter grammar.
55
- return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
49
+ // Escape characters with special meaning either inside or outside character sets.
50
+ // Use a simple backslash escape when it's always valid, and a `\xnn` escape
51
+ // when the simpler form would be disallowed by Unicode patterns' stricter grammar.
52
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
56
53
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @import { DefaultTreeAdapterTypes } from 'parse5';
2
+ * @fileoverview HTML AST utilities.
3
3
  */
4
+ import type { DefaultTreeAdapterTypes } from 'parse5';
4
5
  /**
5
6
  * Mimics the behavior of `getElementsByTagName` in the DOM API.
6
- * @param {string} html The HTML string to parse.
7
- * @param {string} tagName The tag name to search for (case-insensitive).
8
- * @returns {Array<DefaultTreeAdapterTypes.Element | DefaultTreeAdapterTypes.Template>}
7
+ * @param html The HTML string to parse.
8
+ * @param tagName The tag name to search for (case-insensitive).
9
+ * @returns Matched elements.
9
10
  */
10
- export default function getElementsByTagName(html: string, tagName: string): Array<DefaultTreeAdapterTypes.Element | DefaultTreeAdapterTypes.Template>;
11
- import type { DefaultTreeAdapterTypes } from 'parse5';
11
+ export default function getElementsByTagName(html: string, tagName: string): (DefaultTreeAdapterTypes.Element | DefaultTreeAdapterTypes.Template)[];
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @fileoverview HTML AST utilities.
3
+ */
4
+ // --------------------------------------------------------------------------------
5
+ // Import
6
+ // --------------------------------------------------------------------------------
7
+ import { parseFragment } from 'parse5';
8
+ // --------------------------------------------------------------------------------
9
+ // Export
10
+ // --------------------------------------------------------------------------------
11
+ /**
12
+ * Mimics the behavior of `getElementsByTagName` in the DOM API.
13
+ * @param html The HTML string to parse.
14
+ * @param tagName The tag name to search for (case-insensitive).
15
+ * @returns Matched elements.
16
+ */
17
+ export default function getElementsByTagName(html, tagName) {
18
+ const ast = parseFragment(html, { sourceCodeLocationInfo: true });
19
+ const normalizedTagName = tagName.toLowerCase();
20
+ const nodes = [];
21
+ function visit(node) {
22
+ if ('tagName' in node && node.tagName === normalizedTagName) {
23
+ nodes.push(node);
24
+ }
25
+ if ('childNodes' in node) {
26
+ node.childNodes.forEach(visit);
27
+ }
28
+ }
29
+ visit(ast);
30
+ return nodes;
31
+ }
@@ -2,5 +2,4 @@ import escapeStringRegexp from './escape-string-regexp.js';
2
2
  import getElementsByTagName from './html.js';
3
3
  import isBlankLine from './is-blank-line.js';
4
4
  import SkipRanges from './skip-ranges.js';
5
-
6
5
  export { escapeStringRegexp, getElementsByTagName, isBlankLine, SkipRanges };
@@ -1,8 +1,12 @@
1
+ /**
2
+ * @fileoverview Check if a line is blank.
3
+ * @see https://spec.commonmark.org/0.31.2/#blank-line
4
+ */
1
5
  /**
2
6
  * Check if a line is blank.
3
7
  * - NOTE: The `blockquoteDepth` parameter is zero-based: `0` means one blockquote marker, `1` means two, and so on.
4
- * @param {string} str Line string.
5
- * @param {number} [blockquoteDepth] The depth of blockquotes. Default is `-1`.
6
- * @returns {boolean} `true` if the line is blank. `false` otherwise.
8
+ * @param str Line string.
9
+ * @param blockquoteDepth The depth of blockquotes. Default is `-1`.
10
+ * @returns `true` if the line is blank. `false` otherwise.
7
11
  */
8
12
  export default function isBlankLine(str: string, blockquoteDepth?: number): boolean;
@@ -2,42 +2,34 @@
2
2
  * @fileoverview Check if a line is blank.
3
3
  * @see https://spec.commonmark.org/0.31.2/#blank-line
4
4
  */
5
-
6
5
  // --------------------------------------------------------------------------------
7
6
  // Helper
8
7
  // --------------------------------------------------------------------------------
9
-
10
8
  const whitespaceChars = new Set([' ', '\t']);
11
9
  const blockquoteChar = '>';
12
-
13
10
  // --------------------------------------------------------------------------------
14
11
  // Export
15
12
  // --------------------------------------------------------------------------------
16
-
17
13
  /**
18
14
  * Check if a line is blank.
19
15
  * - NOTE: The `blockquoteDepth` parameter is zero-based: `0` means one blockquote marker, `1` means two, and so on.
20
- * @param {string} str Line string.
21
- * @param {number} [blockquoteDepth] The depth of blockquotes. Default is `-1`.
22
- * @returns {boolean} `true` if the line is blank. `false` otherwise.
16
+ * @param str Line string.
17
+ * @param blockquoteDepth The depth of blockquotes. Default is `-1`.
18
+ * @returns `true` if the line is blank. `false` otherwise.
23
19
  */
24
20
  export default function isBlankLine(str, blockquoteDepth = -1) {
25
- // `.length` is cached for performance.
26
- const strLength = str.length;
27
- let remainingBlockquotes = blockquoteDepth + 1;
28
-
29
- for (let i = 0; i < strLength; i++) {
30
- const char = str[i];
31
-
32
- if (!whitespaceChars.has(char)) {
33
- if (remainingBlockquotes > 0 && char === blockquoteChar) {
34
- remainingBlockquotes--;
35
- continue;
36
- }
37
-
38
- return false;
21
+ // `.length` is cached for performance.
22
+ const strLength = str.length;
23
+ let remainingBlockquotes = blockquoteDepth + 1;
24
+ for (let i = 0; i < strLength; i++) {
25
+ const char = str[i];
26
+ if (!whitespaceChars.has(char)) {
27
+ if (remainingBlockquotes > 0 && char === blockquoteChar) {
28
+ remainingBlockquotes--;
29
+ continue;
30
+ }
31
+ return false;
32
+ }
39
33
  }
40
- }
41
-
42
- return true;
34
+ return true;
43
35
  }
@@ -1,23 +1,22 @@
1
1
  /**
2
2
  * @fileoverview Class to manage skip ranges.
3
3
  */
4
- /**
5
- * @import { SourceRange } from '@eslint/core';
6
- */
4
+ import type { AST } from 'eslint';
5
+ type SourceRange = AST.Range;
7
6
  /**
8
7
  * Class to manage skip ranges.
9
8
  */
10
9
  export default class SkipRanges {
10
+ #private;
11
11
  /**
12
12
  * Push a `range` to the set of skip ranges. (Method chaining supported.)
13
- * @param {SourceRange} range
13
+ * @param range Source range to skip.
14
14
  */
15
15
  push(range: SourceRange): this;
16
16
  /**
17
17
  * Check whether the `offset` is included in any skip ranges.
18
- * @param {number} offset
18
+ * @param offset Offset to check.
19
19
  */
20
20
  includes(offset: number): boolean;
21
- #private;
22
21
  }
23
- import type { SourceRange } from '@eslint/core';
22
+ export {};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fileoverview Class to manage skip ranges.
3
+ */
4
+ // --------------------------------------------------------------------------------
5
+ // Export
6
+ // --------------------------------------------------------------------------------
7
+ /**
8
+ * Class to manage skip ranges.
9
+ */
10
+ export default class SkipRanges {
11
+ // ------------------------------------------------------------------------------
12
+ // Private Property
13
+ // ------------------------------------------------------------------------------
14
+ #skipRanges = new Set();
15
+ // ------------------------------------------------------------------------------
16
+ // Public Method
17
+ // ------------------------------------------------------------------------------
18
+ /**
19
+ * Push a `range` to the set of skip ranges. (Method chaining supported.)
20
+ * @param range Source range to skip.
21
+ */
22
+ push(range) {
23
+ this.#skipRanges.add(range);
24
+ return this;
25
+ }
26
+ /**
27
+ * Check whether the `offset` is included in any skip ranges.
28
+ * @param offset Offset to check.
29
+ */
30
+ includes(offset) {
31
+ return [...this.#skipRanges].some(skipRange => skipRange[0] <= offset && offset < skipRange[1]);
32
+ }
33
+ }
@@ -1,5 +1,6 @@
1
- /** @type {'eslint-markdown'} */
2
- export const PKG_NAME: "eslint-markdown";
3
- /** @satisfies {string} */
4
- export const PKG_VERSION: string;
5
- export function URL_RULE_DOCS(ruleName?: string): string;
1
+ /**
2
+ * @fileoverview This file declares constants used throughout the `eslint-markdown` package.
3
+ */
4
+ export declare const PKG_NAME: "eslint-markdown";
5
+ export declare const PKG_VERSION: string;
6
+ export declare const URL_RULE_DOCS: (ruleName?: string) => string;
@@ -1,20 +1,13 @@
1
1
  /**
2
2
  * @fileoverview This file declares constants used throughout the `eslint-markdown` package.
3
3
  */
4
-
5
4
  // --------------------------------------------------------------------------------
6
5
  // Import
7
6
  // --------------------------------------------------------------------------------
8
-
9
7
  import pkg from '../../package.json' with { type: 'json' };
10
-
11
8
  // --------------------------------------------------------------------------------
12
9
  // Export
13
10
  // --------------------------------------------------------------------------------
14
-
15
- /** @type {'eslint-markdown'} */
16
- export const PKG_NAME = /** @type {'eslint-markdown'} */ (pkg.name);
17
- /** @satisfies {string} */
11
+ export const PKG_NAME = pkg.name;
18
12
  export const PKG_VERSION = pkg.version;
19
- /** Get the URL for the rule documentation based on the rule name. @param {string} [ruleName] */
20
13
  export const URL_RULE_DOCS = (ruleName = '') => `${pkg.homepage}/docs/rules/${ruleName}`;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @fileoverview Define common types.
3
+ */
4
+ export {};