Skip to content

Commit 061c343

Browse files
authored
fix: skip for sourceCode do not support getAllComments (#46)
1 parent 9cd4952 commit 061c343

6 files changed

Lines changed: 29 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@antfu/ni": "catalog:dev",
5454
"@antfu/utils": "catalog:dev",
5555
"@eslint/config-inspector": "catalog:dev",
56+
"@eslint/markdown": "catalog:dev",
5657
"@types/lodash.merge": "catalog:dev",
5758
"@types/node": "catalog:dev",
5859
"@types/semver": "catalog:dev",

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ catalogs:
1212
'@antfu/ni': ^28.0.0
1313
'@antfu/utils': ^9.3.0
1414
'@eslint/config-inspector': ^1.4.2
15+
'@eslint/markdown': ^7.5.1
1516
'@types/lodash.merge': ^4.6.9
1617
'@types/node': ^24.10.2
1718
'@types/semver': ^7.7.1

src/rule.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import eslintMarkdown from '@eslint/markdown'
2+
import { run } from 'eslint-vitest-rule-tester'
3+
import { builtinCommands } from './commands'
4+
import { createRuleWithCommands } from './rule'
5+
6+
// Do not throw error when `getAllComments` is not available (e.g. in markdown source code)
7+
run({
8+
name: 'command',
9+
rule: createRuleWithCommands(builtinCommands),
10+
configs: {
11+
plugins: {
12+
markdown: eslintMarkdown,
13+
},
14+
language: 'markdown/gfm',
15+
},
16+
valid: [
17+
'',
18+
],
19+
})

src/rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function createRuleWithCommands(commands: Command[]) {
2222
defaultOptions: [],
2323
create: (context) => {
2424
const sc = context.sourceCode
25-
const comments = sc.getAllComments()
25+
const comments = sc.getAllComments?.() ?? []
2626

2727
for (const comment of comments) {
2828
const commandRaw = comment.value

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"moduleResolution": "Bundler",
77
"resolveJsonModule": true,
88
"types": [
9+
"@types/node",
910
"vitest/globals"
1011
],
1112
"strict": true,

0 commit comments

Comments
 (0)