Skip to content

Commit 59d8e25

Browse files
authored
Fix defineCustomBlocksVisitor was incompatible with ESLint v8.40 (#192)
1 parent 384b521 commit 59d8e25

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Diff for: src/sfc/custom-block/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type ESLintCustomBlockParser = ParserObject<any, any>
2323

2424
export type CustomBlockContext = {
2525
getSourceCode(): SourceCode
26+
sourceCode: SourceCode
2627
parserServices: any
2728
getAncestors(): any[]
2829
getDeclaredVariables(node: any): any[]
@@ -251,6 +252,9 @@ export function createCustomBlockSharedContext({
251252
: {}),
252253
},
253254
getSourceCode,
255+
get sourceCode() {
256+
return getSourceCode()
257+
},
254258
},
255259
}
256260

Diff for: test/define-custom-blocks-visitor.js

+39
Original file line numberDiff line numberDiff line change
@@ -667,5 +667,44 @@ function a(arg) {
667667
"Assignment to function parameter 'arg'.",
668668
)
669669
})
670+
671+
it("should work sourceCode.", () => {
672+
const code = `
673+
<js lang="js">
674+
var v = + 42
675+
</js>
676+
`
677+
const linter = createLinter()
678+
const rule = linter.getRules().get("space-unary-ops")
679+
linter.defineRule("test-space-unary-ops", {
680+
...rule,
681+
create(context) {
682+
return context.parserServices.defineCustomBlocksVisitor(
683+
context,
684+
espree,
685+
{
686+
target: "js",
687+
create(customBlockContext) {
688+
return rule.create(customBlockContext)
689+
},
690+
},
691+
)
692+
},
693+
})
694+
695+
const messages1 = linter.verify(code, {
696+
...LINTER_CONFIG,
697+
rules: {
698+
...LINTER_CONFIG.rules,
699+
"test-space-unary-ops": "error",
700+
},
701+
})
702+
703+
assert.strictEqual(messages1.length, 1)
704+
assert.strictEqual(
705+
messages1[0].message,
706+
"Unexpected space after unary operator '+'.",
707+
)
708+
})
670709
})
671710
})

0 commit comments

Comments
 (0)