@montage-ui/eslint-plugin
v4.4.0
Published
ESLint plugin for Montage best practices
Readme
@montage-ui/eslint-plugin
Install
pnpm install -D @montage-ui/eslint-pluginLegacy config
"extends": [
"plugin:@montage-ui/recommended"
]or
"extends": [
"plugin:@montage-ui/strict"
]Flat config
import montagePlugin from '@montage-ui/eslint-plugin';
export default [montagePlugin.flatConfig.recommended];or
import montagePlugin from '@montage-ui/eslint-plugin';
export default [montagePlugin.flatConfig.strict];Rules
icon-button-uses-name
When using an icon as a button, you must specify the aria-label attribute.
<IconButton>
<IconCheck />
</IconButton>Without this attribute, screen readers cannot identify the purpose of the button.
// good
<IconButton aria-label="Close modal">
<IconCloseThick />
</IconButton>
<Button iconOnly aria-label="Remove bookmark">
<IconBookFill />
</Button>
// bad
<IconButton>
<IconCloseThick />
</IconButton>
<Button iconOnly>
<IconBookFill />
</Button>segmented-control-item-uses-name
When a SegmentedControl is iconOnly, each SegmentedControlItem must specify the aria-label (or aria-labelledby) attribute.
<SegmentedControl iconOnly defaultValue="0">
<SegmentedControlItem value="0">
<IconColumn />
</SegmentedControlItem>
</SegmentedControl>In iconOnly mode the item's text wrapper is not rendered, so without this attribute screen readers cannot identify what each segment selects.
// good
<SegmentedControl iconOnly defaultValue="0">
<SegmentedControlItem value="0" aria-label="Board view">
<IconColumn />
</SegmentedControlItem>
<SegmentedControlItem value="1" aria-label="List view">
<IconList />
</SegmentedControlItem>
</SegmentedControl>
// bad
<SegmentedControl iconOnly defaultValue="0">
<SegmentedControlItem value="0">
<IconColumn />
</SegmentedControlItem>
<SegmentedControlItem value="1">
<IconList />
</SegmentedControlItem>
</SegmentedControl>image-uses-alt
Visual images such as avatars and thumbnails must provide an alt attribute for screen readers.
<Avatar src="https://example.com/user.png" />Without alt, screen readers cannot properly describe the image. Always provide alternative text.
// good
<Avatar alt="Jane's profile photo" src="https://example.com/user.png" />
<Thumbnail alt="About page" src="/thumb.png" />
<CardThumbnail alt="Frontend developer job posting" src="/cover.png" />
<Box as="img" alt="High-five event" src="/banner.png" />
// bad
<Avatar src="https://example.com/user.png" />
<Thumbnail src="/thumb.png" />
<CardThumbnail src="/cover.png" />
<Box as="img" src="/banner.png" />