diff --git a/.eslintrc b/.eslintrc index cc9d651e0eb..9972ce07536 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,10 +1,8 @@ { "plugins": [ - "@theforeman/foreman", "spellcheck", "@theforeman/rules" ], - "extends": "plugin:@theforeman/foreman/core", "rules": { "spellcheck/spell-checker": [ "warn", @@ -178,6 +176,7 @@ "unprocessable", "unselect", "unstyled", + "utf8", "virtualization", "vms", "vmware", @@ -194,7 +193,25 @@ "minLength": 3 } ], - "@theforeman/rules/require-ouiaid": ["error"], + "@theforeman/rules/require-ouiaid": [ + "error" + ], "import/no-extraneous-dependencies": "off", + "import/no-unresolved": [ + "error", + { + "ignore": [ + "foremanReact/.*" + ] + } + ], + "import/extensions": [ + "error", + { + "ignore": [ + "foremanReact/.*" + ] + } + ] } } diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml index 7501009fb3e..cddfe11b63e 100644 --- a/.github/workflows/js_tests.yml +++ b/.github/workflows/js_tests.yml @@ -52,8 +52,6 @@ jobs: run: npm ci --no-audit - name: Run linter run: npm run lint - - name: Run custom eslint rules Spellcheck (only warnings) and missing ouia-ids - run: npm run lint:custom - name: Run tests run: npm run test - name: Publish Coveralls diff --git a/package.json b/package.json index 8e74ed0dca5..50e982397c0 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,7 @@ "node": ">=14.0.0 <21.0.0" }, "scripts": { - "lint": "tfm-lint", - "lint:custom": "eslint ./webpack", + "lint": "eslint ./webpack ./script -c ./script/lint_core_config.js", "foreman-js:link": "./script/npm_link_foreman_js.sh", "postlint": "./script/npm_lint_plugins.js", "test": "npx jest --setupFilesAfterEnv ./global_test_setup.js ./core_test_setup.js --testPathIgnorePatterns '/node_modules/' '/.+fixtures.+' --config ./webpack/jest.config.js ", @@ -36,7 +35,6 @@ "@testing-library/react": "^10.0.2", "@testing-library/react-hooks": "^3.4.2", "@theforeman/builder": "^13.1.0", - "@theforeman/eslint-plugin-foreman": "^13.1.0", "@theforeman/eslint-plugin-rules": "^13.1.0", "@theforeman/vendor-core": "^13.1.0", "@theforeman/vendor-dev": "^13.1.0", @@ -57,6 +55,10 @@ "enzyme-to-json": "^3.4.3", "eslint": "^6.7.2", "eslint-plugin-spellcheck": "0.0.17", + "eslint-plugin-patternfly-react": "0.2.0", + "eslint-plugin-jquery": "^1.5.1", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-react-hooks": "^2.1.1", "graphql": "^15.5.0", "identity-obj-proxy": "^3.0.0", "jest": "^26.4.0", diff --git a/script/lint_core_config.js b/script/lint_core_config.js new file mode 100644 index 00000000000..d8d68aecf26 --- /dev/null +++ b/script/lint_core_config.js @@ -0,0 +1,59 @@ +module.exports = { + plugins: ['patternfly-react', 'promise', 'jquery', 'react-hooks'], + extends: [ + 'plugin:patternfly-react/recommended', + require.resolve('@theforeman/vendor-dev/eslint.extends.js'), + 'plugin:jquery/deprecated', + ], + rules: { + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + 'max-lines': [ + 'error', + { + max: 300, + skipBlankLines: true, + skipComments: true, + }, + ], + 'no-restricted-syntax': [ + 'error', + { + selector: 'ForInStatement', + message: + 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', + }, + { + selector: 'LabeledStatement', + message: + 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', + }, + { + selector: 'WithStatement', + message: + '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', + }, + ], + 'promise/prefer-await-to-then': 'error', + 'prettier/prettier': [ + 'error', + { + singleQuote: true, + trailingComma: 'es5', + }, + ], + 'import/no-unresolved': [ + 'error', + { + ignore: ['foremanReact/.*'], + }, + ], + 'import/extensions': [ + 'error', + { + ignore: ['foremanReact/.*'], + }, + ], + 'import/no-extraneous-dependencies': 'off', + }, +};