diff --git a/benchmark/index.ts b/benchmark/index.ts index 152dde7a..31225ff3 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -7,7 +7,7 @@ import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser const contents = `${fs.readFileSync( require.resolve("../explorer-v2/src/lib/RulesSettings.svelte"), - "utf-8" + "utf-8", )}// comments`; type Result = { name: string; hz: number }; @@ -34,8 +34,8 @@ function onComplete(): void { for (const name of Object.keys(map)) { console.log( `${name.padEnd(15)} ${format( - map[name].reduce((p, a) => p + a, 0) / map[name].length - )} ops/sec` + map[name].reduce((p, a) => p + a, 0) / map[name].length, + )} ops/sec`, ); } for (let i = 0; i < results.length; ++i) { diff --git a/explorer-v2/package.json b/explorer-v2/package.json index bdd263b5..80ed8b85 100644 --- a/explorer-v2/package.json +++ b/explorer-v2/package.json @@ -26,8 +26,8 @@ "devDependencies": { "@sveltejs/adapter-static": "^2.0.0", "@sveltejs/kit": "^1.0.0-next.456", - "prettier": "^2.3.0", - "prettier-plugin-svelte": "^2.3.0", + "prettier": "^3.0.0", + "prettier-plugin-svelte": "^3.0.0", "string-replace-loader": "^3.0.1", "typescript": "^5.0.4", "vite": "^4.0.0", diff --git a/package.json b/package.json index 0339d47f..459e5845 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "eslint-plugin-jsonc": "^2.8.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-node-dependencies": "^0.11.0", - "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-regexp": "^1.15.0", "eslint-plugin-svelte": "^2.30.0", "eslint-plugin-yml": "^1.7.0", @@ -98,9 +98,9 @@ "mocha": "^10.2.0", "mocha-chai-jest-snapshot": "^1.1.4", "nyc": "^15.1.0", - "prettier": "^2.8.8", + "prettier": "^3.0.0", "prettier-plugin-pkg": "^0.18.0", - "prettier-plugin-svelte": "^2.10.1", + "prettier-plugin-svelte": "^3.0.0", "rimraf": "^5.0.1", "semver": "^7.5.1", "svelte": "^4.0.0", diff --git a/src/context/index.ts b/src/context/index.ts index 79834a03..4c65251a 100644 --- a/src/context/index.ts +++ b/src/context/index.ts @@ -43,7 +43,7 @@ export class ScriptsSourceCode { public constructor( script: string, - attrs: Record + attrs: Record, ) { this.raw = script; this.trimmedRaw = script.trimEnd(); @@ -170,12 +170,12 @@ export class Context { // It will be restored later in `convertHTMLElement()` processing. templateCode += `${code.slice( start, - block.startTagRange[0] + 2 /* `<` and first letter */ + block.startTagRange[0] + 2 /* `<` and first letter */, )}${"-".repeat( - block.tag.length - 1 /* skip first letter */ + block.tag.length - 1 /* skip first letter */, )}${code.slice( block.startTagRange[0] + 1 /* skip `<` */ + block.tag.length, - block.startTagRange[1] + block.startTagRange[1], )}`; scriptCode += spaces.slice(start, block.startTagRange[1]); start = block.startTagRange[1]; @@ -227,7 +227,7 @@ export class Context { * @param node The node. */ public getConvertLocation( - node: { start: number; end: number } | ESTree.Node + node: { start: number; end: number } | ESTree.Node, ): Locations { const { start, end } = node as any; @@ -249,7 +249,7 @@ export class Context { */ public addToken( type: Token["type"], - range: { start: number; end: number } + range: { start: number; end: number }, ): Token { const token = { type, @@ -277,7 +277,7 @@ export class Context { } const parserValue = getParserForLang( this.sourceCode.scripts.attrs, - this.parserOptions?.parser + this.parserOptions?.parser, ); if (typeof parserValue !== "string") { return (this.state.isTypeScript = @@ -295,7 +295,7 @@ export class Context { if (fs.existsSync(pkgPath)) { try { return (this.state.isTypeScript = TS_PARSER_NAMES.includes( - JSON.parse(fs.readFileSync(pkgPath, "utf-8"))?.name + JSON.parse(fs.readFileSync(pkgPath, "utf-8"))?.name, )); } catch { return (this.state.isTypeScript = false); @@ -317,7 +317,7 @@ export class Context { } public findBlock( - element: SvelteScriptElement | SvelteStyleElement | SvelteElement + element: SvelteScriptElement | SvelteStyleElement | SvelteElement, ): Block | undefined { const tag = element.type === "SvelteScriptElement" @@ -330,19 +330,19 @@ export class Context { block.tag === tag && !block.selfClosing && element.range[0] <= block.contentRange[0] && - block.contentRange[1] <= element.range[1] + block.contentRange[1] <= element.range[1], ); } public findSelfClosingBlock( - element: SvelteElement + element: SvelteElement, ): SelfClosingBlock | undefined { return this.blocks.find((block): block is SelfClosingBlock => Boolean( block.selfClosing && element.startTag.range[0] <= block.startTagRange[0] && - block.startTagRange[1] <= element.startTag.range[1] - ) + block.startTagRange[1] <= element.startTag.range[1], + ), ); } } @@ -453,7 +453,7 @@ export class LinesAndColumns { public getLocFromIndex(index: number): { line: number; column: number } { const lineNumber = sortedLastIndex( this.lineStartIndices, - (target) => target - index + (target) => target - index, ); return { line: lineNumber, diff --git a/src/context/script-let.ts b/src/context/script-let.ts index 9d62927c..6953b75a 100644 --- a/src/context/script-let.ts +++ b/src/context/script-let.ts @@ -37,7 +37,7 @@ type TSParenthesizedType = { export type ScriptLetCallback = ( es: E, - options: ScriptLetCallbackOption + options: ScriptLetCallbackOption, ) => void; export type ScriptLetCallbackOption = { @@ -50,7 +50,7 @@ export type ScriptLetRestoreCallback = ( node: ESTree.Node, tokens: Token[], comments: Comment[], - options: ScriptLetRestoreCallbackOption + options: ScriptLetRestoreCallbackOption, ) => void; type ScriptLetRestoreCallbackOption = { getScope: (node: ESTree.Node) => Scope; @@ -76,7 +76,7 @@ function getNodeRange( range: [number, number]; leadingComments?: Comment[]; trailingComments?: Comment[]; - } + }, ): [number, number] { let start = null; let end = null; @@ -85,7 +85,7 @@ function getNodeRange( } if (node.trailingComments) { end = getWithLoc( - node.trailingComments[node.trailingComments.length - 1] + node.trailingComments[node.trailingComments.length - 1], ).end; } @@ -167,7 +167,7 @@ export class ScriptLetContext { if (isTS) { for (const scope of extractTypeNodeScopes( tsAs!.typeAnnotation, - result + result, )) { removeScope(result.scopeManager, scope); } @@ -181,7 +181,7 @@ export class ScriptLetContext { ], tokens, comments, - result.visitorKeys + result.visitorKeys, ); } @@ -193,7 +193,7 @@ export class ScriptLetContext { // Disconnect the tree structure. exprSt.expression = null as never; - } + }, ); return callbacks; } @@ -228,7 +228,7 @@ export class ScriptLetContext { // Disconnect the tree structure. exprSt.expression = null as never; - } + }, ); } @@ -266,7 +266,7 @@ export class ScriptLetContext { // Disconnect the tree structure. decl.declarations = []; - } + }, ); return callbacks; } @@ -274,7 +274,7 @@ export class ScriptLetContext { public nestIfBlock( expression: ESTree.Expression, ifBlock: SvelteIfBlock, - callback: ScriptLetCallback + callback: ScriptLetCallback, ): void { const range = getNodeRange(expression); const part = this.ctx.code.slice(...range); @@ -302,7 +302,7 @@ export class ScriptLetContext { // Disconnect the tree structure. ifSt.test = null as never; ifSt.consequent = null as never; - } + }, ); this.pushScope(restore, "}"); } @@ -315,8 +315,8 @@ export class ScriptLetContext { callback: ( expr: ESTree.Expression, ctx: ESTree.Pattern, - index: ESTree.Identifier | null - ) => void + index: ESTree.Identifier | null, + ) => void, ): void { const exprRange = getNodeRange(expression); const ctxRange = getNodeRange(context); @@ -362,7 +362,7 @@ export class ScriptLetContext { const arrayId = (callArrayFrom.callee as ESTree.MemberExpression) .object; const ref = scope.upper!.references.find( - (r) => r.identifier === arrayId + (r) => r.identifier === arrayId, ); if (ref) { removeReference(ref, scope.upper!); @@ -409,7 +409,7 @@ export class ScriptLetContext { // Disconnect the tree structure. expSt.expression = null as never; - } + }, ); this.pushScope(restore, "});"); } @@ -421,7 +421,7 @@ export class ScriptLetContext { | ((helper: TypeGenHelper | null) => { param: ScriptLetBlockParam; preparationScript?: string[]; - }) + }), ): void { let resolvedParams; if (typeof params === "function") { @@ -438,7 +438,7 @@ export class ScriptLetContext { tokens.length = 0; comments.length = 0; removeAllScopeAndVariableAndReference(node, result); - } + }, ); } } @@ -464,7 +464,7 @@ export class ScriptLetContext { // Disconnect the tree structure. blockSt.body = null as never; - } + }, ); this.pushScope(restore, "}"); } else { @@ -559,12 +559,12 @@ export class ScriptLetContext { }), tokens, comments, - result.visitorKeys + result.visitorKeys, ); // Disconnect the tree structure. exprSt.expression = null as never; - } + }, ); this.pushScope(restore, "};"); } @@ -585,8 +585,8 @@ export class ScriptLetContext { node: ESTree.Node, tokens: Token[], comments: Comment[], - options: ScriptLetCallbackOption - ) => void + options: ScriptLetCallbackOption, + ) => void, ) { const resultCallback = this.appendScriptWithoutOffset( text, @@ -596,10 +596,10 @@ export class ScriptLetContext { tokens, comments, offset - resultCallback.start, - result.visitorKeys + result.visitorKeys, ); callback(node, tokens, comments, result); - } + }, ); return resultCallback; } @@ -610,8 +610,8 @@ export class ScriptLetContext { node: ESTree.Node, tokens: Token[], comments: Comment[], - options: ScriptLetCallbackOption - ) => void + options: ScriptLetCallbackOption, + ) => void, ) { const { start: startOffset, end: endOffset } = this.script.addLet(text); @@ -678,7 +678,7 @@ export class ScriptLetContext { */ private restoreNodes( result: ESLintExtendedProgram, - callbackOption: ScriptLetRestoreCallbackOption + callbackOption: ScriptLetRestoreCallbackOption, ): void { let orderedRestoreCallback = this.restoreCallbacks.shift(); if (!orderedRestoreCallback) { @@ -748,7 +748,7 @@ export class ScriptLetContext { const startIndex = { token: tokens.findIndex((t) => restoreCallback.start <= t.range[0]), comment: comments.findIndex( - (t) => restoreCallback.start <= t.range[0] + (t) => restoreCallback.start <= t.range[0], ), }; if (startIndex.comment === -1) { @@ -757,11 +757,11 @@ export class ScriptLetContext { const endIndex = { token: tokens.findIndex( (t) => restoreCallback.end < t.range[1], - startIndex.token + startIndex.token, ), comment: comments.findIndex( (t) => restoreCallback.end < t.range[1], - startIndex.comment + startIndex.comment, ), }; if (endIndex.token === -1) { @@ -772,17 +772,17 @@ export class ScriptLetContext { } const targetTokens = tokens.splice( startIndex.token, - endIndex.token - startIndex.token + endIndex.token - startIndex.token, ); const targetComments = comments.splice( startIndex.comment, - endIndex.comment - startIndex.comment + endIndex.comment - startIndex.comment, ); restoreCallback.callback( node, targetTokens, targetComments, - callbackOption + callbackOption, ); processedTokens.push(...targetTokens); @@ -803,14 +803,14 @@ export class ScriptLetContext { */ private restoreProgram( result: ESLintExtendedProgram, - callbackOption: ScriptLetRestoreCallbackOption + callbackOption: ScriptLetRestoreCallbackOption, ): void { for (const callback of this.programRestoreCallbacks) { callback( result.ast, result.ast.tokens, result.ast.comments, - callbackOption + callbackOption, ); } } @@ -823,7 +823,7 @@ export class ScriptLetContext { }[], tokens: Token[], comments: Comment[], - visitorKeys?: { [type: string]: string[] } + visitorKeys?: { [type: string]: string[] }, ) { const targetMaps = [...maps]; const first = targetMaps.shift()!; @@ -861,10 +861,10 @@ export class ScriptLetContext { map.newNode, bufferTokens, comments.filter( - (t) => startOffset <= t.range[0] && t.range[1] <= endOffset + (t) => startOffset <= t.range[0] && t.range[1] <= endOffset, ), map.range[0] - startOffset, - visitorKeys + visitorKeys, ); } tokens.splice(tokenIndex); @@ -876,7 +876,7 @@ export class ScriptLetContext { tokens: Token[], comments: Comment[], offset: number, - visitorKeys?: { [type: string]: string[] } + visitorKeys?: { [type: string]: string[] }, ) { if (offset === 0) { return; @@ -928,7 +928,7 @@ export class ScriptLetContext { return this.unique.generate( base, this.ctx.code, - this.script.getCurrentVirtualCode() + this.script.getCurrentVirtualCode(), ); } } @@ -949,7 +949,7 @@ function applyLocs(target: Locations | ESTree.Node, locs: Locations) { /** Get the node to scope map from given scope manager */ function getNodeToScope( - scopeManager: ScopeManager + scopeManager: ScopeManager, ): WeakMap { if ("__nodeToScope" in scopeManager) { return (scopeManager as any).__nodeToScope; @@ -1015,7 +1015,7 @@ function getNodeToScope( /** Extract the type scope of the given node. */ function extractTypeNodeScopes( node: TSESTree.TypeNode | TSParenthesizedType, - result: ScriptLetCallbackOption + result: ScriptLetCallbackOption, ): Iterable { const scopes = new Set(); for (const scope of iterateTypeNodeScopes(node)) { @@ -1026,7 +1026,7 @@ function extractTypeNodeScopes( /** Iterate the type scope of the given node. */ function* iterateTypeNodeScopes( - node: TSESTree.TypeNode | TSParenthesizedType + node: TSESTree.TypeNode | TSParenthesizedType, ): Iterable { if (node.type === "TSParenthesizedType") { // Skip TSParenthesizedType. diff --git a/src/parser/analyze-scope.ts b/src/parser/analyze-scope.ts index 9cec85bc..d42b4fca 100644 --- a/src/parser/analyze-scope.ts +++ b/src/parser/analyze-scope.ts @@ -10,7 +10,7 @@ import { addElementToSortedArray } from "../utils"; */ export function analyzeScope( node: ESTree.Node, - parserOptions: any = {} + parserOptions: any = {}, ): ScopeManager { const ecmaVersion = parserOptions.ecmaVersion || 2020; const ecmaFeatures = parserOptions.ecmaFeatures || {}; @@ -59,7 +59,7 @@ export function analyzeReactiveScope(scopeManager: ScopeManager): void { function transformComputedVariable( node: ESTree.AssignmentExpression, parent: SvelteReactiveStatement, - reference: Reference + reference: Reference, ) { const referenceScope: Scope = reference.from; const name = reference.identifier.name; @@ -76,7 +76,7 @@ export function analyzeReactiveScope(scopeManager: ScopeManager): void { parent: parent as any, name: reference.identifier, }, - (a, b) => a.node.range[0] - b.node.range[0] + (a, b) => a.node.range[0] - b.node.range[0], ); addVariable(referenceScope.variables, variable); referenceScope.set.set(name, variable); @@ -84,7 +84,7 @@ export function analyzeReactiveScope(scopeManager: ScopeManager): void { addElementToSortedArray( variable.identifiers, reference.identifier, - (a, b) => a.range![0] - b.range![0] + (a, b) => a.range![0] - b.range![0], ); reference.resolved = variable; removeReferenceFromThrough(reference, referenceScope); @@ -96,7 +96,7 @@ export function analyzeReactiveScope(scopeManager: ScopeManager): void { */ export function analyzeStoreScope(scopeManager: ScopeManager): void { const moduleScope = scopeManager.scopes.find( - (scope) => scope.type === "module" + (scope) => scope.type === "module", ); if (!moduleScope) { return; @@ -129,13 +129,13 @@ export function analyzeStoreScope(scopeManager: ScopeManager): void { } for (const variable of new Set( - toBeMarkAsUsedReferences.map((ref) => ref.resolved!) + toBeMarkAsUsedReferences.map((ref) => ref.resolved!), )) { if ( variable.references.some( (ref) => !toBeMarkAsUsedReferences.includes(ref) && - ref.identifier !== variable.identifiers[0] + ref.identifier !== variable.identifiers[0], ) ) { // It is already used. @@ -154,10 +154,10 @@ export function analyzeStoreScope(scopeManager: ScopeManager): void { /** Transform props exports */ export function analyzePropsScope( body: SvelteScriptElement, - scopeManager: ScopeManager + scopeManager: ScopeManager, ): void { const moduleScope = scopeManager.scopes.find( - (scope) => scope.type === "module" + (scope) => scope.type === "module", ); if (!moduleScope) { return; @@ -210,7 +210,7 @@ export function analyzePropsScope( { write: true, read: true, - } + }, ); (reference as any).sveltePropReference = true; } @@ -246,7 +246,7 @@ function addVirtualReference( node: ESTree.Identifier, variable: Variable, scope: Scope, - readWrite: { read?: boolean; write?: boolean } + readWrite: { read?: boolean; write?: boolean }, ) { const reference = new Reference(); (reference as any).svelteVirtualReference = true; diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 3490d6d4..6051def8 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -37,7 +37,7 @@ export function* convertAttributes( attributes: SvAST.AttributeOrDirective[], parent: SvelteStartTag, elementName: string, - ctx: Context + ctx: Context, ): IterableIterator< | SvelteAttribute | SvelteShorthandAttribute @@ -93,13 +93,13 @@ export function* convertAttributes( throw new ParseError( `Svelte v3.46.0 is no longer supported. Please use Svelte>=v3.46.1.`, attr.start, - ctx + ctx, ); } throw new ParseError( `Unknown directive or attribute (${attr.type}) are not supported.`, attr.start, - ctx + ctx, ); } } @@ -108,7 +108,7 @@ export function* convertAttributes( export function* convertAttributeTokens( attributes: AttributeToken[], parent: SvelteStartTag, - ctx: Context + ctx: Context, ): IterableIterator { for (const attr of attributes) { const attribute: SvelteAttribute = { @@ -133,7 +133,7 @@ export function* convertAttributeTokens( attribute.boolean = true; } else { attribute.value.push( - convertAttributeValueTokenToLiteral(attr.value, attribute, ctx) + convertAttributeValueTokenToLiteral(attr.value, attribute, ctx), ); } yield attribute; @@ -144,7 +144,7 @@ export function* convertAttributeTokens( function convertAttribute( node: SvAST.Attribute, parent: SvelteAttribute["parent"], - ctx: Context + ctx: Context, ): SvelteAttribute | SvelteShorthandAttribute { const attribute: SvelteAttribute = { type: "SvelteAttribute", @@ -199,7 +199,7 @@ function convertAttribute( processAttributeValue( node.value as (SvAST.Text | SvAST.MustacheTag)[], attribute, - ctx + ctx, ); // Not required for shorthands. Therefore, register the token here. @@ -212,7 +212,7 @@ function convertAttribute( function processAttributeValue( nodeValue: (SvAST.Text | SvAST.MustacheTag)[], attribute: SvelteAttribute | SvelteStyleDirectiveLongform, - ctx: Context + ctx: Context, ) { for (let index = 0; index < nodeValue.length; index++) { const v = nodeValue[index]; @@ -240,7 +240,7 @@ function processAttributeValue( throw new ParseError( `Unknown attribute value (${u.type}) are not supported.`, u.start, - ctx + ctx, ); } } @@ -249,7 +249,7 @@ function processAttributeValue( function convertSpreadAttribute( node: SvAST.Spread, parent: SvelteSpreadAttribute["parent"], - ctx: Context + ctx: Context, ): SvelteSpreadAttribute { const attribute: SvelteSpreadAttribute = { type: "SvelteSpreadAttribute", @@ -275,7 +275,7 @@ function convertSpreadAttribute( function convertBindingDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteBindingDirective { const directive: SvelteBindingDirective = { type: "SvelteDirective", @@ -297,7 +297,7 @@ function convertBindingDirective( directive.expression = es; const scope = getScope(es); const reference = scope.references.find( - (ref) => ref.identifier === es + (ref) => ref.identifier === es, ); if (reference) { // The bind directive does read and write. @@ -307,7 +307,7 @@ function convertBindingDirective( reference.isReadOnly = () => false; reference.isRead = () => true; } - } + }, ); }, }); @@ -319,7 +319,7 @@ function convertEventHandlerDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], elementName: string, - ctx: Context + ctx: Context, ): SvelteEventHandlerDirective { const directive: SvelteEventHandlerDirective = { type: "SvelteDirective", @@ -334,7 +334,7 @@ function convertEventHandlerDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - typing + typing, ), }); return directive; @@ -344,7 +344,7 @@ function convertEventHandlerDirective( function buildEventHandlerType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, elementName: string, - eventName: string + eventName: string, ) { const nativeEventHandlerType = `(e:${conditional({ check: `'${eventName}'`, @@ -427,7 +427,7 @@ function buildEventHandlerType( function convertClassDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteClassDirective { const directive: SvelteClassDirective = { type: "SvelteDirective", @@ -451,7 +451,7 @@ function convertClassDirective( function convertStyleDirective( node: SvAST.StyleDirective, parent: SvelteStyleDirective["parent"], - ctx: Context + ctx: Context, ): SvelteStyleDirective { const directive: SvelteStyleDirectiveLongform = { type: "SvelteStyleDirective", @@ -477,11 +477,11 @@ function convertStyleDirective( throw new ParseError( `Expected JS identifier or attribute value.`, expression.range![0], - ctx + ctx, ); } shorthandDirective.key.name = expression; - } + }, ); return shorthandDirective; } @@ -499,7 +499,7 @@ function convertStyleDirective( function convertTransitionDirective( node: SvAST.TransitionDirective, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteTransitionDirective { const directive: SvelteTransitionDirective = { type: "SvelteDirective", @@ -515,14 +515,14 @@ function convertTransitionDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - null + null, ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier"], ctx) + buildExpressionTypeChecker(["Identifier"], ctx), ), }); return directive; @@ -532,7 +532,7 @@ function convertTransitionDirective( function convertAnimationDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteAnimationDirective { const directive: SvelteAnimationDirective = { type: "SvelteDirective", @@ -546,14 +546,14 @@ function convertAnimationDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - null + null, ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier"], ctx) + buildExpressionTypeChecker(["Identifier"], ctx), ), }); return directive; @@ -563,7 +563,7 @@ function convertAnimationDirective( function convertActionDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteActionDirective { const directive: SvelteActionDirective = { type: "SvelteDirective", @@ -577,14 +577,14 @@ function convertActionDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - `Parameters[1]` + `Parameters[1]`, ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx) + buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx), ), }); return directive; @@ -594,7 +594,7 @@ function convertActionDirective( function convertLetDirective( node: SvAST.LetDirective, parent: SvelteLetDirective["parent"], - ctx: Context + ctx: Context, ): SvelteLetDirective { const directive: SvelteLetDirective = { type: "SvelteDirective", @@ -628,26 +628,26 @@ function convertLetDirective( type DirectiveProcessors< D extends SvAST.Directive, S extends SvelteDirective, - E extends D["expression"] & S["expression"] + E extends D["expression"] & S["expression"], > = | { processExpression: ( expression: E, - shorthand: boolean + shorthand: boolean, ) => ScriptLetCallback>[]; processPattern?: undefined; processName?: ( - expression: SvelteName + expression: SvelteName, ) => ScriptLetCallback>[]; } | { processExpression?: undefined; processPattern: ( expression: E, - shorthand: boolean + shorthand: boolean, ) => ScriptLetCallback>[]; processName?: ( - expression: SvelteName + expression: SvelteName, ) => ScriptLetCallback>[]; }; @@ -655,12 +655,12 @@ type DirectiveProcessors< function processDirective< D extends SvAST.Directive, S extends SvelteDirective, - E extends D["expression"] & S["expression"] + E extends D["expression"] & S["expression"], >( node: D & { expression: null | E }, directive: S, ctx: Context, - processors: DirectiveProcessors + processors: DirectiveProcessors, ) { processDirectiveKey(node, directive, ctx); processDirectiveExpression(node, directive, ctx, processors); @@ -669,7 +669,7 @@ function processDirective< /** Common process for directive key */ function processDirectiveKey< D extends SvAST.Directive | SvAST.StyleDirective, - S extends SvelteDirective | SvelteStyleDirective + S extends SvelteDirective | SvelteStyleDirective, >(node: D, directive: S, ctx: Context) { const colonIndex = ctx.code.indexOf(":", directive.range[0]); ctx.addToken("HTMLIdentifier", { @@ -690,7 +690,7 @@ function processDirectiveKey< let nextEnd = indexOf( ctx.code, (c) => c === "=" || c === ">" || c === "/" || c === "|" || !c.trim(), - nextStart + nextStart, ); ctx.addToken("HTMLIdentifier", { start: nextStart, end: nextEnd }); while (ctx.code[nextEnd] === "|") { @@ -698,7 +698,7 @@ function processDirectiveKey< nextEnd = indexOf( ctx.code, (c) => c === "=" || c === ">" || c === "/" || c === "|" || !c.trim(), - nextStart + nextStart, ); ctx.addToken("HTMLIdentifier", { start: nextStart, end: nextEnd }); } @@ -726,12 +726,12 @@ function processDirectiveKey< function processDirectiveExpression< D extends SvAST.Directive, S extends SvelteDirective, - E extends D["expression"] + E extends D["expression"], >( node: D & { expression: null | E }, directive: S, ctx: Context, - processors: DirectiveProcessors + processors: DirectiveProcessors, ) { const key = directive.key; const keyName = key.name as SvelteName; @@ -753,7 +753,7 @@ function processDirectiveExpression< throw new ParseError( `Expected ${node.expression.type}, but ${es.type} found.`, es.range![0], - ctx + ctx, ); } directive.expression = es; @@ -782,7 +782,7 @@ function processDirectiveExpression< function buildProcessExpressionForExpression( directive: SvelteDirective & { expression: null | ESTree.Expression }, ctx: Context, - typing: string | null + typing: string | null, ): (expression: ESTree.Expression) => ScriptLetCallback[] { return (expression) => { return ctx.scriptLet.addExpression(expression, directive, typing); @@ -792,14 +792,14 @@ function buildProcessExpressionForExpression( /** Build expression type checker to script let callbacks */ function buildExpressionTypeChecker( expected: T["type"][], - ctx: Context + ctx: Context, ): ScriptLetCallback { return (node) => { if (!expected.includes(node.type)) { throw new ParseError( `Expected JS ${expected.join(", or ")}, but ${node.type} found.`, node.range![0], - ctx + ctx, ); } }; diff --git a/src/parser/converts/block.ts b/src/parser/converts/block.ts index 14daf9c9..41c3ec4f 100644 --- a/src/parser/converts/block.ts +++ b/src/parser/converts/block.ts @@ -37,27 +37,27 @@ function startBlockIndex(code: string, endIndex: number): number { } return false; }, - endIndex + endIndex, ); } export function convertIfBlock( node: SvAST.IfBlock, parent: SvelteIfBlock["parent"], - ctx: Context + ctx: Context, ): SvelteIfBlockAlone; export function convertIfBlock( node: SvAST.IfBlock, parent: SvelteIfBlock["parent"], ctx: Context, - elseif: true + elseif: true, ): SvelteIfBlockElseIf; /** Convert for IfBlock */ export function convertIfBlock( node: SvAST.IfBlock, parent: SvelteIfBlock["parent"], ctx: Context, - elseif?: true + elseif?: true, ): SvelteIfBlock { // {#if expr} {:else} {/if} // {:else if expr} {/if} @@ -141,7 +141,7 @@ export function convertIfBlock( export function convertEachBlock( node: SvAST.EachBlock, parent: SvelteEachBlock["parent"], - ctx: Context + ctx: Context, ): SvelteEachBlock { // {#each expr as item, index (key)} {/each} const eachBlock: SvelteEachBlock = { @@ -175,7 +175,7 @@ export function convertEachBlock( eachBlock.expression = expression; eachBlock.context = context; eachBlock.index = index; - } + }, ); const asStart = ctx.code.indexOf("as", getWithLoc(node.expression).end); @@ -224,7 +224,7 @@ export function convertEachBlock( export function convertAwaitBlock( node: SvAST.AwaitBlock, parent: SvelteAwaitBlock["parent"], - ctx: Context + ctx: Context, ): SvelteAwaitBlock { const awaitBlock = { type: "SvelteAwaitBlock", @@ -243,7 +243,7 @@ export function convertAwaitBlock( null, (expression) => { awaitBlock.expression = expression; - } + }, ); if (!node.pending.skip) { @@ -258,7 +258,7 @@ export function convertAwaitBlock( }; ctx.scriptLet.nestBlock(pendingBlock); pendingBlock.children.push( - ...convertChildren(node.pending, pendingBlock, ctx) + ...convertChildren(node.pending, pendingBlock, ctx), ); awaitBlock.pending = pendingBlock; ctx.scriptLet.closeScope(); @@ -341,7 +341,7 @@ export function convertAwaitBlock( } else { const thenIndex = ctx.code.indexOf( "then", - getWithLoc(node.expression).end + getWithLoc(node.expression).end, ); ctx.addToken("MustacheKeyword", { start: thenIndex, @@ -390,7 +390,7 @@ export function convertAwaitBlock( } else { const catchIndex = ctx.code.indexOf( "catch", - getWithLoc(node.expression).end + getWithLoc(node.expression).end, ); ctx.addToken("MustacheKeyword", { start: catchIndex, @@ -410,7 +410,7 @@ export function convertAwaitBlock( export function convertKeyBlock( node: SvAST.KeyBlock, parent: SvelteKeyBlock["parent"], - ctx: Context + ctx: Context, ): SvelteKeyBlock { const keyBlock: SvelteKeyBlock = { type: "SvelteKeyBlock", @@ -444,17 +444,17 @@ function extractMustacheBlockTokens( | SvelteAwaitCatchBlock | SvelteKeyBlock, ctx: Context, - option?: { startOnly?: true } + option?: { startOnly?: true }, ) { const startSectionNameStart = indexOf( ctx.code, (c) => Boolean(c.trim()), - node.range[0] + 1 + node.range[0] + 1, ); const startSectionNameEnd = indexOf( ctx.code, (c) => c === "}" || !c.trim(), - startSectionNameStart + 1 + startSectionNameStart + 1, ); ctx.addToken("MustacheKeyword", { start: startSectionNameStart, @@ -470,7 +470,7 @@ function extractMustacheBlockTokens( const endSectionNameStart = lastIndexOf( ctx.code, (c) => c === "{" || c === "/" || !c.trim(), - endSectionNameEnd - 1 + endSectionNameEnd - 1, ); ctx.addToken("MustacheKeyword", { start: endSectionNameStart, @@ -498,12 +498,12 @@ function hasIdentifierFor(name: string, node: ESTree.Pattern): boolean { return node.properties.some((property) => property.type === "Property" ? hasIdentifierFor(name, property.value) - : hasIdentifierFor(name, property) + : hasIdentifierFor(name, property), ); } if (node.type === "ArrayPattern") { return node.elements.some( - (element) => element && hasIdentifierFor(name, element) + (element) => element && hasIdentifierFor(name, element), ); } if (node.type === "RestElement") { diff --git a/src/parser/converts/common.ts b/src/parser/converts/common.ts index a8c117e7..07bc38ef 100644 --- a/src/parser/converts/common.ts +++ b/src/parser/converts/common.ts @@ -4,7 +4,7 @@ export function indexOf( str: string, search: (c: string, index: number) => boolean, start: number, - end?: number + end?: number, ): number { const endIndex = end ?? str.length; for (let index = start; index < endIndex; index++) { @@ -20,7 +20,7 @@ export function indexOf( export function lastIndexOf( str: string, search: (c: string, index: number) => boolean, - end: number + end: number, ): number { for (let index = end; index >= 0; index--) { const c = str[index]; @@ -32,15 +32,15 @@ export function lastIndexOf( } export function getWithLoc( - node: N + node: N, ): N & { start: number; end: number }; export function getWithLoc< - N extends ESTree.Node | { start: number; end: number } + N extends ESTree.Node | { start: number; end: number }, >(node: N): N & { start: number; end: number }; export function getWithLoc< - N extends ESTree.Node | { start: number; end: number } + N extends ESTree.Node | { start: number; end: number }, >( - node: N | null | undefined + node: N | null | undefined, ): (N & { start: number; end: number }) | null | undefined; /** Get node with location */ diff --git a/src/parser/converts/const.ts b/src/parser/converts/const.ts index 3ffaf17d..9aeea7b6 100644 --- a/src/parser/converts/const.ts +++ b/src/parser/converts/const.ts @@ -6,7 +6,7 @@ import type * as SvAST from "../svelte-ast-types"; export function convertConstTag( node: SvAST.ConstTag, parent: SvelteConstTag["parent"], - ctx: Context + ctx: Context, ): SvelteConstTag { const mustache: SvelteConstTag = { type: "SvelteConstTag", @@ -19,7 +19,7 @@ export function convertConstTag( mustache, (declaration) => { mustache.declaration = declaration; - } + }, ); const atConstStart = ctx.code.indexOf("@const", mustache.range[0]); ctx.addToken("MustacheKeyword", { diff --git a/src/parser/converts/element.ts b/src/parser/converts/element.ts index 99547366..29e94d46 100644 --- a/src/parser/converts/element.ts +++ b/src/parser/converts/element.ts @@ -63,7 +63,7 @@ export function* convertChildren( | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock, - ctx: Context + ctx: Context, ): IterableIterator< | SvelteText | SvelteElement @@ -213,7 +213,7 @@ function needScopeByChildren(fragment: { function convertComment( node: SvAST.Comment, parent: SvelteHTMLComment["parent"], - ctx: Context + ctx: Context, ): SvelteHTMLComment { const comment: SvelteHTMLComment = { type: "SvelteHTMLComment", @@ -231,7 +231,7 @@ function convertComment( function convertHTMLElement( node: SvAST.Element | SvAST.Slot | SvAST.Title, parent: SvelteHTMLElement["parent"], - ctx: Context + ctx: Context, ): SvelteHTMLElement { const locs = ctx.getConvertLocation(node); const element: SvelteHTMLElement = { @@ -265,19 +265,19 @@ function convertHTMLElement( if (letDirectives.length) { ctx.letDirCollections.beginExtract(); element.startTag.attributes.push( - ...convertAttributes(letDirectives, element.startTag, elementName, ctx) + ...convertAttributes(letDirectives, element.startTag, elementName, ctx), ); letParams.push(...ctx.letDirCollections.extract().getLetParams()); } if (!letParams.length && !needScopeByChildren(node)) { element.startTag.attributes.push( - ...convertAttributes(attributes, element.startTag, elementName, ctx) + ...convertAttributes(attributes, element.startTag, elementName, ctx), ); element.children.push(...convertChildren(node, element, ctx)); } else { ctx.scriptLet.nestBlock(element, letParams); element.startTag.attributes.push( - ...convertAttributes(attributes, element.startTag, elementName, ctx) + ...convertAttributes(attributes, element.startTag, elementName, ctx), ); sortNodes(element.startTag.attributes); element.children.push(...convertChildren(node, element, ctx)); @@ -311,7 +311,7 @@ function convertHTMLElement( if (element.name.name === "script") { ctx.stripScriptCode( element.startTag.range[1], - element.endTag?.range[0] ?? element.range[1] + element.endTag?.range[0] ?? element.range[1], ); } } @@ -340,7 +340,7 @@ function convertSpecialElement( | SvAST.Options | SvAST.SlotTemplate, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { const locs = ctx.getConvertLocation(node); const element: SvelteSpecialElement = { @@ -374,19 +374,19 @@ function convertSpecialElement( if (letDirectives.length) { ctx.letDirCollections.beginExtract(); element.startTag.attributes.push( - ...convertAttributes(letDirectives, element.startTag, elementName, ctx) + ...convertAttributes(letDirectives, element.startTag, elementName, ctx), ); letParams.push(...ctx.letDirCollections.extract().getLetParams()); } if (!letParams.length && !needScopeByChildren(node)) { element.startTag.attributes.push( - ...convertAttributes(attributes, element.startTag, elementName, ctx) + ...convertAttributes(attributes, element.startTag, elementName, ctx), ); element.children.push(...convertChildren(node, element, ctx)); } else { ctx.scriptLet.nestBlock(element, letParams); element.startTag.attributes.push( - ...convertAttributes(attributes, element.startTag, elementName, ctx) + ...convertAttributes(attributes, element.startTag, elementName, ctx), ); sortNodes(element.startTag.attributes); element.children.push(...convertChildren(node, element, ctx)); @@ -423,7 +423,7 @@ function processThisAttribute( node: SvAST.SvelteElement | SvAST.InlineSvelteComponent, thisValue: string | ESTree.Expression, element: SvelteSpecialElement, - ctx: Context + ctx: Context, ) { let thisNode: SvelteSpecialDirective | SvelteAttribute; if (typeof thisValue === "string") { @@ -433,7 +433,7 @@ function processThisAttribute( const valueStartIndex = indexOf( ctx.code, (c) => Boolean(c.trim()), - eqIndex + 1 + eqIndex + 1, ); const quote = ctx.code.startsWith(thisValue, valueStartIndex) ? null @@ -503,7 +503,7 @@ function processThisAttribute( const endIndex = indexOf( ctx.code, (c) => c === ">" || !c.trim(), - closeIndex + closeIndex, ); const thisDir: SvelteSpecialDirective = { type: "SvelteSpecialDirective", @@ -535,7 +535,7 @@ function processThisAttribute( } const targetIndex = element.startTag.attributes.findIndex( - (attr) => thisNode.range[1] <= attr.range[0] + (attr) => thisNode.range[1] <= attr.range[0], ); if (targetIndex === -1) { element.startTag.attributes.push(thisNode); @@ -547,7 +547,7 @@ function processThisAttribute( /** Find the start index of `this` */ function findStartIndexOfThis( node: SvAST.SvelteElement | SvAST.InlineSvelteComponent, - ctx: Context + ctx: Context, ) { // Get the end index of `svelte:element` const startIndex = ctx.code.indexOf(node.name, node.start) + node.name.length; @@ -558,7 +558,7 @@ function findStartIndexOfThis( ctx.code, (_c, index) => ctx.code.startsWith("this", index), startIndex, - sortedAttrs[0]?.start ?? node.end + sortedAttrs[0]?.start ?? node.end, ); while (thisIndex < 0) { if (sortedAttrs.length === 0) @@ -570,7 +570,7 @@ function findStartIndexOfThis( ctx.code, (_c, index) => ctx.code.startsWith("this", index), nextStartIndex, - sortedAttrs[0]?.start ?? node.end + sortedAttrs[0]?.start ?? node.end, ); } return thisIndex; @@ -580,7 +580,7 @@ function findStartIndexOfThis( function convertComponentElement( node: SvAST.InlineComponent, parent: SvelteComponentElement["parent"], - ctx: Context + ctx: Context, ): SvelteComponentElement { const locs = ctx.getConvertLocation(node); const element: SvelteComponentElement = { @@ -614,19 +614,19 @@ function convertComponentElement( if (letDirectives.length) { ctx.letDirCollections.beginExtract(); element.startTag.attributes.push( - ...convertAttributes(letDirectives, element.startTag, elementName, ctx) + ...convertAttributes(letDirectives, element.startTag, elementName, ctx), ); letParams.push(...ctx.letDirCollections.extract().getLetParams()); } if (!letParams.length && !needScopeByChildren(node)) { element.startTag.attributes.push( - ...convertAttributes(attributes, element.startTag, elementName, ctx) + ...convertAttributes(attributes, element.startTag, elementName, ctx), ); element.children.push(...convertChildren(node, element, ctx)); } else { ctx.scriptLet.nestBlock(element, letParams); element.startTag.attributes.push( - ...convertAttributes(attributes, element.startTag, elementName, ctx) + ...convertAttributes(attributes, element.startTag, elementName, ctx), ); sortNodes(element.startTag.attributes); element.children.push(...convertChildren(node, element, ctx)); @@ -691,7 +691,7 @@ function convertComponentElement( identifier, (identifier as any).parent, null, - esCallback + esCallback, ); return object; @@ -704,7 +704,7 @@ function convertComponentElement( function convertSlotElement( node: SvAST.Slot, parent: SvelteHTMLElement["parent"], - ctx: Context + ctx: Context, ): SvelteHTMLElement { // Slot translates to SvelteHTMLElement. const element = convertHTMLElement(node, parent, ctx); @@ -716,7 +716,7 @@ function convertSlotElement( function convertWindowElement( node: SvAST.Window, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { return convertSpecialElement(node, parent, ctx); } @@ -725,7 +725,7 @@ function convertWindowElement( function convertDocumentElement( node: SvAST.Document, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { return convertSpecialElement(node, parent, ctx); } @@ -734,7 +734,7 @@ function convertDocumentElement( function convertBodyElement( node: SvAST.Body, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { return convertSpecialElement(node, parent, ctx); } @@ -743,7 +743,7 @@ function convertBodyElement( function convertHeadElement( node: SvAST.Head, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { return convertSpecialElement(node, parent, ctx); } @@ -752,7 +752,7 @@ function convertHeadElement( function convertTitleElement( node: SvAST.Title, parent: SvelteHTMLElement["parent"], - ctx: Context + ctx: Context, ): SvelteHTMLElement { return convertHTMLElement(node, parent, ctx); } @@ -761,7 +761,7 @@ function convertTitleElement( function convertOptionsElement( node: SvAST.Options, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { return convertSpecialElement(node, parent, ctx); } @@ -770,14 +770,14 @@ function convertOptionsElement( function convertSlotTemplateElement( node: SvAST.SlotTemplate, parent: SvelteSpecialElement["parent"], - ctx: Context + ctx: Context, ): SvelteSpecialElement { return convertSpecialElement(node, parent, ctx); } /** Extract element tag and tokens */ export function extractElementTags< - E extends SvelteScriptElement | SvelteElement | SvelteStyleElement + E extends SvelteScriptElement | SvelteElement | SvelteStyleElement, >( element: E, ctx: Context, @@ -787,12 +787,12 @@ export function extractElementTags< end: number; }) => E["name"]; extractAttribute?: boolean; - } + }, ): void { const startTagNameEnd = indexOf( ctx.code, (c) => c === "/" || c === ">" || !c.trim(), - element.range[0] + 1 + element.range[0] + 1, ); const openTokenRange = { start: element.range[0] + 1, @@ -805,7 +805,7 @@ export function extractElementTags< ctx.code.indexOf( ">", element.startTag.attributes[element.startTag.attributes.length - 1] - ?.range[1] ?? openTokenRange.end + ?.range[1] ?? openTokenRange.end, ) + 1; element.startTag.range[1] = startTagEnd; element.startTag.loc.end = ctx.getLocFromIndex(startTagEnd); @@ -829,7 +829,7 @@ export function extractElementTags< const endTagNameEnd = indexOf( ctx.code, (c) => c === ">" || !c.trim(), - endTagNameStart + endTagNameStart, ); const endTagClose = ctx.code.indexOf(">", endTagNameEnd); element.endTag = { diff --git a/src/parser/converts/mustache.ts b/src/parser/converts/mustache.ts index 0b01a93b..d784bf87 100644 --- a/src/parser/converts/mustache.ts +++ b/src/parser/converts/mustache.ts @@ -10,7 +10,7 @@ import type * as SvAST from "../svelte-ast-types"; export function convertMustacheTag( node: SvAST.MustacheTag, parent: SvelteMustacheTag["parent"], - ctx: Context + ctx: Context, ): SvelteMustacheTagText { return convertMustacheTag0(node, "text", parent, ctx); } @@ -18,13 +18,13 @@ export function convertMustacheTag( export function convertRawMustacheTag( node: SvAST.RawMustacheTag, parent: SvelteMustacheTag["parent"], - ctx: Context + ctx: Context, ): SvelteMustacheTagRaw { const mustache: SvelteMustacheTagRaw = convertMustacheTag0( node, "raw", parent, - ctx + ctx, ); const atHtmlStart = ctx.code.indexOf("@html", mustache.range[0]); ctx.addToken("MustacheKeyword", { @@ -38,7 +38,7 @@ export function convertRawMustacheTag( export function convertDebugTag( node: SvAST.DebugTag, parent: SvelteDebugTag["parent"], - ctx: Context + ctx: Context, ): SvelteDebugTag { const mustache: SvelteDebugTag = { type: "SvelteDebugTag", @@ -64,7 +64,7 @@ function convertMustacheTag0( node: SvAST.MustacheTag | SvAST.RawMustacheTag, kind: T["kind"], parent: T["parent"], - ctx: Context + ctx: Context, ): T { const mustache = { type: "SvelteMustacheTag", diff --git a/src/parser/converts/root.ts b/src/parser/converts/root.ts index 500abba6..2426cfb4 100644 --- a/src/parser/converts/root.ts +++ b/src/parser/converts/root.ts @@ -16,7 +16,7 @@ import type { Scope } from "eslint-scope"; */ export function convertSvelteRoot( svelteAst: SvAST.Ast, - ctx: Context + ctx: Context, ): SvelteProgram { const ast: SvelteProgram = { type: "Program", @@ -134,7 +134,7 @@ export function convertSvelteRoot( node, _tokens, _comments, - { scopeManager, registerNodeToScope, addPostProcess } + { scopeManager, registerNodeToScope, addPostProcess }, ) => { const scopes: Scope[] = []; for (const scope of scopeManager.scopes) { @@ -149,7 +149,7 @@ export function convertSvelteRoot( // from Program nodes set to `block` in global scope. This can only be handled by the original Program node. scopeManager.globalScope.block = node; }); - } + }, ); return ast; @@ -158,7 +158,7 @@ export function convertSvelteRoot( /** Extract attrs */ function extractAttributes( element: SvelteScriptElement | SvelteStyleElement, - ctx: Context + ctx: Context, ) { element.startTag = { type: "SvelteStartTag", @@ -177,7 +177,7 @@ function extractAttributes( const block = ctx.findBlock(element); if (block) { element.startTag.attributes.push( - ...convertAttributeTokens(block.attrs, element.startTag, ctx) + ...convertAttributeTokens(block.attrs, element.startTag, ctx), ); } } diff --git a/src/parser/converts/text.ts b/src/parser/converts/text.ts index f8d3973a..89f5d0ad 100644 --- a/src/parser/converts/text.ts +++ b/src/parser/converts/text.ts @@ -6,7 +6,7 @@ import type * as SvAST from "../svelte-ast-types"; export function convertText( node: SvAST.Text, parent: SvelteText["parent"], - ctx: Context + ctx: Context, ): SvelteText { const text: SvelteText = { type: "SvelteText", @@ -22,7 +22,7 @@ export function convertText( export function convertTextToLiteral( node: SvAST.Text, parent: SvelteLiteral["parent"], - ctx: Context + ctx: Context, ): SvelteLiteral { const text: SvelteLiteral = { type: "SvelteLiteral", @@ -38,7 +38,7 @@ export function convertTextToLiteral( export function convertAttributeValueTokenToLiteral( node: AttributeValueToken, parent: SvelteLiteral["parent"], - ctx: Context + ctx: Context, ): SvelteLiteral { const valueLoc = node.quote ? { start: node.start + 1, end: node.end - 1 } @@ -56,7 +56,7 @@ export function convertAttributeValueTokenToLiteral( /** Extract tokens */ function extractTextTokens( node: { start: number; end: number }, - ctx: Context + ctx: Context, ): void { const loc = node; let start = loc.start; diff --git a/src/parser/html.ts b/src/parser/html.ts index ebc9e941..09330f29 100644 --- a/src/parser/html.ts +++ b/src/parser/html.ts @@ -19,7 +19,7 @@ const spacePattern = /\s/; /** Parse HTML attributes */ export function parseAttributes( code: string, - startIndex: number + startIndex: number, ): { attributes: AttributeToken[]; index: number } { const attributes: AttributeToken[] = []; @@ -42,7 +42,7 @@ export function parseAttributes( /** Parse HTML attribute */ function parseAttribute( code: string, - startIndex: number + startIndex: number, ): { attribute: AttributeToken; index: number } { // parse key const keyData = parseAttributeKey(code, startIndex); @@ -85,7 +85,7 @@ function parseAttribute( /** Parse HTML attribute key */ function parseAttributeKey( code: string, - startIndex: number + startIndex: number, ): { key: AttributeKeyToken; index: number } { const key: AttributeKeyToken = { name: code[startIndex], @@ -134,7 +134,7 @@ function parseAttributeKey( /** Parse HTML attribute value */ function parseAttributeValue( code: string, - startIndex: number + startIndex: number, ): { value: AttributeValueToken | null; index: number } { let index = startIndex; const maybeQuote = code[index]; diff --git a/src/parser/index.ts b/src/parser/index.ts index 351deed6..28d5abfe 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -63,7 +63,7 @@ export interface ESLintExtendedProgram { */ export function parseForESLint( code: string, - options?: any + options?: any, ): { ast: SvelteProgram; services: Record & { @@ -95,7 +95,7 @@ export function parseForESLint( const resultTemplate = parseTemplate( ctx.sourceCode.template, ctx, - parserOptions + parserOptions, ); const scripts = ctx.sourceCode.scripts; @@ -104,12 +104,12 @@ export function parseForESLint( scripts.getCurrentVirtualCodeInfo(), scripts.attrs, parserOptions, - { slots: ctx.slots } + { slots: ctx.slots }, ) : parseScript( scripts.getCurrentVirtualCode(), scripts.attrs, - parserOptions + parserOptions, ); ctx.scriptLet.restore(resultScript); ctx.tokens.push(...resultScript.ast.tokens); @@ -148,7 +148,7 @@ export function parseForESLint( ast.sourceType = resultScript.ast.sourceType; const scriptElements = ast.body.filter( - (b): b is SvelteScriptElement => b.type === "SvelteScriptElement" + (b): b is SvelteScriptElement => b.type === "SvelteScriptElement", ); for (let index = 0; index < scriptElements.length; index++) { const body = scriptElements[index]; @@ -172,7 +172,7 @@ export function parseForESLint( attr.key.name === "context" && attr.value.length === 1 && attr.value[0].type === "SvelteLiteral" && - attr.value[0].value === "module" + attr.value[0].value === "module", ) ) { analyzePropsScope(body, resultScript.scopeManager!); @@ -182,12 +182,12 @@ export function parseForESLint( throw new ParseError( "The script is unterminated", statements[0].range![1], - ctx + ctx, ); } const styleElement = ast.body.find( - (b): b is SvelteStyleElement => b.type === "SvelteStyleElement" + (b): b is SvelteStyleElement => b.type === "SvelteStyleElement", ); let styleContext: StyleContext | null = null; @@ -214,7 +214,7 @@ export function parseForESLint( /** Extract tokens */ function extractTokens(ctx: Context) { const useRanges = sortNodes([...ctx.tokens, ...ctx.comments]).map( - (t) => t.range + (t) => t.range, ); let range = useRanges.shift(); for (let index = 0; index < ctx.sourceCode.template.length; index++) { diff --git a/src/parser/parser-object.ts b/src/parser/parser-object.ts index f0bcbf1d..e87df98d 100644 --- a/src/parser/parser-object.ts +++ b/src/parser/parser-object.ts @@ -29,20 +29,20 @@ export function isParserObject(value: unknown): value is ParserObject { } /** Checks whether given object is EnhancedParserObject */ export function isEnhancedParserObject( - value: unknown + value: unknown, ): value is EnhancedParserObject { return Boolean(value && typeof (value as any).parseForESLint === "function"); } /** Checks whether given object is BasicParserObject */ export function isBasicParserObject( - value: unknown + value: unknown, ): value is BasicParserObject { return Boolean(value && typeof (value as any).parse === "function"); } /** Checks whether given object maybe "@typescript-eslint/parser" */ export function maybeTSESLintParserObject( - value: unknown + value: unknown, ): value is TSESLintParser { return ( isEnhancedParserObject(value) && @@ -55,7 +55,7 @@ export function maybeTSESLintParserObject( /** Checks whether given object is "@typescript-eslint/parser" */ export function isTSESLintParserObject( - value: unknown + value: unknown, ): value is TSESLintParser { if (!isEnhancedParserObject(value)) return false; try { @@ -65,7 +65,7 @@ export function isTSESLintParserObject( services && services.esTreeNodeToTSNodeMap && services.tsNodeToESTreeNodeMap && - services.program + services.program, ); } catch { return false; diff --git a/src/parser/resolve-parser.ts b/src/parser/resolve-parser.ts index 3192eed4..3cc2c1dd 100644 --- a/src/parser/resolve-parser.ts +++ b/src/parser/resolve-parser.ts @@ -11,7 +11,7 @@ type UserOptionParser = /** Get parser for script lang */ export function getParserForLang( attrs: Record, - parser: UserOptionParser + parser: UserOptionParser, ): string | ParserObject { if (parser) { if (typeof parser === "string" || isParserObject(parser)) { @@ -30,7 +30,7 @@ export function getParserForLang( /** Get parser */ export function getParser( attrs: Record, - parser: UserOptionParser + parser: UserOptionParser, ): ParserObject { const parserValue = getParserForLang(attrs, parser); if (isParserObject(parserValue)) { diff --git a/src/parser/script.ts b/src/parser/script.ts index 13e3f724..0fedd339 100644 --- a/src/parser/script.ts +++ b/src/parser/script.ts @@ -10,12 +10,12 @@ import { isEnhancedParserObject } from "./parser-object"; export function parseScript( code: string, attrs: Record, - parserOptions: any = {} + parserOptions: any = {}, ): ESLintExtendedProgram { const result = parseScriptWithoutAnalyzeScopeFromVCode( code, attrs, - parserOptions + parserOptions, ); if (!result.scopeManager) { @@ -49,7 +49,7 @@ export function parseScript( export function parseScriptWithoutAnalyzeScope( code: string, attrs: Record, - options: any + options: any, ): ESLintExtendedProgram { const parser = getParser(attrs, options.parser); @@ -69,7 +69,7 @@ export function parseScriptWithoutAnalyzeScope( function parseScriptWithoutAnalyzeScopeFromVCode( code: string, attrs: Record, - options: any + options: any, ): ESLintExtendedProgram { const result = parseScriptWithoutAnalyzeScope(code, attrs, options); result._virtualScriptCode = code; diff --git a/src/parser/sort.ts b/src/parser/sort.ts index ff1919be..a7adba15 100644 --- a/src/parser/sort.ts +++ b/src/parser/sort.ts @@ -2,7 +2,7 @@ * Sort tokens */ export function sortNodes( - tokens: T[] | null | undefined + tokens: T[] | null | undefined, ): T[] { if (!tokens) { return []; diff --git a/src/parser/style-context.ts b/src/parser/style-context.ts index 9df8ff41..3d5daa91 100644 --- a/src/parser/style-context.ts +++ b/src/parser/style-context.ts @@ -37,7 +37,7 @@ export interface StyleContextUnknownLang { */ export function parseStyleContext( styleElement: SvelteStyleElement | undefined, - ctx: Context + ctx: Context, ): StyleContext { if (!styleElement || !styleElement.endTag) { return { status: "no-style-element" }; @@ -66,7 +66,7 @@ export function parseStyleContext( } const styleCode = ctx.code.slice( styleElement.startTag.range[1], - styleElement.endTag.range[0] + styleElement.endTag.range[0], ); try { sourceAst = parseFn(styleCode, { @@ -109,7 +109,7 @@ export function styleNodeLoc(node: Node): Partial { * Extracts a node range (like that of any ESLint node) from a parsed svelte style node. */ export function styleNodeRange( - node: Node + node: Node, ): [number | undefined, number | undefined] { if (node.source === undefined) { return [undefined, undefined]; diff --git a/src/parser/template.ts b/src/parser/template.ts index 0f260aee..d5b4b63a 100644 --- a/src/parser/template.ts +++ b/src/parser/template.ts @@ -13,7 +13,7 @@ import { ParseError } from ".."; export function parseTemplate( code: string, ctx: Context, - parserOptions: any = {} + parserOptions: any = {}, ): { ast: SvelteProgram; svelteAst: SvAST.Ast; diff --git a/src/parser/typescript/analyze/index.ts b/src/parser/typescript/analyze/index.ts index 1eab39f7..805f5a86 100644 --- a/src/parser/typescript/analyze/index.ts +++ b/src/parser/typescript/analyze/index.ts @@ -31,7 +31,7 @@ export function analyzeTypeScript( code: { script: string; render: string }, attrs: Record, parserOptions: any, - context: AnalyzeTypeScriptContext + context: AnalyzeTypeScriptContext, ): VirtualTypeScriptContext { const ctx = new VirtualTypeScriptContext(code.script + code.render); ctx.appendOriginal(/^\s*/u.exec(code.script)![0].length); @@ -43,7 +43,7 @@ export function analyzeTypeScript( ...parserOptions, // Without typings project: null, - } + }, ) as unknown as TSESParseForESLintResult; ctx._beforeResult = result; @@ -65,7 +65,7 @@ export function analyzeTypeScript( */ function analyzeStoreReferenceNames( result: TSESParseForESLintResult, - ctx: VirtualTypeScriptContext + ctx: VirtualTypeScriptContext, ) { const scopeManager = result.scopeManager; const programScope = getProgramScope(scopeManager as ScopeManager); @@ -93,7 +93,7 @@ function analyzeStoreReferenceNames( ? F extends (value: infer V, ...args: any) => any ? V : never -: T;` +: T;`, ); ctx.restoreContext.addRestoreStatementProcess((node, result) => { if ( @@ -117,7 +117,7 @@ function analyzeStoreReferenceNames( for (const nm of maybeStoreRefNames) { const realName = nm.slice(1); ctx.appendVirtualScript( - `declare let ${nm}: ${storeValueTypeName};` + `declare let ${nm}: ${storeValueTypeName};`, ); ctx.restoreContext.addRestoreStatementProcess((node, result) => { if ( @@ -153,34 +153,34 @@ function analyzeStoreReferenceNames( function analyzeDollarDollarVariables( result: TSESParseForESLintResult, ctx: VirtualTypeScriptContext, - slots: Set + slots: Set, ) { const scopeManager = result.scopeManager; if ( scopeManager.globalScope!.through.some( - (reference) => reference.identifier.name === "$$props" + (reference) => reference.identifier.name === "$$props", ) ) { appendDeclareVirtualScript("$$props", `{ [index: string]: any }`); } if ( scopeManager.globalScope!.through.some( - (reference) => reference.identifier.name === "$$restProps" + (reference) => reference.identifier.name === "$$restProps", ) ) { appendDeclareVirtualScript("$$restProps", `{ [index: string]: any }`); } if ( scopeManager.globalScope!.through.some( - (reference) => reference.identifier.name === "$$slots" + (reference) => reference.identifier.name === "$$slots", ) ) { const nameTypes = new Set(); for (const slot of slots) { const nameAttr = slot.startTag.attributes.find( (attr): attr is SvelteAttribute => - attr.type === "SvelteAttribute" && attr.key.name === "name" + attr.type === "SvelteAttribute" && attr.key.name === "name", ); if (!nameAttr || nameAttr.value.length === 0) { nameTypes.add('"default"'); @@ -201,9 +201,9 @@ function analyzeDollarDollarVariables( .map((value) => value.type === "SvelteLiteral" ? value.value.replace(/([$`])/gu, "\\$1") - : "${string}" + : "${string}", ) - .join("")}\`` + .join("")}\``, ); } @@ -211,7 +211,7 @@ function analyzeDollarDollarVariables( "$$slots", `Record<${ nameTypes.size > 0 ? [...nameTypes].join(" | ") : "any" - }, boolean>` + }, boolean>`, ); } @@ -250,11 +250,11 @@ function analyzeDollarDollarVariables( */ function analyzeReactiveScopes( result: TSESParseForESLintResult, - ctx: VirtualTypeScriptContext + ctx: VirtualTypeScriptContext, ) { const scopeManager = result.scopeManager; const throughIds = scopeManager.globalScope!.through.map( - (reference) => reference.identifier + (reference) => reference.identifier, ); for (const statement of result.ast.body) { if (statement.type === "LabeledStatement" && statement.label.name === "$") { @@ -271,7 +271,8 @@ function analyzeReactiveScopes( const left = statement.body.expression.left; if ( throughIds.some( - (id) => left.range[0] <= id.range[0] && id.range[1] <= left.range[1] + (id) => + left.range[0] <= id.range[0] && id.range[1] <= left.range[1], ) ) { transformForDeclareReactiveVar( @@ -279,7 +280,7 @@ function analyzeReactiveScopes( statement.body.expression.left, statement.body.expression, result.ast.tokens!, - ctx + ctx, ); continue; } @@ -295,7 +296,7 @@ function analyzeReactiveScopes( */ function analyzeRenderScopes( code: { script: string; render: string }, - ctx: VirtualTypeScriptContext + ctx: VirtualTypeScriptContext, ) { ctx.appendOriginal(code.script.length); const renderFunctionName = ctx.generateUniqueId("render"); @@ -329,7 +330,7 @@ function transformForDeclareReactiveVar( id: TSESTree.Identifier | TSESTree.ArrayPattern | TSESTree.ObjectPattern, expression: TSESTree.AssignmentExpression, tokens: TSESTree.Token[], - ctx: VirtualTypeScriptContext + ctx: VirtualTypeScriptContext, ): void { // e.g. // From: @@ -373,7 +374,7 @@ function transformForDeclareReactiveVar( let expressionCloseParen: TSESTree.Token | null = null; const startIndex = sortedLastIndex( tokens, - (target) => target.range[0] - statement.range[0] + (target) => target.range[0] - statement.range[0], ); for (let index = startIndex; index < tokens.length; index++) { const token = tokens[index]; @@ -413,7 +414,7 @@ function transformForDeclareReactiveVar( ctx.appendVirtualScript("let "); ctx.appendOriginal(eq ? eq.range[1] : expression.right.range[0]); ctx.appendVirtualScript( - `${functionId}();\nfunction ${functionId}(){let ${tmpVarId};return (${tmpVarId} = ` + `${functionId}();\nfunction ${functionId}(){let ${tmpVarId};return (${tmpVarId} = `, ); ctx.appendOriginal(expression.right.range[1]); ctx.appendVirtualScript(`)`); @@ -519,7 +520,7 @@ function transformForDeclareReactiveVar( addElementsToSortedArray( program.tokens!, [...openParens, ...closeParens], - (a, b) => a.range[0] - b.range[0] + (a, b) => a.range[0] - b.range[0], ); const scopeManager = result.scopeManager as ScopeManager; @@ -548,7 +549,7 @@ function transformForDeclareReactiveVar( */ function transformForReactiveStatement( statement: TSESTree.LabeledStatement, - ctx: VirtualTypeScriptContext + ctx: VirtualTypeScriptContext, ) { const functionId = ctx.generateUniqueId("reactiveStatementScopeFunction"); const originalBody = statement.body; @@ -582,7 +583,7 @@ function removeFunctionScope( | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression, - scopeManager: ScopeManager + scopeManager: ScopeManager, ) { const scope = scopeManager.acquire(node)!; const upper = scope.upper!; @@ -604,12 +605,12 @@ function removeFunctionScope( addElementsToSortedArray( upperVariable.identifiers, variable.identifiers, - (a, b) => a.range![0] - b.range![0] + (a, b) => a.range![0] - b.range![0], ); addElementsToSortedArray( upperVariable.defs, variable.defs, - (a, b) => a.node.range![0] - b.node.range![0] + (a, b) => a.node.range![0] - b.node.range![0], ); addAllReferences(upperVariable.references, variable.references); } else { diff --git a/src/parser/typescript/index.ts b/src/parser/typescript/index.ts index afe042f8..13b669e1 100644 --- a/src/parser/typescript/index.ts +++ b/src/parser/typescript/index.ts @@ -11,7 +11,7 @@ export function parseTypeScript( code: { script: string; render: string }, attrs: Record, parserOptions: unknown, - context: AnalyzeTypeScriptContext + context: AnalyzeTypeScriptContext, ): ESLintExtendedProgram { const tsCtx = analyzeTypeScript(code, attrs, parserOptions, context); diff --git a/src/parser/typescript/restore.ts b/src/parser/typescript/restore.ts index e66957e3..cc3c8951 100644 --- a/src/parser/typescript/restore.ts +++ b/src/parser/typescript/restore.ts @@ -15,7 +15,7 @@ import type { TSESParseForESLintResult } from "./types"; */ type RestoreStatementProcess = ( node: TSESTree.Statement, - result: TSESParseForESLintResult + result: TSESParseForESLintResult, ) => boolean; export class RestoreContext { @@ -56,7 +56,7 @@ export class RestoreContext { remapLocation: (n) => this.remapLocation(n), removeToken: (token) => this.virtualFragments.some( - (f) => f.start <= token.range[0] && token.range[1] <= f.end + (f) => f.start <= token.range[0] && token.range[1] <= f.end, ), }); @@ -66,7 +66,7 @@ export class RestoreContext { const firstOffset = Math.min( ...[result.ast.body[0], result.ast.tokens?.[0], result.ast.comments?.[0]] .filter((t): t is NonNullable => Boolean(t)) - .map((t) => t.range[0]) + .map((t) => t.range[0]), ); if (firstOffset < result.ast.range[0]) { result.ast.range[0] = firstOffset; @@ -77,13 +77,13 @@ export class RestoreContext { private remapLocation(node: TSESTree.Node | TSESTree.Token): void { let [start, end] = node.range; const startFragment = this.virtualFragments.find( - (f) => f.start <= start && start < f.end + (f) => f.start <= start && start < f.end, ); if (startFragment) { start = startFragment.end; } const endFragment = this.virtualFragments.find( - (f) => f.start < end && end <= f.end + (f) => f.start < end && end <= f.end, ); if (endFragment) { end = endFragment.start; @@ -99,7 +99,7 @@ export class RestoreContext { } const locs = this.originalLocs.getLocations( - ...this.getRemapRange(start, end) + ...this.getRemapRange(start, end), ); node.loc = locs.loc; @@ -145,7 +145,7 @@ function remapLocations( }: { remapLocation: (node: TSESTree.Node | TSESTree.Token) => void; removeToken: (node: TSESTree.Token) => boolean; - } + }, ) { const traversed = new Map(); // remap locations @@ -179,7 +179,7 @@ function remapLocations( /** Restore statement nodes */ function restoreStatements( result: TSESParseForESLintResult, - restoreStatementProcesses: RestoreStatementProcess[] + restoreStatementProcesses: RestoreStatementProcess[], ) { const restoreStatementProcessesSet = new Set(restoreStatementProcesses); for (const node of [...result.ast.body]) { diff --git a/src/scope/index.ts b/src/scope/index.ts index f1022230..ccbb2c47 100644 --- a/src/scope/index.ts +++ b/src/scope/index.ts @@ -14,7 +14,7 @@ export function removeAllScopeAndVariableAndReference( readonly [type: string]: readonly string[] | undefined; }; scopeManager: ScopeManager; - } + }, ): void { const targetScopes = new Set(); traverseNodes(target, { @@ -58,7 +58,7 @@ export function removeAllScopeAndVariableAndReference( */ export function getScopeFromNode( scopeManager: ScopeManager, - currentNode: ESTree.Node + currentNode: ESTree.Node, ): Scope { let node: ESTree.Node | null = currentNode; for (; node; node = (node as any).parent || null) { @@ -99,7 +99,7 @@ export function removeIdentifierVariable( | TSESTree.BindingName | TSESTree.RestElement | TSESTree.DestructuringPattern, - scope: Scope + scope: Scope, ): void { if (node.type === "ObjectPattern") { for (const prop of node.properties) { @@ -168,7 +168,7 @@ export function* getAllReferences( | TSESTree.BindingName | TSESTree.RestElement | TSESTree.DestructuringPattern, - scope: Scope + scope: Scope, ): Iterable { if (node.type === "ObjectPattern") { for (const prop of node.properties) { @@ -209,7 +209,7 @@ export function* getAllReferences( /** Remove reference */ export function removeIdentifierReference( node: ESTree.Identifier, - scope: Scope + scope: Scope, ): boolean { const reference = scope.references.find((ref) => ref.identifier === node); if (reference) { @@ -307,7 +307,7 @@ export function removeScope(scopeManager: ScopeManager, scope: Scope): void { export function replaceScope( scopeManager: ScopeManager, scope: Scope, - newChildScopes: Scope[] = [] + newChildScopes: Scope[] = [], ): void { // remove scope from scopeManager scopeManager.scopes = scopeManager.scopes.filter((s) => s !== scope); @@ -318,7 +318,7 @@ export function replaceScope( upper.childScopes.splice( upper.childScopes.indexOf(scope), 1, - ...newChildScopes + ...newChildScopes, ); for (const child of newChildScopes) { child.upper = upper; @@ -359,7 +359,7 @@ export function addReference(list: Reference[], reference: Reference): void { addElementToSortedArray( list, reference, - (a, b) => a.identifier.range![0] - b.identifier.range![0] + (a, b) => a.identifier.range![0] - b.identifier.range![0], ); } /** @@ -367,12 +367,12 @@ export function addReference(list: Reference[], reference: Reference): void { */ export function addAllReferences( list: Reference[], - elements: Reference[] + elements: Reference[], ): void { addElementsToSortedArray( list, elements, - (a, b) => a.identifier.range![0] - b.identifier.range![0] + (a, b) => a.identifier.range![0] - b.identifier.range![0], ); } @@ -409,7 +409,7 @@ function simplifyVariables(variables: Variable[]) { { loc: JSON.stringify(v.defs[0]?.node.loc), }, - ]) + ]), ); } diff --git a/src/traverse.ts b/src/traverse.ts index 82d35cc8..c801694b 100644 --- a/src/traverse.ts +++ b/src/traverse.ts @@ -43,7 +43,7 @@ export function getFallbackKeys(node: any): string[] { */ export function getKeys( node: any, - visitorKeys?: VisitorKeys | TSESVisitorKeys + visitorKeys?: VisitorKeys | TSESVisitorKeys, ): string[] { const keys = (visitorKeys || KEYS)[node.type] || getFallbackKeys(node); @@ -56,7 +56,7 @@ export function getKeys( */ export function* getNodes( node: any, - key: string + key: string, ): IterableIterator { const child = node[key]; if (Array.isArray(child)) { @@ -88,7 +88,7 @@ function isNode(x: any): x is SvelteNode { function traverse( node: N, parent: N | null, - visitor: Visitor + visitor: Visitor, ): void { visitor.enterNode(node, parent); @@ -114,19 +114,19 @@ export interface Visitor { export function traverseNodes( node: SvelteNode, - visitor: Visitor + visitor: Visitor, ): void; export function traverseNodes( node: ESTree.Node, - visitor: Visitor + visitor: Visitor, ): void; export function traverseNodes( node: TSESTree.Node, - visitor: Visitor + visitor: Visitor, ): void; export function traverseNodes( node: ESTree.Node | TSESTree.Node, - visitor: Visitor + visitor: Visitor, ): void; /** * Traverse the given AST tree. @@ -135,7 +135,7 @@ export function traverseNodes( */ export function traverseNodes( node: ESTree.Node | SvelteNode | TSESTree.Node, - visitor: Visitor + visitor: Visitor, ): void { traverse(node, null, visitor); } diff --git a/src/utils/index.ts b/src/utils/index.ts index f4e967ee..bfbbf380 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -4,7 +4,7 @@ export function addElementToSortedArray( array: T[], element: T, - compare: (a: T, b: T) => number + compare: (a: T, b: T) => number, ): void { const index = sortedLastIndex(array, (target) => compare(target, element)); array.splice(index, 0, element); @@ -16,7 +16,7 @@ export function addElementToSortedArray( export function addElementsToSortedArray( array: T[], elements: T[], - compare: (a: T, b: T) => number + compare: (a: T, b: T) => number, ): void { if (!elements.length) { return; @@ -40,7 +40,7 @@ export function addElementsToSortedArray( */ export function sortedLastIndex( array: T[], - compare: (target: T) => number + compare: (target: T) => number, ): number { let lower = 0; let upper = array.length; diff --git a/src/visitor-keys.ts b/src/visitor-keys.ts index c7da1c92..d9a02cef 100644 --- a/src/visitor-keys.ts +++ b/src/visitor-keys.ts @@ -51,5 +51,5 @@ const svelteKeys: SvelteKeysType = { }; export const KEYS: SourceCode.VisitorKeys = unionWith( - svelteKeys + svelteKeys, ) as SourceCode.VisitorKeys; diff --git a/tests/fixtures/integrations/scope-tests/ts-scope01-setup.ts b/tests/fixtures/integrations/scope-tests/ts-scope01-setup.ts index d546b48c..4f85b241 100644 --- a/tests/fixtures/integrations/scope-tests/ts-scope01-setup.ts +++ b/tests/fixtures/integrations/scope-tests/ts-scope01-setup.ts @@ -5,7 +5,7 @@ import { rules } from "eslint-plugin-svelte"; export function setupLinter(linter: Linter) { linter.defineRule( "svelte/no-immutable-reactive-statements", - rules["no-immutable-reactive-statements"] as never + rules["no-immutable-reactive-statements"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/await-setup.ts b/tests/fixtures/integrations/type-info-tests/await-setup.ts index 85e17fa3..d1038fe0 100644 --- a/tests/fixtures/integrations/type-info-tests/await-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/await-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unsafe-call", - rules["no-unsafe-call"] as never + rules["no-unsafe-call"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts b/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts index de06e86a..43276b18 100644 --- a/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/await-with-same-id-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unsafe-member-access", - rules["no-unsafe-member-access"] as never + rules["no-unsafe-member-access"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/i18n-setup.ts b/tests/fixtures/integrations/type-info-tests/i18n-setup.ts index 85e17fa3..d1038fe0 100644 --- a/tests/fixtures/integrations/type-info-tests/i18n-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/i18n-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unsafe-call", - rules["no-unsafe-call"] as never + rules["no-unsafe-call"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/issue226-setup.ts b/tests/fixtures/integrations/type-info-tests/issue226-setup.ts index a0a6ab4d..b3c17593 100644 --- a/tests/fixtures/integrations/type-info-tests/issue226-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/issue226-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unsafe-argument", - rules["no-unsafe-argument"] as never + rules["no-unsafe-argument"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts b/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts index e8992371..640da051 100644 --- a/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/no-unnecessary-condition01-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unnecessary-condition", - rules["no-unnecessary-condition"] as never + rules["no-unnecessary-condition"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts b/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts index e8992371..640da051 100644 --- a/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/plugin-issue254-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unnecessary-condition", - rules["no-unnecessary-condition"] as never + rules["no-unnecessary-condition"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/reactive-setup.ts b/tests/fixtures/integrations/type-info-tests/reactive-setup.ts index 77be6301..ecf35dd1 100644 --- a/tests/fixtures/integrations/type-info-tests/reactive-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/reactive-setup.ts @@ -5,23 +5,23 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unsafe-argument", - rules["no-unsafe-argument"] as never + rules["no-unsafe-argument"] as never, ); linter.defineRule( "@typescript-eslint/no-unsafe-assignment", - rules["no-unsafe-assignment"] as never + rules["no-unsafe-assignment"] as never, ); linter.defineRule( "@typescript-eslint/no-unsafe-call", - rules["no-unsafe-call"] as never + rules["no-unsafe-call"] as never, ); linter.defineRule( "@typescript-eslint/no-unsafe-member-access", - rules["no-unsafe-member-access"] as never + rules["no-unsafe-member-access"] as never, ); linter.defineRule( "@typescript-eslint/no-unsafe-return", - rules["no-unsafe-return"] as never + rules["no-unsafe-return"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts b/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts index a57b3284..93fee4aa 100644 --- a/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/reactive2-setup.ts @@ -5,11 +5,11 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-unsafe-assignment", - rules["no-unsafe-assignment"] as never + rules["no-unsafe-assignment"] as never, ); linter.defineRule( "@typescript-eslint/no-unsafe-member-access", - rules["no-unsafe-member-access"] as never + rules["no-unsafe-member-access"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts b/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts index d7426cf1..edeef56f 100644 --- a/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/ts-newline-setup.ts @@ -5,11 +5,11 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-confusing-void-expression", - rules["no-confusing-void-expression"] as never + rules["no-confusing-void-expression"] as never, ); linter.defineRule( "@typescript-eslint/explicit-function-return-type", - rules["explicit-function-return-type"] as never + rules["explicit-function-return-type"] as never, ); } diff --git a/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts b/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts index f4f435fe..6e8c0fd0 100644 --- a/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts +++ b/tests/fixtures/integrations/type-info-tests/ts-no-misused-promises-setup.ts @@ -5,7 +5,7 @@ import { rules } from "@typescript-eslint/eslint-plugin"; export function setupLinter(linter: Linter) { linter.defineRule( "@typescript-eslint/no-misused-promises", - rules["no-misused-promises"] as never + rules["no-misused-promises"] as never, ); } diff --git a/tests/src/integrations.ts b/tests/src/integrations.ts index bfbf6f3f..23ce1992 100644 --- a/tests/src/integrations.ts +++ b/tests/src/integrations.ts @@ -22,12 +22,12 @@ function createLinter() { describe("Integration tests.", () => { for (const { input, inputFileName, outputFileName, config } of listupFixtures( - FIXTURE_ROOT + FIXTURE_ROOT, )) { it(inputFileName, () => { const setupFileName = inputFileName.replace( /input\.svelte$/u, - "setup.ts" + "setup.ts", ); const setup = fs.existsSync(setupFileName) ? // eslint-disable-next-line @typescript-eslint/no-require-imports -- test @@ -45,7 +45,7 @@ describe("Integration tests.", () => { es2021: true, }, }, - inputFileName + inputFileName, ); const messagesJson = JSON.stringify( messages.map((m) => { @@ -55,7 +55,7 @@ describe("Integration tests.", () => { }; }), null, - 2 + 2, ); if (fs.existsSync(outputFileName)) { diff --git a/tests/src/parser/error.ts b/tests/src/parser/error.ts index 90ebca94..242b13ef 100644 --- a/tests/src/parser/error.ts +++ b/tests/src/parser/error.ts @@ -11,7 +11,7 @@ import path from "path"; const ERROR_FIXTURE_ROOT = path.resolve( __dirname, - "../../fixtures/parser/error" + "../../fixtures/parser/error", ); function parse(code: string, filePath: string, config: any) { diff --git a/tests/src/parser/eslint-rules.ts b/tests/src/parser/eslint-rules.ts index 2fe6e67c..791b5f2d 100644 --- a/tests/src/parser/eslint-rules.ts +++ b/tests/src/parser/eslint-rules.ts @@ -60,14 +60,14 @@ describe("svelte-eslint-parser with ESLint rules", () => { es2021: true, }, }, - inputFileName + inputFileName, ); if (messages.length === 0) { assert.strictEqual( fs.existsSync(outputFileName), false, - "Expected empty messages" + "Expected empty messages", ); } else { const messagesJson = JSON.stringify( @@ -75,7 +75,7 @@ describe("svelte-eslint-parser with ESLint rules", () => { return getMessageData(input, m); }), null, - 2 + 2, ); const output = fs.readFileSync(outputFileName, "utf8"); assert.strictEqual(messagesJson, output); diff --git a/tests/src/parser/eslint.ts b/tests/src/parser/eslint.ts index fed4fe58..4025c519 100644 --- a/tests/src/parser/eslint.ts +++ b/tests/src/parser/eslint.ts @@ -222,7 +222,7 @@ describe("eslint custom parser", () => { ...(semver.satisfies( // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- ignore require("eslint/package.json").version, - ">=8.0.0" + ">=8.0.0", ) ? [ { @@ -269,7 +269,7 @@ describe("eslint custom parser", () => { column: m.column, }; }), - messages + messages, ); assert.strictEqual(result.output, output ?? code); diff --git a/tests/src/parser/parser.ts b/tests/src/parser/parser.ts index 02e11167..ba8a5646 100644 --- a/tests/src/parser/parser.ts +++ b/tests/src/parser/parser.ts @@ -99,7 +99,7 @@ function checkTokens(ast: SvelteProgram, input: string) { .replace(/\s/gu, "") .split(/(.{0,20})/) .filter((s) => s) - .join("\n") + .join("\n"), ); function getText(token: Token | Comment) { @@ -115,13 +115,13 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { for (const token of ast.tokens) { assert.ok( token.range[0] < token.range[1], - `No range on "${token.type} line:${token.loc.start.line} col:${token.loc.start.column}" in ${fileName}` + `No range on "${token.type} line:${token.loc.start.line} col:${token.loc.start.column}" in ${fileName}`, ); } for (const token of ast.comments) { assert.ok( token.range[0] < token.range[1], - `No range on "${token.type} line:${token.loc.start.line} col:${token.loc.start.column}" in ${fileName}` + `No range on "${token.type} line:${token.loc.start.line} col:${token.loc.start.column}" in ${fileName}`, ); } const set = new Set(); @@ -132,35 +132,32 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { set.has(node) ) { assert.fail( - `Duplicate node @parent: ${parent?.type}, ${astToJson(node)}` + `Duplicate node @parent: ${parent?.type}, ${astToJson(node)}`, ); } set.add(node); if (parent?.type.startsWith("Svelte")) { assert.ok( (node as any).parent?.type === parent?.type, - `Parent type mismatch [${(node as any).parent?.type} : ${ - parent?.type - }] @${astToJson(node)}` + `Parent type mismatch [${(node as any).parent + ?.type} : ${parent?.type}] @${astToJson(node)}`, ); } assert.ok( (node as any).parent?.range?.[0] === parent?.range![0], - `Parent range mismatch [${(node as any).parent?.range?.[0]} : ${ - parent?.range![0] - }] @${astToJson(node)}` + `Parent range mismatch [${(node as any).parent + ?.range?.[0]} : ${parent?.range![0]}] @${astToJson(node)}`, ); assert.ok( (node as any).parent?.range?.[1] === parent?.range![1], - `Parent range mismatch [${(node as any).parent?.range?.[1]} : ${ - parent?.range![1] - }] @${astToJson(node)}` + `Parent range mismatch [${(node as any).parent + ?.range?.[1]} : ${parent?.range![1]}] @${astToJson(node)}`, ); assert.ok( node.range![0] < node.range![1], `No range on "${node.type} line:${node.loc!.start.line} col:${ node.loc!.start.column - }" in ${fileName}` + }" in ${fileName}`, ); if (parent) { @@ -170,7 +167,7 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { parent.loc!.start.line } col:${parent.loc!.start.column}" > "${node.type} line:${ node.loc!.start.line - } col:${node.loc!.start.column}" in ${fileName}` + } col:${node.loc!.start.column}" in ${fileName}`, ); assert.ok( node.range![1] <= parent.range![1], @@ -178,7 +175,7 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { parent.loc!.end.line } col:${parent.loc!.end.column}" > "${node.type} line:${ node.loc!.end.line - } col:${node.loc!.end.column}" in ${fileName}` + } col:${node.loc!.end.column}" in ${fileName}`, ); assert.ok( @@ -187,7 +184,7 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { parent.loc!.start.line } col:${parent.loc!.start.column}" > "${node.type} line:${ node.loc!.start.line - } col:${node.loc!.start.column}" in ${fileName}` + } col:${node.loc!.start.column}" in ${fileName}`, ); if (parent.loc!.start.line === node.loc!.start.line) { assert.ok( @@ -196,7 +193,7 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { parent.loc!.start.line } col:${parent.loc!.start.column}" > "${node.type} line:${ node.loc!.start.line - } col:${node.loc!.start.column}" in ${fileName}` + } col:${node.loc!.start.column}" in ${fileName}`, ); } @@ -206,7 +203,7 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { parent.loc!.end.line } col:${parent.loc!.end.column}" > "${node.type} line:${ node.loc!.end.line - } col:${node.loc!.end.column}" in ${fileName}` + } col:${node.loc!.end.column}" in ${fileName}`, ); if (parent.loc!.end.line === node.loc!.end.line) { assert.ok( @@ -215,7 +212,7 @@ function checkLoc(ast: SvelteProgram, fileName: string, code: string) { parent.loc!.end.line } col:${parent.loc!.end.column}" > "${node.type} line:${ node.loc!.end.line - } col:${node.loc!.end.column}" in ${fileName}` + } col:${node.loc!.end.column}" in ${fileName}`, ); } } diff --git a/tests/src/parser/style-context.ts b/tests/src/parser/style-context.ts index 157e3539..f4e96d37 100644 --- a/tests/src/parser/style-context.ts +++ b/tests/src/parser/style-context.ts @@ -8,7 +8,7 @@ import { generateParserOptions, listupFixtures } from "./test-utils"; const STYLE_CONTEXT_FIXTURE_ROOT = path.resolve( __dirname, - "../../fixtures/parser/style-context" + "../../fixtures/parser/style-context", ); function parse(code: string, filePath: string, config: any) { diff --git a/tests/src/parser/style-location-coverter.ts b/tests/src/parser/style-location-coverter.ts index 361aa507..95482868 100644 --- a/tests/src/parser/style-location-coverter.ts +++ b/tests/src/parser/style-location-coverter.ts @@ -9,7 +9,7 @@ import { generateParserOptions, listupFixtures } from "./test-utils"; const STYLE_CONTEXT_FIXTURE_ROOT = path.resolve( __dirname, - "../../fixtures/parser/style-location-converter" + "../../fixtures/parser/style-location-converter", ); function parse(code: string, filePath: string, config: any) { @@ -36,7 +36,7 @@ describe("Check for AST.", () => { assert.strictEqual(styleContext.status, "success"); const locations: [ Partial, - [number | undefined, number | undefined] + [number | undefined, number | undefined], ][] = [ [ services.styleNodeLoc(styleContext.sourceAst), @@ -52,7 +52,7 @@ describe("Check for AST.", () => { const output = fs.readFileSync(outputFileName, "utf8"); assert.strictEqual( `${JSON.stringify(locations, undefined, 2)}\n`, - output + output, ); }); }); diff --git a/tests/src/parser/test-utils.ts b/tests/src/parser/test-utils.ts index b5336b37..7ce3fd9d 100644 --- a/tests/src/parser/test-utils.ts +++ b/tests/src/parser/test-utils.ts @@ -61,23 +61,23 @@ function* listupFixturesImpl(dir: string): Iterable<{ if (filename.endsWith("input.svelte")) { const outputFileName = inputFileName.replace( /input\.svelte$/u, - "output.json" + "output.json", ); const scopeFileName = inputFileName.replace( /input\.svelte$/u, - "scope-output.json" + "scope-output.json", ); const typeFileName = inputFileName.replace( /input\.svelte$/u, - "type-output.svelte" + "type-output.svelte", ); const configFileName = inputFileName.replace( /input\.svelte$/u, - "config.json" + "config.json", ); const requirementsFileName = inputFileName.replace( /input\.svelte$/u, - "requirements.json" + "requirements.json", ); const input = fs.readFileSync(inputFileName, "utf8"); @@ -98,7 +98,7 @@ function* listupFixturesImpl(dir: string): Iterable<{ getRuleOutputFileName: (ruleName) => { return inputFileName.replace( /input\.svelte$/u, - `${ruleName}-result.json` + `${ruleName}-result.json`, ); }, meetRequirements(key) { @@ -129,7 +129,7 @@ function* listupFixturesImpl(dir: string): Iterable<{ export function getMessageData( code: string, - message: Linter.LintMessage + message: Linter.LintMessage, ): { ruleId: string | null; code: string; @@ -174,7 +174,7 @@ export function astToJson(node: any): string { export function scopeToJSON( scopeManager: ScopeManager | TSESScopes.ScopeManager, - option?: { skipGlobalScope?: boolean } + option?: { skipGlobalScope?: boolean }, ): string { const globalScope = scopeManager.globalScope!; let scopeData; @@ -218,7 +218,7 @@ function normalizeReference(reference: Reference | TSESScopes.Reference) { } function normalizeDef( - reference: ESLintScope.Definition | TSESScopes.Definition + reference: ESLintScope.Definition | TSESScopes.Definition, ) { return { type: reference.type, @@ -347,7 +347,7 @@ function normalizeObject(value: any) { let entries = Object.entries(value); if (isNode) { entries = entries.filter( - ([k]) => k !== "parent" && k !== "start" && k !== "end" + ([k]) => k !== "parent" && k !== "start" && k !== "end", ); } const nodeType: string | null = isNode ? value.type : null; @@ -361,6 +361,6 @@ function normalizeObject(value: any) { return c; } return a < b ? -1 : a > b ? 1 : 0; - }) + }), ); } diff --git a/tests/src/parser/typescript/assert-result.ts b/tests/src/parser/typescript/assert-result.ts index 25e01069..30269bc5 100644 --- a/tests/src/parser/typescript/assert-result.ts +++ b/tests/src/parser/typescript/assert-result.ts @@ -3,7 +3,7 @@ export function assertResult( aRoot: unknown, bRoot: unknown, - _info: any + _info: any, ): boolean { const buffers = new Set([{ a: aRoot, b: bRoot, path: "$" }]); const pairs = new Map(); @@ -18,7 +18,7 @@ export function assertResult( if (a == null || b == null) { throw error( path, - `Not equal at ${path}: ${toDebugString(a)} !== ${toDebugString(b)}` + `Not equal at ${path}: ${toDebugString(a)} !== ${toDebugString(b)}`, ); } if (typeof a === "function" && typeof b === "function") { @@ -28,7 +28,7 @@ export function assertResult( if (typeof a !== "object" || typeof b !== "object") { throw error( path, - `Not equal at ${path}: ${toDebugString(a)} !== ${toDebugString(b)}` + `Not equal at ${path}: ${toDebugString(a)} !== ${toDebugString(b)}`, ); } if (pairs.get(a) === b) { @@ -41,7 +41,7 @@ export function assertResult( throw error( path, `Not equal array length at ${path}: ${a.length} !== ${b.length} - ${toDebugString(a)} !== ${toDebugString(b)}` + ${toDebugString(a)} !== ${toDebugString(b)}`, ); } const len = Math.max(a.length, b.length); @@ -68,8 +68,8 @@ export function assertResult( throw error( path, `Not equal keys at ${path}.${key}: ${toDebugString( - key - )} !== undefined` + key, + )} !== undefined`, ); } } @@ -77,10 +77,10 @@ export function assertResult( } const aKeys = Object.getOwnPropertyNames(a).filter( - (key) => !ignoreKey(key) + (key) => !ignoreKey(key), ); const bKeys = Object.getOwnPropertyNames(b).filter( - (key) => !ignoreKey(key) + (key) => !ignoreKey(key), ); const keys = new Set([...aKeys, ...bKeys]); for (const key of keys) { @@ -143,7 +143,7 @@ function toDebugString(o: unknown): string { circular.add(value); return normalize(value); }, - 2 + 2, ); /** Normalize */ diff --git a/tests/src/parser/typescript/index.ts b/tests/src/parser/typescript/index.ts index 68222903..2b6489e2 100644 --- a/tests/src/parser/typescript/index.ts +++ b/tests/src/parser/typescript/index.ts @@ -45,7 +45,7 @@ describe("Check for typescript analyze result.", () => { const result = parseScript( code.script + code.render, attrs, - parserOptions + parserOptions, ); const info = { code: code.script + code.render, diff --git a/tests/src/scope/scope.ts b/tests/src/scope/scope.ts index 89ae82fb..4b8c4397 100644 --- a/tests/src/scope/scope.ts +++ b/tests/src/scope/scope.ts @@ -39,7 +39,7 @@ describe("context.getScope", () => { generateScopeTestCase( '', "ImportDeclaration", - "module" + "module", ); }); @@ -47,7 +47,7 @@ describe("context.getScope", () => { generateScopeTestCase( "", "LogicalExpression", - "module" + "module", ); }); @@ -55,7 +55,7 @@ describe("context.getScope", () => { generateScopeTestCase( "", "FunctionDeclaration", - "function" + "function", ); }); @@ -63,7 +63,7 @@ describe("context.getScope", () => { generateScopeTestCase( "", "ArrowFunctionExpression", - "function" + "function", ); }); @@ -71,7 +71,7 @@ describe("context.getScope", () => { generateScopeTestCase( "", "ExpressionStatement", - "function" + "function", ); }); }); diff --git a/tools/lib/changesets-util.ts b/tools/lib/changesets-util.ts index 11cdab28..709fbead 100644 --- a/tools/lib/changesets-util.ts +++ b/tools/lib/changesets-util.ts @@ -6,6 +6,6 @@ export async function getNewVersion(): Promise { const releasePlan = await getReleasePlan(path.resolve(__dirname, "../..")); return releasePlan.releases.find( - ({ name }) => name === "svelte-eslint-parser" + ({ name }) => name === "svelte-eslint-parser", )!.newVersion; } diff --git a/tools/update-fixtures.ts b/tools/update-fixtures.ts index 989df403..b3ad86a0 100644 --- a/tools/update-fixtures.ts +++ b/tools/update-fixtures.ts @@ -17,7 +17,7 @@ import * as tsESLintParser from "@typescript-eslint/parser"; const ERROR_FIXTURE_ROOT = path.resolve( __dirname, - "../tests/fixtures/parser/error" + "../tests/fixtures/parser/error", ); const RULES = [ @@ -45,7 +45,7 @@ function parse(code: string, filePath: string, config: any) { // Clear type info cache tsESLintParser.parseForESLint( "", - generateParserOptions({ filePath: beforeFilePath }, config) + generateParserOptions({ filePath: beforeFilePath }, config), ); } @@ -97,7 +97,7 @@ for (const { es2021: true, }, }, - inputFileName + inputFileName, ); if (messages.length === 0) { @@ -108,7 +108,7 @@ for (const { return getMessageData(input, m); }), null, - 2 + 2, ); fs.writeFileSync(ruleOutputFileName, messagesJson, "utf8"); } @@ -116,7 +116,7 @@ for (const { } for (const { input, inputFileName, outputFileName, config } of listupFixtures( - ERROR_FIXTURE_ROOT + ERROR_FIXTURE_ROOT, )) { // eslint-disable-next-line no-console -- ignore console.log(inputFileName); @@ -144,7 +144,7 @@ function buildTypes( ast: parser.AST.SvelteProgram; services: Record; visitorKeys: { [type: string]: string[] }; - } + }, ): string { const scriptLineRange: [number, number][] = []; parser.traverseNodes(result.ast, { @@ -187,8 +187,8 @@ function buildTypes( { type: node.type, loc: node.loc, - } - )}` + }, + )}`, ); } const type = checker.getTypeAtLocation(tsNode); @@ -198,7 +198,9 @@ function buildTypes( lineTypes.push(`${node.name}: ${typeText}`); } else { lineTypes.push( - `${input.slice(...node.range!).replace(/\s*\n\s*/gu, " ")}: ${typeText}` + `${input + .slice(...node.range!) + .replace(/\s*\n\s*/gu, " ")}: ${typeText}`, ); } } diff --git a/tools/update-meta.ts b/tools/update-meta.ts index 8fa671ab..ad11a74e 100644 --- a/tools/update-meta.ts +++ b/tools/update-meta.ts @@ -23,7 +23,7 @@ async function main() { export const name = ${JSON.stringify(name)} as const; export const version = ${JSON.stringify(await getVersion())} as const; `, - { filePath: META_PATH } + { filePath: META_PATH }, ); fs.writeFileSync(META_PATH, result.output!); }