Skip to content

Commit

Permalink
chore(*): clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
adjsky committed Oct 31, 2024
1 parent f31ae26 commit d742d7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 6 additions & 3 deletions eslint-plugin/rules/must_use_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const rule = ruleCreator({
},
type: "problem",
messages: {
mustUse: "`Result` may be an `Err` variant, which should be handled.",
mustUse:
"`Result` may be an `Err` variant, which should be handled.",
},
schema: [],
},
Expand Down Expand Up @@ -76,7 +77,8 @@ function isResult(
return false;
}

const resolvedSymbol = typeArgument.getSymbol() ?? typeArgument.aliasSymbol;
const resolvedSymbol = typeArgument.getSymbol() ??
typeArgument.aliasSymbol;

if (!resolvedSymbol) {
return false;
Expand Down Expand Up @@ -137,7 +139,8 @@ function isMatched({ parent }: TSESTree.Node) {
if (
parent?.type == "MemberExpression" &&
parent.property.type == "Identifier" &&
(parent.property.name == "match" || parent.property.name == "asyncMatch")
(parent.property.name == "match" ||
parent.property.name == "asyncMatch")
) {
return true;
}
Expand Down
15 changes: 10 additions & 5 deletions eslint-plugin/rules/must_use_result_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ tester.run("must-use-result", rule, {
},

{
name: "return a sync result in an async function, await and assign it",
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",
name:
"return an async result in an async function, await and assign it",
code: injectCode(`
const okAsyncResult = await asyncGetAsyncOk()
const errAsyncResult = await asyncGetAsyncErr()
Expand All @@ -172,7 +174,8 @@ tester.run("must-use-result", rule, {
},

{
name: "create results in an array expression, assigned to a variable",
name:
"create results in an array expression, assigned to a variable",
code: injectCode(`
const _ = [ok(1), err(2), okAsync(3), errAsync(4)]
`),
Expand Down Expand Up @@ -219,7 +222,8 @@ tester.run("must-use-result", rule, {
},

{
name: "do stuff with results in logical expressions and assign them",
name:
"do stuff with results in logical expressions and assign them",
code: injectCode(`
let someBool = false
const _ = someBool ? ok(4) : err(2)
Expand Down Expand Up @@ -282,7 +286,8 @@ tester.run("must-use-result", rule, {
},

{
name: "create a sync result using class constructor but don't assign it",
name:
"create a sync result using class constructor but don't assign it",
code: injectCode(`
new Ok(5)
new Err(5)
Expand Down

0 comments on commit d742d7f

Please sign in to comment.