Skip to content

Commit

Permalink
Fixes #37639 - Use own lint instead of @theforeman
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Jul 10, 2024
1 parent 05eb90a commit 5423aac
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"unprocessable",
"unselect",
"unstyled",
"utf8",
"virtualization",
"vms",
"vmware",
Expand All @@ -195,6 +196,6 @@
}
],
"@theforeman/rules/require-ouiaid": ["error"],
"import/no-extraneous-dependencies": "off",
"import/no-extraneous-dependencies": "off"
}
}
2 changes: 0 additions & 2 deletions .github/workflows/js_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./webpack --setupFilesAfterEnv ./global_test_setup.js ./core_test_setup.js --testPathIgnorePatterns '/node_modules/' '<rootDir>/.+fixtures.+' --config ./webpack/jest.config.js ",
Expand Down
59 changes: 59 additions & 0 deletions script/lint_core_config.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
17 changes: 10 additions & 7 deletions script/npm_test_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function runChildProcess(args, pluginPath) {
});
}
const runTests = async () => {
var dirs = packageJsonDirs();
function pluginDefinesLint(pluginPath) {
var packageHasNodeModules = fs.existsSync(`${pluginPath}/node_modules`); // skip gems
var packageData = JSON.parse(fs.readFileSync(`${pluginPath}/package.json`));
Expand All @@ -59,11 +60,17 @@ const runTests = async () => {
packageHasNodeModules && packageData.scripts && packageData.scripts.lint
);
}
var dirs = packageJsonDirs();
if (passedArgs[0] && passedArgs[0][0] !== '-') {
dirs = dirs.filter(dir => dir.endsWith(passedArgs[0]));
passedArgs.shift();
}
function customizer(objValue, srcValue) {
if (lodash.isArray(objValue)) {
return lodash.uniq(objValue.concat(srcValue));
}
return undefined;
}
// eslint-disable-next-line no-unused-vars
for (const pluginPath of dirs) {
if (pluginDefinesLint(pluginPath)) {
const testSetupFiles = [
Expand All @@ -82,11 +89,6 @@ const runTests = async () => {
if (fs.existsSync(pluginConfigPath)) {
// eslint-disable-next-line global-require
const pluginConfig = require(pluginConfigPath);
function customizer(objValue, srcValue) {
if (lodash.isArray(objValue)) {
return lodash.uniq(objValue.concat(srcValue));
}
}

const combinedConfig = lodash.mergeWith(
pluginConfig,
Expand Down Expand Up @@ -124,8 +126,9 @@ const runTests = async () => {
...passedArgs,
];

// eslint-disable-next-line no-await-in-loop
await runChildProcess(args, pluginPath); // Run every plugin test in a separate process
if(fs.existsSync(combinedConfigPath)) {
if (fs.existsSync(combinedConfigPath)) {
fs.unlinkSync(combinedConfigPath);
}
}
Expand Down
10 changes: 8 additions & 2 deletions webpack/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ const path = require('path');
const nodeModules = path.resolve(__dirname, '..', 'node_modules');
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const vendorCorePackageJsonPath = path.resolve(nodeModules, '@theforeman/vendor-core', 'package.json');
const vendorCorePackageJson = JSON.parse(fs.readFileSync(vendorCorePackageJsonPath, 'utf8'));
const vendorCorePackageJsonPath = path.resolve(
nodeModules,
'@theforeman/vendor-core',
'package.json'
);
const vendorCorePackageJson = JSON.parse(
fs.readFileSync(vendorCorePackageJsonPath, 'utf8')
);
const dependencies = {
...packageJson.dependencies,
...packageJson.devDependencies,
Expand Down

0 comments on commit 5423aac

Please sign in to comment.