@redhat-cloud-services/eslint-config-redhat-cloud-services 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js
CHANGED
|
@@ -24,7 +24,8 @@ module.exports = {
|
|
|
24
24
|
'rulesdir/disallow-fec-relative-imports': 2,
|
|
25
25
|
'rulesdir/deprecated-packages': 1,
|
|
26
26
|
'rulesdir/no-chrome-api-call-from-window': 2,
|
|
27
|
-
'rulesdir/forbid-pf-relative-imports':
|
|
27
|
+
'rulesdir/forbid-pf-relative-imports': 1,
|
|
28
|
+
'rulesdir/disallow-pf-migrated-components': 1,
|
|
28
29
|
},
|
|
29
30
|
globals: {
|
|
30
31
|
CRC_APP_NAME: 'readonly',
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Rule to disallow importing components already migrated to @patternfly/react-component-groups
|
|
3
|
+
* @author Filip Hlavac
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Please add any components moved to the @patternfly/react-component-groups repo from this one
|
|
7
|
+
const forbiddenImports = ['ErrorBoundary', 'ErrorState', 'NotAuthorized'];
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'suggestion',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'disallow already migrated components',
|
|
14
|
+
category: 'Possible run errors',
|
|
15
|
+
recommended: true,
|
|
16
|
+
},
|
|
17
|
+
fixable: 'code',
|
|
18
|
+
schema: [],
|
|
19
|
+
},
|
|
20
|
+
create: function (context) {
|
|
21
|
+
return {
|
|
22
|
+
ImportDeclaration(node) {
|
|
23
|
+
const sourceValue = node.source.value;
|
|
24
|
+
const specifiers = node.specifiers;
|
|
25
|
+
const patternflyPackage = '@patternfly/react-component-groups';
|
|
26
|
+
if (sourceValue === '@redhat-cloud-services/frontend-components') {
|
|
27
|
+
specifiers.forEach((specifier) => {
|
|
28
|
+
if (specifier.type === 'ImportDefaultSpecifier' && forbiddenImports.includes(specifier.local.name)) {
|
|
29
|
+
context.report({
|
|
30
|
+
node,
|
|
31
|
+
message: `Importing ${specifier.local.name} from ${sourceValue} is deprecated, use import from ${patternflyPackage} instead.`,
|
|
32
|
+
fix(fixer) {
|
|
33
|
+
const importStatement = `import ${specifier.local.name} from '${patternflyPackage}';`;
|
|
34
|
+
return fixer.replaceText(node, importStatement);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
} else if (specifier.type === 'ImportSpecifier' && forbiddenImports.includes(specifier.imported.name)) {
|
|
38
|
+
context.report({
|
|
39
|
+
node,
|
|
40
|
+
message: `Importing ${specifier.imported.name} from ${sourceValue} is deprecated, use import from ${patternflyPackage} instead.`,
|
|
41
|
+
fix(fixer) {
|
|
42
|
+
const importStatement = `import { ${specifier.imported.name} } from '${patternflyPackage}';`;
|
|
43
|
+
return fixer.replaceText(node, importStatement);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|