Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 34 additions & 4 deletions packages/eslint-plugin-rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,55 @@ If not specified in the eslintrc file, these components will be checked for an `
"Checkbox",
"Chip",
"ChipGroup",
"Content",
"ContextSelector",
"Dropdown",
"DropdownItem",
"DropdownList",
"DropdownSeparator",
"DropdownToggle",
"DropdownToggleCheckbox",
"DualListSelector",
"EmptyState",
"EmptyStateActions",
"EmptyStateBody",
"EmptyStateFooter",
"EmptyStateHeader",
"FormSelect",
"KebabToggle",
"Masthead",
"Menu",
"MenuToggle",
"Modal",
"ModalBoxCloseButton",
"ModalContent",
"Nav",
"NavExpandable",
"NavItem",
"OptionsMenu",
"Page",
"PageSidebar",
"Pagination",
"Radio",
"RowWrapper",
"SearchInput",
"Select",
"Switch",
"Tab",
"TabButton",
"TabContent",
"Table",
"TableComposable",
"Tabs",
"Text",
"TextInput",
"TextInputGroup",
"Title",
"Toolbar",
"Table",
"TableComposable",
"Tr"
```

You can specify what components you want to check against.
You can specify what components you want to check against. This replaces the default list entirely.
```js
{
"plugins": ["@theforeman/rules"],
Expand All @@ -71,4 +87,18 @@ You can specify what components you want to check against.
}
```

Here is the list of [OUIA-compliant PatternFly 4 components](https://www.patternfly.org/v4/developer-resources/open-ui-automation/).
You can also extend the default list with additional components without replacing it:
```js
{
"plugins": ["@theforeman/rules"],
"rules": {
"@theforeman/rules/require-ouiaid": [
"warn",
{ "additional": ["CustomComponent", "AnotherComponent"] }
]
}
```

Here is the list of OUIA-compliant PatternFly components:
- [PatternFly 5](https://v5-archive.patternfly.org/developer-resources/open-ui-automation/)
- [PatternFly 4](https://v4-archive.patternfly.org/v4/developer-resources/open-ui-automation)
108 changes: 66 additions & 42 deletions packages/eslint-plugin-rules/lib/require-ouiaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,72 @@ 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',
];
const defaults = [
'Alert',
'Breadcrumb',
'Button',
'Card',
'Checkbox',
'Chip',
'ChipGroup',
'Content',
'ContextSelector',
'Dropdown',
'DropdownItem',
'DropdownList',
'DropdownSeparator',
'DropdownToggle',
'DropdownToggleCheckbox',
'DualListSelector',
'EmptyState',
'EmptyStateActions',
'EmptyStateBody',
'EmptyStateFooter',
'EmptyStateHeader',
'FormSelect',
'KebabToggle',
'Masthead',
'Menu',
'MenuToggle',
'Modal',
'ModalBoxCloseButton',
'ModalContent',
'Nav',
'NavExpandable',
'NavItem',
'OptionsMenu',
'Page',
'PageSidebar',
'Pagination',
'Radio',
'RowWrapper',
'SearchInput',
'Select',
'Switch',
'Tab',
'TabButton',
'TabContent',
'Table',
'TableComposable',
'Tabs',
'Text',
'TextInput',
'TextInputGroup',
'Title',
'Toolbar',
'Tr',
];

const { additional } =
(context.options.length === 1 && context.options[0]) || {};
const { options: contextOptions } = context;

let options = defaults;
if (additional) {
options = [...defaults, ...additional];
} else if (contextOptions.length) {
options = contextOptions;
}

function addPatternflyImport(node) {
if (
Expand Down
Loading