From 92f8ea88c669c83e7981300614b355ef6198fb2f Mon Sep 17 00:00:00 2001 From: David-Emmanuel DIVERNOIS Date: Wed, 13 Dec 2023 14:29:02 +0100 Subject: [PATCH] fix: replacing context.getSourceCode() by context.sourceCode in eslint-plugin --- eslint-plugin/src/angular-check-props.ts | 7 +++---- eslint-plugin/src/ast-utils.ts | 2 +- eslint-plugin/src/svelte-check-props.ts | 6 +++--- eslint-plugin/src/svelte-check-slots.ts | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/eslint-plugin/src/angular-check-props.ts b/eslint-plugin/src/angular-check-props.ts index 9f6f216e11..807bf30fd3 100644 --- a/eslint-plugin/src/angular-check-props.ts +++ b/eslint-plugin/src/angular-check-props.ts @@ -253,8 +253,7 @@ const reportNonMatchingPropDoc = ( type, }, *fix(fixer) { - const commentsBefore = context - .getSourceCode() + const commentsBefore = context.sourceCode .getCommentsBefore(node) .filter((comment) => comment.type === TSESTree.AST_TOKEN_TYPES.Block && comment.value.startsWith('*')); for (const comment of commentsBefore) { @@ -300,7 +299,7 @@ const fixOutputEmit = ( const indentation = getChildIndentation(eventInEventsObject.body.body[0], eventInEventsObject.body, context); return insertLineBefore( fixer, - context.getSourceCode().getLastToken(eventInEventsObject.body)!, + context.sourceCode.getLastToken(eventInEventsObject.body)!, addIndentation(`\nthis.${name}.emit(${eventInEventsObject.params[0].name});`, indentation), context, ); @@ -310,7 +309,7 @@ const fixOutputEmit = ( const propText = `\n${prop.widgetProp}: ${arrowFunction},`; if (eventsObject) { const indentation = getChildIndentation(eventsObject.properties[0], eventsObject, context); - return fixer.insertTextAfter(context.getSourceCode().getFirstToken(eventsObject)!, addIndentation(propText, indentation)); + return fixer.insertTextAfter(context.sourceCode.getFirstToken(eventsObject)!, addIndentation(propText, indentation)); } return null; }; diff --git a/eslint-plugin/src/ast-utils.ts b/eslint-plugin/src/ast-utils.ts index c897de57b6..d89de28b7d 100644 --- a/eslint-plugin/src/ast-utils.ts +++ b/eslint-plugin/src/ast-utils.ts @@ -43,7 +43,7 @@ const everythingAfterNonSpaceRegExp = /\S.*$/; export const getIndentation = (node: TSESTree.Node | TSESTree.Token | SvelteAST.SvelteNode, context: Readonly>) => { const position = node.range[0]; const column = node.loc.start.column; - const text = context.getSourceCode().text; + const text = context.sourceCode.text; const indentation = text.substring(position - column, position).replace(everythingAfterNonSpaceRegExp, ''); return indentation; }; diff --git a/eslint-plugin/src/svelte-check-props.ts b/eslint-plugin/src/svelte-check-props.ts index 28d4a8cbe3..4e4f2fbdb7 100644 --- a/eslint-plugin/src/svelte-check-props.ts +++ b/eslint-plugin/src/svelte-check-props.ts @@ -32,7 +32,7 @@ const isContextModuleScript = (node: SvelteAST.SvelteScriptElement) => { }; const followingComma = (node: TSESTree.Node, context: Readonly>) => { - const followingComma = context.getSourceCode().getTokenAfter(node); + const followingComma = context.sourceCode.getTokenAfter(node); return followingComma?.value === ',' ? followingComma : null; }; @@ -188,7 +188,7 @@ const fixApiPatchEventHandler = ( content += `\n${prop.propBinding} = ${eventInApiPatch.params[0].name};`; } const indentation = getChildIndentation(eventInApiPatch.body.body[0], eventInApiPatch.body, context); - return insertNewLineBefore(fixer, context.getSourceCode().getLastToken(eventInApiPatch.body)!, addIndentation(content, indentation), context); + return insertNewLineBefore(fixer, context.sourceCode.getLastToken(eventInApiPatch.body)!, addIndentation(content, indentation), context); } const indentation = getIndentation(eventInApiPatch, context); return fixer.replaceText(eventInApiPatch, addIndentation(arrowFunction, indentation)); @@ -196,7 +196,7 @@ const fixApiPatchEventHandler = ( const propText = `\n${prop.widgetProp}: ${arrowFunction},`; if (widgetPatchArgNode) { const indentation = getChildIndentation(widgetPatchArgNode.properties[0], widgetPatchArgNode, context); - return fixer.insertTextAfter(context.getSourceCode().getFirstToken(widgetPatchArgNode)!, addIndentation(propText, indentation)); + return fixer.insertTextAfter(context.sourceCode.getFirstToken(widgetPatchArgNode)!, addIndentation(propText, indentation)); } const widgetPatchCall = `\nwidget.patch({${addIndentation(propText, '\t')}\n});`; const indentation = getIndentation(widgetStatementNode, context); diff --git a/eslint-plugin/src/svelte-check-slots.ts b/eslint-plugin/src/svelte-check-slots.ts index 8e0043c63b..07a3e558eb 100644 --- a/eslint-plugin/src/svelte-check-slots.ts +++ b/eslint-plugin/src/svelte-check-slots.ts @@ -149,7 +149,7 @@ export const svelteCheckSlotsRule = ESLintUtils.RuleCreator.withoutDocs({ return { SvelteElement(node: SvelteAST.SvelteElement) { if (node.kind === 'component' && node.name.type === 'Identifier' && node.name.name === 'Slot') { - const sourceText = context.getSourceCode().text; + const sourceText = context.sourceCode.text; const nodeText = sourceText.substring(...node.range); const slotName = extractSlotName(node); if (slotName) {