diff --git a/.changeset/better-tires-wait.md b/.changeset/better-tires-wait.md new file mode 100644 index 00000000..e6cfb9b3 --- /dev/null +++ b/.changeset/better-tires-wait.md @@ -0,0 +1,5 @@ +--- +"@codemod-utils/ast-template-tag": minor +--- + +Fixed lint errors diff --git a/packages/ast/template-tag/src/-private/content-tag/get-template.ts b/packages/ast/template-tag/src/-private/content-tag/get-template.ts index 4b3b0d90..1a683a2b 100644 --- a/packages/ast/template-tag/src/-private/content-tag/get-template.ts +++ b/packages/ast/template-tag/src/-private/content-tag/get-template.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { MARKER } from './marker.js'; export function getTemplate(expression: unknown): string | undefined { @@ -9,14 +8,17 @@ export function getTemplate(expression: unknown): string | undefined { if ( // @ts-expect-error: Incorrect type + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access expression.callee.type !== 'Identifier' || // @ts-expect-error: Incorrect type + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access expression.callee.name !== MARKER ) { return; } // @ts-expect-error: Incorrect type + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access const template = expression.arguments[0].quasis[0].value.raw as string; return template; diff --git a/packages/ast/template-tag/src/-private/to-ecma.ts b/packages/ast/template-tag/src/-private/to-ecma.ts index 91ad7e36..dafd797a 100644 --- a/packages/ast/template-tag/src/-private/to-ecma.ts +++ b/packages/ast/template-tag/src/-private/to-ecma.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */ import { AST } from '@codemod-utils/ast-javascript'; import { getTemplate, preprocessor } from './content-tag.js'; @@ -13,15 +12,6 @@ type Marker = { }; }; -function getMarker(nodeValue: unknown): Marker { - return { - // @ts-expect-error: Incorrect type - code: AST.print(nodeValue), - // @ts-expect-error: Incorrect type - end: nodeValue.loc.end, - }; -} - function sortMarkers(a: Marker, b: Marker): number { if (a.end.line > b.end.line) { return -1; @@ -49,36 +39,44 @@ export function findMarkers(file: string): Marker[] { const markers: Marker[] = []; traverse(code, { - visitCallExpression(node) { - const template = getTemplate(node.value); + visitCallExpression(path) { + const template = getTemplate(path.node); if (template === undefined) { - this.traverse(node); + this.traverse(path); return false; } - markers.push(getMarker(node.value)); + markers.push({ + code: AST.print(path.node), + // @ts-expect-error: Incorrect type + end: path.node.loc!.end, + }); return false; }, - visitExportDefaultDeclaration(node) { - const template = getTemplate(node.value.declaration); + visitExportDefaultDeclaration(path) { + const template = getTemplate(path.node.declaration); if (template === undefined) { - this.traverse(node); + this.traverse(path); return false; } - markers.push(getMarker(node.value)); + markers.push({ + code: AST.print(path.node), + // @ts-expect-error: Incorrect type + end: path.node.loc!.end, + }); return false; }, - visitStaticBlock(node) { - const bodyNode = node.value.body[0]; + visitStaticBlock(path) { + const bodyNode = path.node.body[0]!; if (bodyNode.type !== 'ExpressionStatement') { return false; @@ -90,7 +88,11 @@ export function findMarkers(file: string): Marker[] { return false; } - markers.push(getMarker(node.value)); + markers.push({ + code: AST.print(path.node), + // @ts-expect-error: Incorrect type + end: path.node.loc!.end, + }); return false; }, diff --git a/packages/ast/template-tag/src/-private/to-template-tag.ts b/packages/ast/template-tag/src/-private/to-template-tag.ts index 5f20e9a0..b00ac320 100644 --- a/packages/ast/template-tag/src/-private/to-template-tag.ts +++ b/packages/ast/template-tag/src/-private/to-template-tag.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */ import { AST } from '@codemod-utils/ast-javascript'; import { getTemplate, MARKER } from './content-tag.js'; @@ -11,11 +10,11 @@ export function removeMarkers(file: string): string { const traverse = AST.traverse(true); const ast = traverse(file, { - visitCallExpression(node) { - const template = getTemplate(node.value); + visitCallExpression(path) { + const template = getTemplate(path.node); if (template === undefined) { - this.traverse(node); + this.traverse(path); return false; } @@ -23,11 +22,11 @@ export function removeMarkers(file: string): string { return ``; }, - visitExportDefaultDeclaration(node) { - const template = getTemplate(node.value.declaration); + visitExportDefaultDeclaration(path) { + const template = getTemplate(path.node.declaration); if (template === undefined) { - this.traverse(node); + this.traverse(path); return false; } @@ -35,10 +34,10 @@ export function removeMarkers(file: string): string { return ``; }, - visitImportDeclaration(node) { + visitImportDeclaration(path) { if ( - node.value.source.type !== 'StringLiteral' || - node.value.source.value !== '@ember/template-compiler' + path.node.source.type !== 'StringLiteral' || + path.node.source.value !== '@ember/template-compiler' ) { return false; } @@ -47,8 +46,8 @@ export function removeMarkers(file: string): string { return null; }, - visitStaticBlock(node) { - const bodyNode = node.value.body[0]; + visitStaticBlock(path) { + const bodyNode = path.node.body[0]!; if (bodyNode.type !== 'ExpressionStatement') { return false;