Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37636 - remove usage of "@theforeman/test" #10239

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 0 additions & 201 deletions .eslintrc

This file was deleted.

21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const lintCoreConfig = require('./script/lint/lint_core_config.js');
const lintGenericConfig = require('./script/lint/lint_generic_config.js');

const combinedConfig = {
...lintCoreConfig,
...lintGenericConfig,
rules: {
...lintCoreConfig.rules,
...lintGenericConfig.rules,
},
plugins: [
...(lintCoreConfig.plugins || []),
...(lintGenericConfig.plugins || []),
],
extends: [
...(lintCoreConfig.extends || []),
...(lintGenericConfig.extends || []),
],
};

module.exports = combinedConfig;
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
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"node": ">=14.0.0 <21.0.0"
},
"scripts": {
"lint": "tfm-lint",
"lint:custom": "eslint ./webpack",
"lint": "eslint ./webpack ./script",
"prelint": "node ./script/lint/link-eslint-plugin.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/' '<rootDir>/.+fixtures.+' --config ./webpack/jest.config.js",
Expand All @@ -36,8 +36,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",
"@types/jest": "<27.0.0",
Expand All @@ -57,12 +55,17 @@
"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",
"jest-prop-type-error": "^1.1.0",
"jest-svg-transformer": "^1.0.0",
"jest-transform-graphql": "^2.1.0",
"jsx-ast-utils": "^3.3.3",
"path-browserify": "^1.0.1",
"prettier": "^1.19.1",
"pretty-format": "26.6.2",
Expand Down
7 changes: 7 additions & 0 deletions script/lint/@foreman/eslint-plugin-custom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const requireOuiaidRule = require('./require-ouiaid');

module.exports = {
rules: {
'require-ouiaid': requireOuiaidRule,
},
};
84 changes: 84 additions & 0 deletions script/lint/@foreman/eslint-plugin-custom/require-ouiaid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const getProp = require('jsx-ast-utils/getProp');

module.exports = {
create(context) {
const patternflyImports = new Set();
const options = context.options.length
? context.options
: [
'Alert',
'Breadcrumb',
'Button',
'Card',
'Checkbox',
'Chip',
'ChipGroup',
'ContextSelector',
'Dropdown',
'DropdownItem',
'DropdownSeparator',
'DropdownToggle',
'DropdownToggleCheckbox',
'FormSelect',
'Menu',
'Modal',
'ModalBoxCloseButton',
'ModalContent',
'Nav',
'NavExpandable',
'NavItem',
'OptionsMenu',
'Pagination',
'Radio',
'RowWrapper',
'Select',
'Switch',
'TabButton',
'TabContent',
'Tab',
'Tabs',
'Text',
'TextInput',
'Title',
'Toolbar',
'Table',
'TableComposable',
'Tr',
];

function addPatternflyImport(node) {
if (
node.type === 'ImportDeclaration' &&
node.source.value.startsWith('@patternfly/react')
) {
node.specifiers.forEach(specifier => {
if (specifier.type === 'ImportSpecifier') {
patternflyImports.add(specifier.local.name);
}
});
}
}

function checkPatternflyComponent(node) {
if (!options.includes(node.name.name)) {
return;
}
if (
node.type === 'JSXOpeningElement' &&
patternflyImports.has(node.name.name)
) {
const ouiaIdProp = getProp(node.attributes, 'ouiaId');
if (!ouiaIdProp) {
context.report({
node,
message: `ouiaId property is missing in PatternFly component '${node.name.name}'`,
});
}
}
}
return {
ImportDeclaration: addPatternflyImport,
JSXOpeningElement: checkPatternflyComponent,
};
},
};
33 changes: 33 additions & 0 deletions script/lint/link-eslint-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');

function linkEslintPlugin(runPath = process.cwd()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check npm link

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm link too complicated (need package.json with specific naming, deletes files sometimes) while creating a symlink is simple.

// instead of creating an npm package for the custom eslint plugin, we symlink it
// eslint will only search for plugins in node_modules, so we need to symlink it there
const sourceDir = path.join(__dirname, '@foreman');
const destinationDir = path.join(runPath, 'node_modules', '@foreman');
function createSymlink() {
fs.symlink(sourceDir, destinationDir, 'dir', err => {
if (err) {
console.error('Error creating symlink:', err);
MariaAga marked this conversation as resolved.
Show resolved Hide resolved
}
});
}

// Check if the symlink exists and remove it if it does
fs.lstat(destinationDir, (err, stats) => {
if (!err && stats.isSymbolicLink()) {
fs.unlink(destinationDir, unlinkErr => {
if (unlinkErr) {
console.error('Error removing existing symlink:', unlinkErr);
return;
}
createSymlink();
});
} else {
createSymlink();
}
});
}
linkEslintPlugin();
Loading
Loading