-
Notifications
You must be signed in to change notification settings - Fork 991
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
11 changed files
with
465 additions
and
208 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,33 @@ | ||
/* eslint-disable no-console */ | ||
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 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(); |
Oops, something went wrong.