diff --git a/src/sfc/custom-block/index.ts b/src/sfc/custom-block/index.ts index bdaa1d2..c685af0 100644 --- a/src/sfc/custom-block/index.ts +++ b/src/sfc/custom-block/index.ts @@ -23,6 +23,7 @@ export type ESLintCustomBlockParser = ParserObject export type CustomBlockContext = { getSourceCode(): SourceCode + sourceCode: SourceCode parserServices: any getAncestors(): any[] getDeclaredVariables(node: any): any[] @@ -251,6 +252,9 @@ export function createCustomBlockSharedContext({ : {}), }, getSourceCode, + get sourceCode() { + return getSourceCode() + }, }, } diff --git a/test/define-custom-blocks-visitor.js b/test/define-custom-blocks-visitor.js index 31f6e94..3463402 100644 --- a/test/define-custom-blocks-visitor.js +++ b/test/define-custom-blocks-visitor.js @@ -667,5 +667,44 @@ function a(arg) { "Assignment to function parameter 'arg'.", ) }) + + it("should work sourceCode.", () => { + const code = ` + +var v = + 42 + +` + 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 '+'.", + ) + }) }) })