Skip to content

Commit f2fc9f8

Browse files
authored
Merge pull request #48 from buildo/fix-match
Fix matching of adjacent combinators
2 parents 9ed4e9d + da868b9 commit f2fc9f8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/utils.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ export function getAdjacentCombinators<
7777
combinator2: CombinatorQuery<N2["type"]>,
7878
requireMatchingPrefix: boolean
7979
): option.Option<[N1, N2]> {
80+
function matches(value: string, stringOrRegex: string | RegExp): boolean {
81+
if (typeof stringOrRegex === "string") {
82+
return value === stringOrRegex;
83+
} else {
84+
return !!value.match(stringOrRegex);
85+
}
86+
}
87+
8088
const firstCombinatorIndex = pipeOrFlowExpression.arguments.findIndex(
8189
(a, index) => {
8290
if (
@@ -92,8 +100,8 @@ export function getAdjacentCombinators<
92100
}),
93101
option.exists(
94102
({ idA, idB }) =>
95-
!!idA.name.match(combinator1.name) &&
96-
!!idB.name.match(combinator2.name)
103+
matches(idA.name, combinator1.name) &&
104+
matches(idB.name, combinator2.name)
97105
)
98106
);
99107
}

tests/rules/prefer-bimap.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ ruleTester.run("prefer-bimap", rule, {
1919
)
2020
`,
2121
},
22+
{
23+
code: stripIndent`
24+
import { either } from "fp-ts"
25+
import { pipe } from "fp-ts/function"
26+
27+
pipe(
28+
getResult(),
29+
either.mapLeft(e => e.toString()),
30+
either.mapLeft(e => e.toString()),
31+
)
32+
`,
33+
},
2234
],
2335
invalid: [
2436
{

0 commit comments

Comments
 (0)