|
1 |
| -import { ParserServices } from "@typescript-eslint/experimental-utils"; |
| 1 | +import { |
| 2 | + ParserServices, |
| 3 | + AST_NODE_TYPES, |
| 4 | +} from "@typescript-eslint/experimental-utils"; |
2 | 5 | import { array, option, readonlyArray } from "fp-ts";
|
3 | 6 | import { constVoid, pipe } from "fp-ts/function";
|
4 | 7 | import { Option } from "fp-ts/Option";
|
@@ -78,41 +81,43 @@ export default createRule({
|
78 | 81 |
|
79 | 82 | return {
|
80 | 83 | ExpressionStatement(node) {
|
81 |
| - pipe( |
82 |
| - node.expression, |
83 |
| - typeOfNode, |
84 |
| - option.filter((t) => { |
85 |
| - if (t.isUnion()) { |
86 |
| - return pipe(t.types, array.every(isPureDataType)); |
87 |
| - } |
88 |
| - return isPureDataType(t); |
89 |
| - }), |
90 |
| - option.fold(constVoid, (t) => { |
91 |
| - context.report({ |
92 |
| - node: node.expression, |
93 |
| - messageId: "pureExpressionInStatementPosition", |
94 |
| - data: { |
95 |
| - dataType: t.isUnion() |
96 |
| - ? t.types[0]!.symbol.escapedName |
97 |
| - : t.symbol.escapedName, |
98 |
| - }, |
99 |
| - suggest: [ |
100 |
| - { |
101 |
| - messageId: "addReturn", |
102 |
| - fix(fixer) { |
103 |
| - return fixer.insertTextBefore(node.expression, "return "); |
104 |
| - }, |
| 84 | + if (node.expression.type !== AST_NODE_TYPES.AssignmentExpression) { |
| 85 | + pipe( |
| 86 | + node.expression, |
| 87 | + typeOfNode, |
| 88 | + option.filter((t) => { |
| 89 | + if (t.isUnion()) { |
| 90 | + return pipe(t.types, array.every(isPureDataType)); |
| 91 | + } |
| 92 | + return isPureDataType(t); |
| 93 | + }), |
| 94 | + option.fold(constVoid, (t) => { |
| 95 | + context.report({ |
| 96 | + node: node.expression, |
| 97 | + messageId: "pureExpressionInStatementPosition", |
| 98 | + data: { |
| 99 | + dataType: t.isUnion() |
| 100 | + ? t.types[0]!.symbol.escapedName |
| 101 | + : t.symbol.escapedName, |
105 | 102 | },
|
106 |
| - { |
107 |
| - messageId: "runExpression", |
108 |
| - fix(fixer) { |
109 |
| - return fixer.insertTextAfter(node.expression, "()"); |
| 103 | + suggest: [ |
| 104 | + { |
| 105 | + messageId: "addReturn", |
| 106 | + fix(fixer) { |
| 107 | + return fixer.insertTextBefore(node.expression, "return "); |
| 108 | + }, |
110 | 109 | },
|
111 |
| - }, |
112 |
| - ], |
113 |
| - }); |
114 |
| - }) |
115 |
| - ); |
| 110 | + { |
| 111 | + messageId: "runExpression", |
| 112 | + fix(fixer) { |
| 113 | + return fixer.insertTextAfter(node.expression, "()"); |
| 114 | + }, |
| 115 | + }, |
| 116 | + ], |
| 117 | + }); |
| 118 | + }) |
| 119 | + ); |
| 120 | + } |
116 | 121 | },
|
117 | 122 | JSXAttribute(node) {
|
118 | 123 | const parameterWithVoidOrUknownReturnType = (
|
|
0 commit comments