Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59d8e25

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

File tree

Expand file treeCollapse file tree

2 files changed

+43
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+43
-0
lines changed

‎src/sfc/custom-block/index.ts

Copy file name to clipboardExpand all lines: src/sfc/custom-block/index.ts
+4Lines changed: 4 additions & 0 deletions
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

‎test/define-custom-blocks-visitor.js

Copy file name to clipboardExpand all lines: test/define-custom-blocks-visitor.js
+39Lines changed: 39 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.