generated from rdlabo/typescript-template-eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeny-import-from-ionic-module.ts
45 lines (43 loc) · 1.15 KB
/
deny-import-from-ionic-module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { TSESLint } from '@typescript-eslint/utils';
const rule: TSESLint.RuleModule<'denyImportFromIonicModule', []> = {
defaultOptions: [],
meta: {
docs: {
description:
'This plugin prevents accidental imports from @ionic/angular instead of @ionic/angular/standalone.',
url: '',
},
fixable: 'code',
messages: {
denyImportFromIonicModule:
'You must import from @ionic/angular/standalone instead of @ionic/angular.',
},
schema: [],
type: 'problem',
},
create: (context) => ({
Program(node) {
if (node.tokens) {
const moduleImport = node.tokens.find((token, index) => {
return (
token.value === "'@ionic/angular'" &&
node.tokens?.[index - 1].value === 'from'
);
});
if (moduleImport) {
context.report({
node: node,
messageId: 'denyImportFromIonicModule',
fix: (fixer) => {
return fixer.replaceText(
moduleImport,
"'@ionic/angular/standalone'"
);
},
});
}
}
},
}),
};
export = rule;