@redhat-cloud-services/eslint-config-redhat-cloud-services 1.2.0 → 1.2.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
@@ -3,43 +3,31 @@ const path = require('path');
3
3
  rulesDirPlugin.RULES_DIR = path.resolve(__dirname, './lib/rules');
4
4
 
5
5
  module.exports = {
6
- parser: '@babel/eslint-parser',
7
- env: {
8
- browser: true,
9
- node: true,
10
- es6: true,
11
- jasmine: true,
12
- jest: true
6
+ parser: '@babel/eslint-parser',
7
+ env: {
8
+ browser: true,
9
+ node: true,
10
+ es6: true,
11
+ jasmine: true,
12
+ jest: true,
13
+ },
14
+ settings: {
15
+ react: {
16
+ version: 'detect',
13
17
  },
14
- settings: {
15
- react: {
16
- version: 'detect'
17
- }
18
- },
19
- plugins: [
20
- 'prettier',
21
- 'rulesdir'
22
- ],
23
- extends: [
24
- 'eslint:recommended',
25
- 'prettier',
26
- 'plugin:prettier/recommended',
27
- 'plugin:react/recommended',
28
- 'prettier/react'
29
- ],
30
- rules: {
31
- 'no-unused-vars': [
32
- 'error',
33
- { ignoreRestSiblings: true }
34
- ],
35
- 'prettier/prettier': [
36
- 'error',
37
- { singleQuote: true }
38
- ],
39
- 'rulesdir/disallow-fec-relative-imports': 2
40
- },
41
- parserOptions: {
42
- ecmaVersion: 7,
43
- sourceType: 'module'
44
- }
18
+ },
19
+ plugins: ['prettier', 'rulesdir'],
20
+ extends: ['eslint:recommended', 'prettier', 'plugin:prettier/recommended', 'plugin:react/recommended'],
21
+ rules: {
22
+ 'no-unused-vars': ['error', { ignoreRestSiblings: true }],
23
+ 'prettier/prettier': ['error', { singleQuote: true }],
24
+ 'rulesdir/disallow-fec-relative-imports': 2,
25
+ },
26
+ globals: {
27
+ CRC_APP_NAME: 'readonly',
28
+ },
29
+ parserOptions: {
30
+ ecmaVersion: 7,
31
+ sourceType: 'module',
32
+ },
45
33
  };
@@ -4,95 +4,90 @@
4
4
  */
5
5
 
6
6
  const FECPackages = [
7
- '@redhat-cloud-services/frontend-components-charts',
8
- '@redhat-cloud-services/frontend-components',
9
- '@redhat-cloud-services/frontend-components-config',
10
- '@redhat-cloud-services/frontend-components-demo',
11
- '@redhat-cloud-services/eslint-config-redhat-cloud-services',
12
- '@redhat-cloud-services/frontend-components-inventory-compliance',
13
- '@redhat-cloud-services/frontend-components-inventory-general-info',
14
- '@redhat-cloud-services/frontend-components-inventory-insights',
15
- '@redhat-cloud-services/frontend-components-inventory',
16
- '@redhat-cloud-services/frontend-components-notifications',
17
- '@redhat-cloud-services/frontend-components-pdf-generator',
18
- '@redhat-cloud-services/frontend-components-remediations',
19
- '@redhat-cloud-services/rule-components',
20
- '@redhat-cloud-services/frontend-components-translations',
21
- '@redhat-cloud-services/frontend-components-utilities'
7
+ '@redhat-cloud-services/frontend-components-charts',
8
+ '@redhat-cloud-services/frontend-components',
9
+ '@redhat-cloud-services/frontend-components-config',
10
+ '@redhat-cloud-services/frontend-components-demo',
11
+ '@redhat-cloud-services/eslint-config-redhat-cloud-services',
12
+ '@redhat-cloud-services/frontend-components-notifications',
13
+ '@redhat-cloud-services/frontend-components-pdf-generator',
14
+ '@redhat-cloud-services/frontend-components-remediations',
15
+ '@redhat-cloud-services/rule-components',
16
+ '@redhat-cloud-services/frontend-components-translations',
17
+ '@redhat-cloud-services/frontend-components-utilities',
22
18
  ];
23
19
 
24
20
  module.exports = {
25
- meta: {
26
- type: 'suggestion',
27
- docs: {
28
- description: 'disallow relative imports from FEC packages',
29
- category: 'Possible build errors',
30
- recommended: true
31
- },
32
- fixable: 'code',
33
- messages: {
34
- avoidRelativeImport: 'Avoid using relative imports from {{ package }}. Use direct import path to {{ source }}. Module may be found at {{ hint }}.',
35
- avoidImportingStyles: 'Avoid importing styles from {{ package }}. Styles are injected with components automatically.'
36
- }
21
+ meta: {
22
+ type: 'suggestion',
23
+ docs: {
24
+ description: 'disallow relative imports from FEC packages',
25
+ category: 'Possible build errors',
26
+ recommended: true,
37
27
  },
38
- create: function(context) {
39
- return {
40
- ImportDeclaration: function (codePath) {
41
- const importString = codePath.source.value;
42
- const fecImport = FECPackages.find(pckg => importString.includes(pckg));
43
- if (fecImport && importString.match(/(css|scss|sass)/gim)) {
44
- context.report({
45
- node: codePath,
46
- messageId: 'avoidImportingStyles',
47
- data: {
48
- package: importString
49
- },
50
- fix: function(fixer) {
51
- return fixer.remove(codePath.parent);
52
- }
53
- });
54
- }
55
-
56
- /**
57
- * Check if import is from FEC package and if it directly matches the package name which means its relative import
58
- */
59
- if (fecImport && FECPackages.includes(importString)) {
60
- const fullImport = context.getSourceCode(codePath.parent).text;
61
- /**
62
- * Check if the import is not full import statement
63
- */
64
- if (!fullImport.includes('from')) {
65
- return;
66
- }
67
- /**
68
- * Determine correct variable for direct import
69
- */
70
-
71
- let variables = context.getDeclaredVariables(codePath);
72
- let varName = 'Unknown';
73
- if (variables.length > 0) {
74
- varName = variables[0].name;
75
- }
28
+ fixable: 'code',
29
+ messages: {
30
+ avoidRelativeImport:
31
+ 'Avoid using relative imports from {{ package }}. Use direct import path to {{ source }}. Module may be found at {{ hint }}.',
32
+ avoidImportingStyles: 'Avoid importing styles from {{ package }}. Styles are injected with components automatically.',
33
+ },
34
+ },
35
+ create: function (context) {
36
+ return {
37
+ ImportDeclaration: function (codePath) {
38
+ const importString = codePath.source.value;
39
+ const fecImport = FECPackages.find((pckg) => importString.includes(pckg));
40
+ if (fecImport && importString.match(/(css|scss|sass)/gim)) {
41
+ context.report({
42
+ node: codePath,
43
+ messageId: 'avoidImportingStyles',
44
+ data: {
45
+ package: importString,
46
+ },
47
+ fix: function (fixer) {
48
+ return fixer.remove(codePath.parent);
49
+ },
50
+ });
51
+ }
76
52
 
77
- context.report({
78
- node: codePath,
79
- messageId: 'avoidRelativeImport',
80
- data: {
81
- package: importString,
82
- source: varName,
83
- hint: `import ${varName} from '${importString}/${varName}'`
53
+ /**
54
+ * Check if import is from FEC package and if it directly matches the package name which means its relative import
55
+ */
56
+ if (fecImport && FECPackages.includes(importString)) {
57
+ const fullImport = context.getSourceCode(codePath.parent).text;
58
+ /**
59
+ * Check if the import is not full import statement
60
+ */
61
+ if (!fullImport.includes('from')) {
62
+ return;
63
+ }
64
+ /**
65
+ * Determine correct variable for direct import
66
+ */
84
67
 
85
- },
86
- fix: function(fixer) {
87
- const newText = variables.map(function(data) {
88
- return `import ${data.name} from "${importString}/${data.name}"`;
89
- });
90
- return fixer.replaceText(codePath, newText.join('\n'));
91
- }
92
- });
68
+ let variables = context.getDeclaredVariables(codePath);
69
+ let varName = 'Unknown';
70
+ if (variables.length > 0) {
71
+ varName = variables[0].name;
72
+ }
93
73
 
94
- }
95
- }
96
- };
97
- }
74
+ context.report({
75
+ node: codePath,
76
+ messageId: 'avoidRelativeImport',
77
+ data: {
78
+ package: importString,
79
+ source: varName,
80
+ hint: `import ${varName} from '${importString}/${varName}'`,
81
+ },
82
+ fix: function (fixer) {
83
+ const newText = variables.map(function (data) {
84
+ return `import ${data.name} from "${importString}/${data.name}"`;
85
+ });
86
+ return fixer.replaceText(codePath, newText.join('\n'));
87
+ },
88
+ });
89
+ }
90
+ },
91
+ };
92
+ },
98
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/eslint-config-redhat-cloud-services",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "description": "Recommended eslint configuration used in cloud.redhat.com frontend apps.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -12,13 +12,13 @@
12
12
  "@babel/eslint-parser": "^7.13.14",
13
13
  "eslint-config-prettier": "^8.3.0",
14
14
  "eslint-plugin-prettier": "^3.1.4",
15
- "eslint-plugin-react": "^7.23.2",
15
+ "eslint-plugin-react": "^7.28.0",
16
16
  "eslint-plugin-rulesdir": "^0.1.0",
17
17
  "prettier": "^2.1.2"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@babel/core": "^7.14.0",
21
- "eslint": "^7.19.0"
21
+ "eslint": "^8.9.0"
22
22
  },
23
23
  "license": "Apache",
24
24
  "publishConfig": {
@@ -1,9 +1,9 @@
1
1
  module.exports = {
2
- printWidth: 150,
3
- arrowParens: 'always',
4
- semi: true,
5
- tabWidth: 2,
6
- singleQuote: true,
7
- jsxSingleQuote: false,
8
- bracketSpacing: true
2
+ printWidth: 150,
3
+ arrowParens: 'always',
4
+ semi: true,
5
+ tabWidth: 2,
6
+ singleQuote: true,
7
+ jsxSingleQuote: false,
8
+ bracketSpacing: true,
9
9
  };
@@ -1,57 +0,0 @@
1
- /* eslint-disable max-len */
2
- let rule = require('../../../lib/rules/disallow-fec-relative-imports');
3
- let RuleTester = require('eslint').RuleTester;
4
-
5
- let ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: 'module' } });
6
- ruleTester.run('fec-direct-import', rule, {
7
- valid: [
8
- 'import X from "@redhat-cloud-services/frontend-components/X"',
9
- 'import { X } from "@redhat-cloud-services/frontend-components/X"',
10
- 'import { X, Y, Z } from "@redhat-cloud-services/frontend-components/X"',
11
- 'import A, { X, Y, Z } from "@redhat-cloud-services/frontend-components/X"',
12
- 'const X = 2',
13
- 'import { X } from "@somePackage/frontend-components"',
14
- 'import "@redhat-cloud-services/frontend-components"',
15
- 'const X = require("@redhat-cloud-services/frontend-components")',
16
- 'import { Spinner } from "@redhat-cloud-services/frontend-components/Spinner";\nimport "./compliance.scss";'
17
- ],
18
- invalid: [
19
- {
20
- code: 'import "@redhat-cloud-services/frontend-components/foo/styles.css"\n//additional text that should stay\n//import X from "foo"',
21
- errors: [
22
- {
23
- message: `Avoid importing styles from @redhat-cloud-services/frontend-components/foo/styles.css. Styles are injected with components automatically.`
24
- }
25
- ],
26
- output: '\n//additional text that should stay\n//import X from "foo"'
27
- },
28
- {
29
- code: 'import A from "@redhat-cloud-services/frontend-components/A"\nimport X, { Y } from "@redhat-cloud-services/frontend-components"\nimport { B } from "@redhat-cloud-services/frontend-components/B"',
30
- errors: [
31
- {
32
- message: `Avoid using relative imports from @redhat-cloud-services/frontend-components. Use direct import path to X. Module may be found at import X from '@redhat-cloud-services/frontend-components/X'.`
33
- }
34
- ],
35
- output: 'import A from "@redhat-cloud-services/frontend-components/A"\nimport X from "@redhat-cloud-services/frontend-components/X"\nimport Y from "@redhat-cloud-services/frontend-components/Y"\nimport { B } from "@redhat-cloud-services/frontend-components/B"'
36
- },
37
- {
38
- code: 'import { X } from "@redhat-cloud-services/frontend-components"',
39
- errors: [
40
- {
41
- message: `Avoid using relative imports from @redhat-cloud-services/frontend-components. Use direct import path to X. Module may be found at import X from '@redhat-cloud-services/frontend-components/X'.`
42
- }
43
- ],
44
- output: 'import X from "@redhat-cloud-services/frontend-components/X"'
45
- },
46
- {
47
- code: 'import { X, Y } from "@redhat-cloud-services/frontend-components"',
48
- errors: [
49
- {
50
- message: `Avoid using relative imports from @redhat-cloud-services/frontend-components. Use direct import path to X. Module may be found at import X from '@redhat-cloud-services/frontend-components/X'.`
51
- }
52
- ],
53
- output: 'import X from "@redhat-cloud-services/frontend-components/X"\nimport Y from "@redhat-cloud-services/frontend-components/Y"'
54
- }
55
- ]
56
- });
57
-