Skip to content

Commit

Permalink
Fix defineCustomBlocksVisitor was incompatible with ESLint v8.40 (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 6, 2023
1 parent 384b521 commit 59d8e25
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sfc/custom-block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ESLintCustomBlockParser = ParserObject<any, any>

export type CustomBlockContext = {
getSourceCode(): SourceCode
sourceCode: SourceCode
parserServices: any
getAncestors(): any[]
getDeclaredVariables(node: any): any[]
Expand Down Expand Up @@ -251,6 +252,9 @@ export function createCustomBlockSharedContext({
: {}),
},
getSourceCode,
get sourceCode() {
return getSourceCode()
},
},
}

Expand Down
39 changes: 39 additions & 0 deletions test/define-custom-blocks-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,5 +667,44 @@ function a(arg) {
"Assignment to function parameter 'arg'.",
)
})

it("should work sourceCode.", () => {
const code = `
<js lang="js">
var v = + 42
</js>
`
const linter = createLinter()
const rule = linter.getRules().get("space-unary-ops")
linter.defineRule("test-space-unary-ops", {
...rule,
create(context) {
return context.parserServices.defineCustomBlocksVisitor(
context,
espree,
{
target: "js",
create(customBlockContext) {
return rule.create(customBlockContext)
},
},
)
},
})

const messages1 = linter.verify(code, {
...LINTER_CONFIG,
rules: {
...LINTER_CONFIG.rules,
"test-space-unary-ops": "error",
},
})

assert.strictEqual(messages1.length, 1)
assert.strictEqual(
messages1[0].message,
"Unexpected space after unary operator '+'.",
)
})
})
})

0 comments on commit 59d8e25

Please sign in to comment.