Skip to content

Commit

Permalink
fix: replacing context.getSourceCode() by context.sourceCode in eslin…
Browse files Browse the repository at this point in the history
…t-plugin
  • Loading branch information
divdavem committed Dec 19, 2023
1 parent f061ebd commit 92f8ea8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions eslint-plugin/src/angular-check-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
);
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion eslint-plugin/src/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const everythingAfterNonSpaceRegExp = /\S.*$/;
export const getIndentation = (node: TSESTree.Node | TSESTree.Token | SvelteAST.SvelteNode, context: Readonly<TSESLint.RuleContext<any, any>>) => {
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;
};
Expand Down
6 changes: 3 additions & 3 deletions eslint-plugin/src/svelte-check-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const isContextModuleScript = (node: SvelteAST.SvelteScriptElement) => {
};

const followingComma = (node: TSESTree.Node, context: Readonly<TSESLint.RuleContext<any, any>>) => {
const followingComma = context.getSourceCode().getTokenAfter(node);
const followingComma = context.sourceCode.getTokenAfter(node);
return followingComma?.value === ',' ? followingComma : null;
};

Expand Down Expand Up @@ -188,15 +188,15 @@ 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));
}
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);
Expand Down
2 changes: 1 addition & 1 deletion eslint-plugin/src/svelte-check-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 92f8ea8

Please sign in to comment.