-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37639 - Use own lint instead of @theforeman
- Loading branch information
Showing
10 changed files
with
461 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
84
script/lint/@foreman/eslint-plugin-custom/require-ouiaid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function linkEslintPlugin(runPath = process.cwd()) { | ||
// 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); | ||
Check warning on line 12 in script/lint/link-eslint-plugin.js GitHub Actions / test (13, 2.7, 14)
Check warning on line 12 in script/lint/link-eslint-plugin.js GitHub Actions / test (13, 2.7, 18)
Check warning on line 12 in script/lint/link-eslint-plugin.js GitHub Actions / test (13, 3.0, 14)
|
||
} | ||
}); | ||
} | ||
|
||
// 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); | ||
Check warning on line 22 in script/lint/link-eslint-plugin.js GitHub Actions / test (13, 2.7, 14)
Check warning on line 22 in script/lint/link-eslint-plugin.js GitHub Actions / test (13, 2.7, 18)
Check warning on line 22 in script/lint/link-eslint-plugin.js GitHub Actions / test (13, 3.0, 14)
|
||
return; | ||
} | ||
createSymlink(); | ||
}); | ||
} else { | ||
createSymlink(); | ||
} | ||
}); | ||
} | ||
linkEslintPlugin(); |
Oops, something went wrong.