-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix complex cases in no-unnecessary-duplication (#22)
* Add test for cases from issue #21 * Use text representation of node for comparing * Add test case with complex formatting * Use same formatting for text node comparing
- Loading branch information
1 parent
e9c28f3
commit 315a486
Showing
7 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,8 @@ | |
"peerDependencies": { | ||
"effector": "*", | ||
"eslint": "*" | ||
}, | ||
"dependencies": { | ||
"prettier": "^2.3.2" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
rules/no-unnecessary-duplication/examples/correct-examples-01.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { guard } from "effector"; | ||
|
||
// Examples were found in production code-base with false-poitive detection on 0.1.2 | ||
|
||
guard({ | ||
source: someService.$aviaForm, | ||
clock: someService.submitted, | ||
filter: (state) => | ||
Boolean(state && isValidDirection(state.origin, state.destination)), | ||
target: drawAttention, | ||
}); | ||
|
||
guard({ | ||
source: promocodeModel.$verifyError, | ||
clock: [promocodeChanged, promocodeInputBlurred], | ||
filter: Boolean, | ||
target: promocodeModel.verifyErrorReset, | ||
}); | ||
|
||
guard({ | ||
source: [someService.$aviaForm, $backendFilters, currencyService.$currency], | ||
clock: [$backendFilters, publicApi.allPricesShown], | ||
filter: $isValid, | ||
target: requestPricesFx, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const prettier = require("prettier"); | ||
|
||
function areNodesSameInText({ context, nodes }) { | ||
const texts = nodes.map((node) => | ||
prettier.format(context.getSourceCode().getText(node), { | ||
parser: "babel-ts", | ||
}) | ||
); | ||
|
||
return texts.every((text) => text === texts[0]); | ||
} | ||
|
||
module.exports = { areNodesSameInText }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters