Skip to content

Commit ecb4f67

Browse files
committed
Fix import path for effects operators
1 parent 8022b08 commit ecb4f67

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Diff for: src/rxjsPipeableOperatorsOnlyRule.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,21 @@ function findImportedRxjsOperators(sourceFile: ts.SourceFile): Set<string> {
205205
* @param startIndex Position where the {@link Lint.Replacement} can be inserted
206206
*/
207207
function createImportReplacements(operatorsToAdd: Set<string>, startIndex: number): Lint.Replacement[] {
208-
return [...Array.from(operatorsToAdd.values())].map(operator =>
209-
NGRX_OPERATORS.has(operator)
210-
? Lint.Replacement.appendText(startIndex, `\nimport {${operator}} from '@ngrx/store';\n`)
211-
: Lint.Replacement.appendText(
212-
startIndex,
213-
`\nimport {${operator}} from 'rxjs/operators/${operator}';\n`
214-
)
215-
);
208+
return [...Array.from(operatorsToAdd.values())].map(operator => {
209+
let importPath: string;
210+
if (NGRX_EFFECT_OPERATORS.has(operator)) {
211+
importPath = '@ngrx/effects';
212+
}
213+
if (NGRX_STORE_OPERATORS.has(operator)) {
214+
importPath = '@ngrx/store';
215+
} else {
216+
importPath = `rxjs/operators/${operator}`;
217+
}
218+
return Lint.Replacement.appendText(
219+
startIndex,
220+
`\nimport {${operator}} from '${importPath}';\n`
221+
);
222+
});
216223
}
217224

218225
/**
@@ -302,7 +309,8 @@ function replaceWithPipeableOperators(
302309
return [operatorReplacement, ...separatorReplacements, ...moreReplacements];
303310
}
304311

305-
const NGRX_OPERATORS = new Set(['ofType', 'select']);
312+
const NGRX_STORE_OPERATORS = new Set(['select']);
313+
const NGRX_EFFECT_OPERATORS = new Set(['ofType']);
306314

307315
/**
308316
* Set of all instance operators, including those renamed as part of lettable

0 commit comments

Comments
 (0)