From 595a79665ac8f15e905c9b67cef24a63b68ca17e Mon Sep 17 00:00:00 2001 From: adjsky Date: Thu, 31 Oct 2024 18:48:34 +0300 Subject: [PATCH] format --- .vscode/settings.json | 10 +- core/build_npm.ts | 48 +-- deno.json | 28 +- eslint-plugin/README.md | 28 +- eslint-plugin/build_npm.ts | 62 ++-- eslint-plugin/deno.json | 22 +- eslint-plugin/mod.ts | 38 +-- eslint-plugin/rules/must_use_result.ts | 232 +++++++-------- eslint-plugin/rules/must_use_result_test.ts | 306 ++++++++++---------- eslint-plugin/test/fixture/tsconfig.json | 8 +- eslint-plugin/test/helpers.ts | 22 +- 11 files changed, 402 insertions(+), 402 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 16e8af3..404d1c7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { - "deno.enable": true, - "editor.defaultFormatter": "denoland.vscode-deno", - "[ignore]": { - "editor.defaultFormatter": "foxundermoon.shell-format" - } + "deno.enable": true, + "editor.defaultFormatter": "denoland.vscode-deno", + "[ignore]": { + "editor.defaultFormatter": "foxundermoon.shell-format" + } } diff --git a/core/build_npm.ts b/core/build_npm.ts index 9d83068..66537f1 100644 --- a/core/build_npm.ts +++ b/core/build_npm.ts @@ -4,28 +4,28 @@ import denoJson from "./deno.json" with { type: "json" }; await emptyDir("./npm"); await build({ - entryPoints: ["./mod.ts"], - outDir: "./npm", - shims: {}, - test: false, - package: { - name: "resulto", - version: denoJson.version, - description: - "TypeScript implementation of the Result type from Rust with async support", - author: "adjsky", - repository: { - "type": "git", - "url": "git+https://github.com/adjsky/resulto.git", - }, - keywords: [ - "result", - "rust", - ], - license: "MIT", - }, - postBuild() { - Deno.copyFileSync("../LICENSE", "npm/LICENSE"); - Deno.copyFileSync("README.md", "npm/README.md"); - }, + entryPoints: ["./mod.ts"], + outDir: "./npm", + shims: {}, + test: false, + package: { + name: "resulto", + version: denoJson.version, + description: + "TypeScript implementation of the Result type from Rust with async support", + author: "adjsky", + repository: { + "type": "git", + "url": "git+https://github.com/adjsky/resulto.git", + }, + keywords: [ + "result", + "rust", + ], + license: "MIT", + }, + postBuild() { + Deno.copyFileSync("../LICENSE", "npm/LICENSE"); + Deno.copyFileSync("README.md", "npm/README.md"); + }, }); diff --git a/deno.json b/deno.json index 0e6beda..653386d 100644 --- a/deno.json +++ b/deno.json @@ -1,16 +1,16 @@ { - "tasks": { - "test": "deno test --allow-read --allow-env --allow-sys" - }, - "imports": { - "@deno/dnt": "jsr:@deno/dnt@^0.41.3", - "@std/assert": "jsr:@std/assert@^1.0.6", - "@std/testing": "jsr:@std/testing@^1.0.3" - }, - "fmt": { - "useTabs": true - }, - "workspace": ["./eslint-plugin", "./core"], - "lock": false, - "nodeModulesDir": "auto" + "tasks": { + "test": "deno test --allow-read --allow-env --allow-sys" + }, + "imports": { + "@deno/dnt": "jsr:@deno/dnt@^0.41.3", + "@std/assert": "jsr:@std/assert@^1.0.6", + "@std/testing": "jsr:@std/testing@^1.0.3" + }, + "fmt": { + "useTabs": true + }, + "workspace": ["./eslint-plugin", "./core"], + "lock": false, + "nodeModulesDir": "auto" } diff --git a/eslint-plugin/README.md b/eslint-plugin/README.md index 49df260..a6f27c2 100644 --- a/eslint-plugin/README.md +++ b/eslint-plugin/README.md @@ -17,9 +17,9 @@ npm install --save-dev eslint @eslint/js typescript typescript-eslint eslint-plu ```json { - "compilerOptions": { - "strict": true - } + "compilerOptions": { + "strict": true + } } ``` @@ -31,9 +31,9 @@ import resulto from "eslint-plugin-resulto"; import ts from "typescript-eslint"; export default ts.config( - js.configs.recommended, - ...ts.configs.recommended, - resulto.configs.recommended, + js.configs.recommended, + ...ts.configs.recommended, + resulto.configs.recommended, ); ``` @@ -51,14 +51,14 @@ To make this work in TypeScript without making ESLint or tsc angry you need to: ```js export default ts.config({ - rules: { - "@typescript-eslint/no-unused-vars": [ - "warn", - { - varsIgnorePattern: "^_", - }, - ], - }, + rules: { + "@typescript-eslint/no-unused-vars": [ + "warn", + { + varsIgnorePattern: "^_", + }, + ], + }, }); ``` diff --git a/eslint-plugin/build_npm.ts b/eslint-plugin/build_npm.ts index 9dc0fc3..e72c6ec 100644 --- a/eslint-plugin/build_npm.ts +++ b/eslint-plugin/build_npm.ts @@ -4,35 +4,35 @@ import denoJson from "./deno.json" with { type: "json" }; await emptyDir("./npm"); await build({ - entryPoints: ["./mod.ts"], - outDir: "./npm", - shims: {}, - test: false, - package: { - name: "eslint-plugin-resulto", - version: denoJson.version, - description: "ESLint plugin for resulto", - author: "adjsky", - repository: { - "type": "git", - "url": "git+https://github.com/adjsky/resulto.git", - }, - keywords: [ - "result", - "rust", - "eslint", - "plugin", - ], - license: "MIT", - peerDependencies: { - "@typescript-eslint/parser": "8.x", - }, - dependencies: { - "@typescript-eslint/utils": "^8.5.0", - }, - }, - postBuild() { - Deno.copyFileSync("../LICENSE", "npm/LICENSE"); - Deno.copyFileSync("README.md", "npm/README.md"); - }, + entryPoints: ["./mod.ts"], + outDir: "./npm", + shims: {}, + test: false, + package: { + name: "eslint-plugin-resulto", + version: denoJson.version, + description: "ESLint plugin for resulto", + author: "adjsky", + repository: { + "type": "git", + "url": "git+https://github.com/adjsky/resulto.git", + }, + keywords: [ + "result", + "rust", + "eslint", + "plugin", + ], + license: "MIT", + peerDependencies: { + "@typescript-eslint/parser": "8.x", + }, + dependencies: { + "@typescript-eslint/utils": "^8.5.0", + }, + }, + postBuild() { + Deno.copyFileSync("../LICENSE", "npm/LICENSE"); + Deno.copyFileSync("README.md", "npm/README.md"); + }, }); diff --git a/eslint-plugin/deno.json b/eslint-plugin/deno.json index a41a7a3..306199c 100644 --- a/eslint-plugin/deno.json +++ b/eslint-plugin/deno.json @@ -1,13 +1,13 @@ { - "name": "@resulto/eslint-plugin", - "version": "2.0.1", - "exports": { - ".": "./mod.ts" - }, - "imports": { - "@typescript-eslint/parser": "npm:@typescript-eslint/parser@^8.12.2", - "@typescript-eslint/rule-tester": "npm:@typescript-eslint/rule-tester@^8.12.2", - "@typescript-eslint/utils": "npm:@typescript-eslint/utils@^8.12.2", - "typescript": "npm:typescript@^5.6.3" - } + "name": "@resulto/eslint-plugin", + "version": "2.0.1", + "exports": { + ".": "./mod.ts" + }, + "imports": { + "@typescript-eslint/parser": "npm:@typescript-eslint/parser@^8.12.2", + "@typescript-eslint/rule-tester": "npm:@typescript-eslint/rule-tester@^8.12.2", + "@typescript-eslint/utils": "npm:@typescript-eslint/utils@^8.12.2", + "typescript": "npm:typescript@^5.6.3" + } } diff --git a/eslint-plugin/mod.ts b/eslint-plugin/mod.ts index 50b08c5..171ffd8 100644 --- a/eslint-plugin/mod.ts +++ b/eslint-plugin/mod.ts @@ -4,28 +4,28 @@ import denoJson from "./deno.json" with { type: "json" }; import mustUseResult from "./rules/must_use_result.ts"; const plugin: FlatConfig.Plugin = { - configs: { - get recommended() { - return recommended; - }, - }, - meta: { - name: "eslint-plugin-resulto", - version: denoJson.version, - }, - rules: { - "must-use-result": mustUseResult, - }, + configs: { + get recommended() { + return recommended; + }, + }, + meta: { + name: "eslint-plugin-resulto", + version: denoJson.version, + }, + rules: { + "must-use-result": mustUseResult, + }, }; const recommended: FlatConfig.Config = { - name: "name/recommended", - plugins: { - resulto: plugin, - }, - rules: { - "resulto/must-use-result": "error", - }, + name: "name/recommended", + plugins: { + resulto: plugin, + }, + rules: { + "resulto/must-use-result": "error", + }, }; export default plugin; diff --git a/eslint-plugin/rules/must_use_result.ts b/eslint-plugin/rules/must_use_result.ts index e339e63..8077ad3 100644 --- a/eslint-plugin/rules/must_use_result.ts +++ b/eslint-plugin/rules/must_use_result.ts @@ -1,152 +1,152 @@ import { ESLintUtils } from "@typescript-eslint/utils"; import type { - ParserServicesWithTypeInformation, - TSESTree, + ParserServicesWithTypeInformation, + TSESTree, } from "@typescript-eslint/utils"; import type { TypeChecker, TypeReference } from "typescript"; const ruleCreator = ESLintUtils.RuleCreator( - (name) => - `https://github.com/adjsky/resulto/tree/master/docs/eslint/${name}.md`, + (name) => + `https://github.com/adjsky/resulto/tree/master/docs/eslint/${name}.md`, ); const rule = ruleCreator({ - name: "must-use-result", - meta: { - docs: { - description: "Result must be used to make sure errors are handled.", - }, - type: "problem", - messages: { - mustUse: "`Result` may be an `Err` variant, which should be handled.", - }, - schema: [], - }, - defaultOptions: [], - create(context) { - const parserServices = ESLintUtils.getParserServices(context); - const typeChecker = parserServices.program.getTypeChecker(); - - return { - "CallExpression,NewExpression"( - node: TSESTree.CallExpression | TSESTree.NewExpression, - ) { - if (!isResult(node, parserServices, typeChecker)) { - return; - } - - if (isReturnedOrAssigned(node)) { - return; - } - - if (isMatched(node)) { - return; - } - - context.report({ - messageId: "mustUse", - node, - }); - }, - }; - }, + name: "must-use-result", + meta: { + docs: { + description: "Result must be used to make sure errors are handled.", + }, + type: "problem", + messages: { + mustUse: "`Result` may be an `Err` variant, which should be handled.", + }, + schema: [], + }, + defaultOptions: [], + create(context) { + const parserServices = ESLintUtils.getParserServices(context); + const typeChecker = parserServices.program.getTypeChecker(); + + return { + "CallExpression,NewExpression"( + node: TSESTree.CallExpression | TSESTree.NewExpression, + ) { + if (!isResult(node, parserServices, typeChecker)) { + return; + } + + if (isReturnedOrAssigned(node)) { + return; + } + + if (isMatched(node)) { + return; + } + + context.report({ + messageId: "mustUse", + node, + }); + }, + }; + }, }); function isResult( - node: TSESTree.Node, - parserServices: ParserServicesWithTypeInformation, - typeChecker: TypeChecker, + node: TSESTree.Node, + parserServices: ParserServicesWithTypeInformation, + typeChecker: TypeChecker, ) { - const tsNodeMap = parserServices.esTreeNodeToTSNodeMap.get(node); - const type = typeChecker.getTypeAtLocation(tsNodeMap); + const tsNodeMap = parserServices.esTreeNodeToTSNodeMap.get(node); + const type = typeChecker.getTypeAtLocation(tsNodeMap); - const symbol = type.getSymbol() ?? type.aliasSymbol; + const symbol = type.getSymbol() ?? type.aliasSymbol; - if (!symbol) { - return false; - } + if (!symbol) { + return false; + } - let symbolToCheck = typeChecker.symbolToString(symbol); + let symbolToCheck = typeChecker.symbolToString(symbol); - if (symbolToCheck == "Promise") { - const typeArgument = (type as TypeReference).typeArguments?.[0]; + if (symbolToCheck == "Promise") { + const typeArgument = (type as TypeReference).typeArguments?.[0]; - if (!typeArgument) { - return false; - } + if (!typeArgument) { + return false; + } - const resolvedSymbol = typeArgument.getSymbol() ?? typeArgument.aliasSymbol; + const resolvedSymbol = typeArgument.getSymbol() ?? typeArgument.aliasSymbol; - if (!resolvedSymbol) { - return false; - } + if (!resolvedSymbol) { + return false; + } - symbolToCheck = typeChecker.symbolToString(resolvedSymbol); - } + symbolToCheck = typeChecker.symbolToString(resolvedSymbol); + } - return ( - symbolToCheck == "Result" || - symbolToCheck == "AsyncResult" || - symbolToCheck == "Ok" || - symbolToCheck == "Err" - ); + return ( + symbolToCheck == "Result" || + symbolToCheck == "AsyncResult" || + symbolToCheck == "Ok" || + symbolToCheck == "Err" + ); } function isReturnedOrAssigned(node: TSESTree.Node) { - const { parent } = node; - - if (parent?.type == "AwaitExpression") { - return isReturnedOrAssigned(parent); - } - - if ( - parent?.type == "MemberExpression" || - (node.type == "MemberExpression" && parent) - ) { - return isReturnedOrAssigned(parent); - } - - if ( - parent?.type == "LogicalExpression" || - parent?.type == "ConditionalExpression" - ) { - return isReturnedOrAssigned(parent); - } - - return ( - (parent?.type == "VariableDeclarator" && parent.init == node) || - (parent?.type == "AssignmentExpression" && parent.right == node) || - (parent?.type == "ReturnStatement" && parent.argument == node) || - (parent?.type == "ArrowFunctionExpression" && parent.body == node) || - isArgument(node) - ); + const { parent } = node; + + if (parent?.type == "AwaitExpression") { + return isReturnedOrAssigned(parent); + } + + if ( + parent?.type == "MemberExpression" || + (node.type == "MemberExpression" && parent) + ) { + return isReturnedOrAssigned(parent); + } + + if ( + parent?.type == "LogicalExpression" || + parent?.type == "ConditionalExpression" + ) { + return isReturnedOrAssigned(parent); + } + + return ( + (parent?.type == "VariableDeclarator" && parent.init == node) || + (parent?.type == "AssignmentExpression" && parent.right == node) || + (parent?.type == "ReturnStatement" && parent.argument == node) || + (parent?.type == "ArrowFunctionExpression" && parent.body == node) || + isArgument(node) + ); } function isArgument(node: TSESTree.Node) { - const { parent } = node; + const { parent } = node; - return ( - parent?.type == "CallExpression" || - parent?.type == "ArrayExpression" || - (parent?.type == "Property" && parent.parent.type == "ObjectExpression") - ); + return ( + parent?.type == "CallExpression" || + parent?.type == "ArrayExpression" || + (parent?.type == "Property" && parent.parent.type == "ObjectExpression") + ); } function isMatched({ parent }: TSESTree.Node) { - if ( - parent?.type == "MemberExpression" && - parent.property.type == "Identifier" && - (parent.property.name == "match" || parent.property.name == "asyncMatch") - ) { - return true; - } - - if (!parent) { - return false; - } - - return isMatched(parent); + if ( + parent?.type == "MemberExpression" && + parent.property.type == "Identifier" && + (parent.property.name == "match" || parent.property.name == "asyncMatch") + ) { + return true; + } + + if (!parent) { + return false; + } + + return isMatched(parent); } export default rule; diff --git a/eslint-plugin/rules/must_use_result_test.ts b/eslint-plugin/rules/must_use_result_test.ts index 82774cb..718653d 100644 --- a/eslint-plugin/rules/must_use_result_test.ts +++ b/eslint-plugin/rules/must_use_result_test.ts @@ -2,7 +2,7 @@ import rule from "../rules/must_use_result.ts"; import { tester, trimLeadingIndent } from "../test/helpers.ts"; function injectCode(code: string) { - return ` + return ` interface Result { chain(): Result @@ -62,10 +62,10 @@ ${trimLeadingIndent(code)} } tester.run("must-use-result", rule, { - valid: [ - { - name: "assign a sync result and match it", - code: injectCode(` + valid: [ + { + name: "assign a sync result and match it", + code: injectCode(` const okResult = ok(5) const errResult = err(5) @@ -75,18 +75,18 @@ tester.run("must-use-result", rule, { err(5).match(noop, noop) err(5).asyncMatch(noop, noop) `), - }, - { - name: "create a sync result using class constructor and assign it", - code: injectCode(` + }, + { + name: "create a sync result using class constructor and assign it", + code: injectCode(` const okResult = new Ok(5) const errResult = new Err(5) `), - }, + }, - { - name: "assign an async result and match it", - code: injectCode(` + { + name: "assign an async result and match it", + code: injectCode(` const okAsyncResult = okAsync(5) const errAsyncResult = errAsync(5) @@ -96,11 +96,11 @@ tester.run("must-use-result", rule, { errAsync(5).match(noop, noop) errAsync(5).asyncMatch(noop, noop) `), - }, + }, - { - name: "assign an async result and match it, using await", - code: injectCode(` + { + name: "assign an async result and match it, using await", + code: injectCode(` const okAsyncResult = await okAsync(5) const errAsyncResult = await errAsync(5) @@ -110,139 +110,139 @@ tester.run("must-use-result", rule, { (await errAsync(5)).match(noop, noop) (await errAsync(5)).asyncMatch(noop, noop) `), - }, + }, - { - name: "return a sync result in a sync function and assign it", - code: injectCode(` + { + name: "return a sync result in a sync function and assign it", + code: injectCode(` const okResult = getOk() const errResult = getErr() `), - }, + }, - { - name: "return an async result in a sync function and assign it", - code: injectCode(` + { + name: "return an async result in a sync function and assign it", + code: injectCode(` const okAsyncResult = getOkAsync() const errAsyncResult = getErrAsync() `), - }, + }, - { - name: "return a sync result in an async function and assign it", - code: injectCode(` + { + name: "return a sync result in an async function and assign it", + code: injectCode(` const okResultPromise = asyncGetOk() const errResultPromise = asyncGetErr() `), - }, + }, - { - name: "return an async result in an async function and assign it", - code: injectCode(` + { + name: "return an async result in an async function and assign it", + code: injectCode(` const okAsyncResultPromise = asyncGetAsyncOk() const errAsyncResultPromise = asyncGetAsyncOk() `), - }, + }, - { - name: "return a sync result in an async function, await and assign it", - code: injectCode(` + { + name: "return a sync result in an async function, await and assign it", + code: injectCode(` const okResult = await asyncGetOk() const errResult = await asyncGetErr() `), - }, + }, - { - name: "return an async result in an async function, await and assign it", - code: injectCode(` + { + name: "return an async result in an async function, await and assign it", + code: injectCode(` const okAsyncResult = await asyncGetAsyncOk() const errAsyncResult = await asyncGetAsyncErr() `), - }, + }, - { - name: "create a sync result and immediately pass it as an argument", - code: injectCode(` + { + name: "create a sync result and immediately pass it as an argument", + code: injectCode(` function doSomething(res: Result) { // } doSomething(ok(4)) doSomething(err(5)) `), - }, + }, - { - name: "create results in an array expression, assigned to a variable", - code: injectCode(` + { + name: "create results in an array expression, assigned to a variable", + code: injectCode(` const _ = [ok(1), err(2), okAsync(3), errAsync(4)] `), - }, - { - name: "create results in an array expression", - code: injectCode(` + }, + { + name: "create results in an array expression", + code: injectCode(` [ok(3), err(5), okAsync(2), errAsync(0)] `), - }, + }, - { - name: - "create a sync result in an object expression, assigned to a variable", - code: injectCode(` + { + name: + "create a sync result in an object expression, assigned to a variable", + code: injectCode(` const _ = { res: ok(2) } `), - }, + }, - { - name: "create a sync result and return it from an arrow function", - code: injectCode(` + { + name: "create a sync result and return it from an arrow function", + code: injectCode(` () => ok(1) `), - }, + }, - { - name: "create a sync result and return it from a regular function", - code: injectCode(` + { + name: "create a sync result and return it from a regular function", + code: injectCode(` function fn() { return ok(1) } `), - }, + }, - { - name: "create a sync result and assign it to a declared variable", - code: injectCode(` + { + name: "create a sync result and assign it to a declared variable", + code: injectCode(` let res res = ok(1) `), - }, + }, - { - name: "do stuff with results in logical expressions and assign them", - code: injectCode(` + { + name: "do stuff with results in logical expressions and assign them", + code: injectCode(` let someBool = false const _ = someBool ? ok(4) : err(2) const _ = someBool && ok(4) const _ = someBool || err(4) const _ = someBool ?? ok(2) `), - }, - { - name: - "do stuff with results in logical expressions and assign them to a declared variable", - code: injectCode(` + }, + { + name: + "do stuff with results in logical expressions and assign them to a declared variable", + code: injectCode(` let res res = false ? ok(4) : err(2) res = true && ok(4) res = false || err(4) res = true ?? ok(2) `), - }, + }, - { - name: "pass results as arguments using logical expressions", - code: injectCode(` + { + name: "pass results as arguments using logical expressions", + code: injectCode(` function fn(res: Result) { // } @@ -250,122 +250,122 @@ tester.run("must-use-result", rule, { fn(false && ok(4)) fn(false ? ok(4) : err(5)) `), - }, + }, - { - name: - "return a result from a sync function after calling some method on it returning another result", - code: injectCode(` + { + name: + "return a result from a sync function after calling some method on it returning another result", + code: injectCode(` function test() { return ok(4).chain() } `), - }, - { - name: - "return a result from an async function after calling some method on it returning another result", - code: injectCode(` + }, + { + name: + "return a result from an async function after calling some method on it returning another result", + code: injectCode(` async function test() { return await okAsync(4).chain() } `), - }, - ], - invalid: [ - { - name: "create a sync result but don't assign it", - code: injectCode(` + }, + ], + invalid: [ + { + name: "create a sync result but don't assign it", + code: injectCode(` ok(5) err(5) `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: "create a sync result using class constructor but don't assign it", - code: injectCode(` + { + name: "create a sync result using class constructor but don't assign it", + code: injectCode(` new Ok(5) new Err(5) `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: "create an async result but don't assign it", - code: injectCode(` + { + name: "create an async result but don't assign it", + code: injectCode(` okAsync(5) errAsync(5) `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: "create an async result, await it, but don't assign it", - code: injectCode(` + { + name: "create an async result, await it, but don't assign it", + code: injectCode(` await okAsync(5) await errAsync(5) `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: - "call a sync function, returning a sync result, but don't assign it", - code: injectCode(` + { + name: + "call a sync function, returning a sync result, but don't assign it", + code: injectCode(` getOk() getErr() `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: - "call a sync function, returning an async result, but don't assign it", - code: injectCode(` + { + name: + "call a sync function, returning an async result, but don't assign it", + code: injectCode(` getAsyncOk() getAsyncErr() `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: - "call an async function, returning a sync result, but don't assign it", - code: injectCode(` + { + name: + "call an async function, returning a sync result, but don't assign it", + code: injectCode(` asyncGetOk() asyncGetErr() `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: - "call an async function, returning an async result, but don't assign it", - code: injectCode(` + { + name: + "call an async function, returning an async result, but don't assign it", + code: injectCode(` asyncGetAsyncOk() asyncGetAsyncOk() `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: - "call an async function, returning a sync result, await it, but don't assign it", - code: injectCode(` + { + name: + "call an async function, returning a sync result, await it, but don't assign it", + code: injectCode(` await asyncGetOk() await asyncGetErr() `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, - { - name: - "call an async function, returning an async result, await it, but don't assign it", - code: injectCode(` + { + name: + "call an async function, returning an async result, await it, but don't assign it", + code: injectCode(` await asyncGetAsyncOk() await asyncGetAsyncErr() `), - errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], - }, - ], + errors: [{ messageId: "mustUse" }, { messageId: "mustUse" }], + }, + ], }); diff --git a/eslint-plugin/test/fixture/tsconfig.json b/eslint-plugin/test/fixture/tsconfig.json index 2ce472f..67563bb 100644 --- a/eslint-plugin/test/fixture/tsconfig.json +++ b/eslint-plugin/test/fixture/tsconfig.json @@ -1,6 +1,6 @@ { - "compilerOptions": { - "strict": true - }, - "include": ["file.ts"] + "compilerOptions": { + "strict": true + }, + "include": ["file.ts"] } diff --git a/eslint-plugin/test/helpers.ts b/eslint-plugin/test/helpers.ts index 08a5947..04e75d4 100644 --- a/eslint-plugin/test/helpers.ts +++ b/eslint-plugin/test/helpers.ts @@ -7,20 +7,20 @@ RuleTester.it = it; RuleTester.itOnly = it.only; export const tester = new RuleTester({ - languageOptions: { - parserOptions: { - tsconfigRootDir: `${import.meta.dirname}/fixture`, - project: "./tsconfig.json", - }, - }, + languageOptions: { + parserOptions: { + tsconfigRootDir: `${import.meta.dirname}/fixture`, + project: "./tsconfig.json", + }, + }, }); export function trimLeadingIndent(str: string) { - const matched = str.match(/^[\r\n]?(\s+)/); + const matched = str.match(/^[\r\n]?(\s+)/); - if (!matched) { - return str; - } + if (!matched) { + return str; + } - return str.replace(new RegExp("^" + matched[1], "gm"), "").trim(); + return str.replace(new RegExp("^" + matched[1], "gm"), "").trim(); }