-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin-rules): add eslint-plugin-rules
Add eslint-plugin-rules to hold eslint custom rules for Foreman and plugins
- Loading branch information
Showing
9 changed files
with
650 additions
and
1 deletion.
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
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,74 @@ | ||
# Eslint Plugin Rules | ||
|
||
## About | ||
|
||
Place for eslint custom rules for Foreman and plugins | ||
|
||
## Usage | ||
|
||
### Create an eslintrc file | ||
```js | ||
{ | ||
"plugins": ["@theforeman/rules"], | ||
"rules": { | ||
"@theforeman/rules/require-ouiaid": "warn", | ||
} | ||
} | ||
``` | ||
`ouiaId` prop is used in automation tests. An example can be found [here](https://github.com/SatelliteQE/airgun/blob/master/airgun/views/cloud_insights.py). | ||
|
||
If not specified in the eslintrc file, these components will be checked for an `ouiaId` prop: | ||
``` | ||
"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", | ||
"Tabs", | ||
"Text", | ||
"TextInput", | ||
"Title", | ||
"Toolbar", | ||
"Table", | ||
"TableComposable", | ||
"Tr" | ||
``` | ||
|
||
You can specify what components you want to check against. | ||
```js | ||
{ | ||
"plugins": ["@theforeman/rules"], | ||
"rules": { | ||
"@theforeman/rules/require-ouiaid": [ | ||
"warn", | ||
"Button", | ||
"Table", | ||
] | ||
} | ||
``` | ||
Here is the list of [OUIA-compliant PatternFly 4 components](https://www.patternfly.org/v4/developer-resources/open-ui-automation/). |
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 ouiaid = require('./lib/require-ouiaid'); | ||
|
||
module.exports = { | ||
rules: { | ||
'require-ouiaid': ouiaid, | ||
}, | ||
}; |
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,60 @@ | ||
const getProp = require('jsx-ast-utils/getProp'); | ||
|
||
module.exports = { | ||
create(context) { | ||
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', | ||
'Tabs', | ||
'Text', | ||
'TextInput', | ||
'Title', | ||
'Toolbar', | ||
'Table', | ||
'TableComposable', | ||
'Tr', | ||
]; | ||
|
||
return { | ||
JSXElement(node) { | ||
if (!options.includes(node.openingElement.name.name)) { | ||
return; | ||
} | ||
|
||
const ouiaIdProp = getProp(node.openingElement.attributes, 'ouiaId'); | ||
if (!ouiaIdProp) { | ||
context.report({ node, message: 'ouiaId property is missing' }); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.