JSX Plugin
Rules for code that describes UI with the "JSX" markup language, commonly in .jsx and/or .tsx files.
This plugin is provided in a standalone @flint.fyi/plugin-jsx npm package.
npm install @flint.fyi/plugin-jsxpnpm install @flint.fyi/plugin-jsxyarn install @flint.fyi/plugin-jsxPresets
Section titled “Presets”Flint’s JSX plugin provides the following presets:
| Preset | Recommended | Description |
|---|---|---|
logical | ✅ Always | Common rules for finding bugs and enforcing good logical practices for JSX. |
logicalStrict | ☑️ When Ready | Additional rules for finding bugs and enforcing good logical practices for JSX. |
stylistic | ✅ Always | Common rules for consistent styling and best JSX stylistic practices for JSX. |
If you are just getting started with linting, Flint recommends using the logical and stylistic presets:
import { jsx } from "@flint.fyi/plugin-jsx";import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: jsx.files.all, rules: [jsx.presets.logical, jsx.presets.stylistic], }, ],});If you are experienced with both JavaScript/TypeScript and linting, Flint recommends additionally using the logicalStrict preset:
import { jsx } from "@flint.fyi/plugin-jsx";import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: jsx.files.all, rules: [jsx.presets.logicalStrict, jsx.presets.stylistic], }, ],});logical
Section titled “logical”Rules that find bugs and enforce best practices and catch common pitfalls around JSX for most-to-all JavaScript and TypeScript files.
import { jsx } from "@flint.fyi/plugin-jsx";import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: jsx.files.all, rules: jsx.presets.logical, }, ],});logicalStrict
Section titled “logicalStrict”Additional logical rules that enforce best practices which are not always straightforward to implement. These rules are recommended for projects where a majority of developers are experienced with both JavaScript/TypeScript and using a linter.
import { jsx } from "@flint.fyi/plugin-jsx";import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: jsx.files.all, rules: jsx.presets.logicalStrict, }, ],});This preset’s rules are a superset of those in logical.
stylistic
Section titled “stylistic”Rules that enforce consistent JSX styling and best JSX stylistic practices for most-to-all JavaScript and TypeScript files.
import { jsx } from "@flint.fyi/plugin-jsx";import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: jsx.files.all, rules: jsx.presets.stylistic, }, ],});| Flint Rule | Preset |
|---|---|
buttonTypesReports button elements without an explicit type attribute. | logical |
accessKeysDisallow the use of the accessKey / accesskey attribute on JSX elements. | Logical |
altTextsReports elements that require alt text but are missing it. | Logical |
anchorContentReports anchor elements without accessible content. | Logical |
anchorValidityReports invalid usage of anchor elements. | Logical |
ariaActiveDescendantTabIndexReports elements with aria-activedescendant without tabIndex. | Logical |
ariaPropsReports invalid ARIA properties. | Logical |
ariaPropTypesReports ARIA properties with invalid value types. | Logical |
ariaRoleValidityReports invalid or abstract ARIA roles. | Logical |
ariaUnsupportedElementsReports ARIA attributes on elements that don't support them. | Logical |
autocompleteEnsure the autocomplete attribute is correct and suitable for the form field. | Logical |
autoFocusPropsReports autoFocus props that are not set to false. | Logical |
clickEventKeyEventsReports onClick without keyboard event handlers. | Logical |
commentTextNodesReports JSX text nodes that contain comment syntax but are rendered as text. | Logical |
distractingElementsReports distracting elements like <marquee> and <blink>. | Logical |
headingContentsReports heading elements without accessible content. | Logical |
htmlLangsReports <html> elements without a lang prop. | Logical |
iframeTitlesReports <iframe> elements without a title prop. | Logical |
interactiveElementRolesReports interactive elements with non-interactive ARIA roles. | Logical |
interactiveElementsFocusableReports interactive elements that are not focusable via keyboard. | Logical |
labelAssociatedControlsReports <label> elements without an associated control element. | Logical |
mediaCaptionsReports media elements without captions. | Logical |
mouseEventKeyEventsReports mouse events without corresponding keyboard events. | Logical |
nonInteractiveElementInteractionsReports non-interactive elements with interactive event handlers. | Logical |
nonInteractiveElementRolesReports non-interactive elements with interactive ARIA roles. | Logical |
nonInteractiveElementTabIndexesReports non-interactive elements with positive or zero tabIndex values. | Logical |
propDuplicatesDisallow duplicate props in JSX elements. | Logical |
roleRedundanciesReports redundant ARIA roles on elements with implicit roles. | Logical |
roleRequiredAriaPropsReports ARIA roles missing their required ARIA properties. | Logical |
roleSupportedAriaPropsReports ARIA properties that are not supported by an element's role. | Logical |
scopePropsReports scope props on non-th elements. | Logical |
staticElementInteractionsReports static elements with event handlers that lack ARIA roles. | Logical |
svgTitlesReports <svg> elements without a <title> child element. | Logical |
tabIndexPositiveValuesReports positive tabIndex values. | Logical |
anchorAmbiguousTextReports anchor elements with ambiguous text that doesn't describe the link destination. | Logical (Strict) |
ariaHiddenFocusablesReports elements with aria-hidden='true' that are focusable. | Logical (Strict) |
elementChildrenValidityReports void DOM elements that have children, which is invalid HTML. | Logical (Strict) |
langValidityReports invalid lang attribute values. | Logical (Strict) |
roleTagsReports ARIA roles that have semantic HTML element equivalents. | Logical (Strict) |
booleanValuesPrefer shorthand boolean attributes over explicit {true} values in JSX. | Stylistic |
bracedStatementsDisallow unnecessary JSX curly braces around literals and JSX elements. | Stylistic |
childrenPropsReports usage of the children prop. | Stylistic |
unescapedEntitiesDisallow unescaped HTML entities in JSX text that may cause rendering issues. | Stylistic |
unnecessaryFragmentsDisallow unnecessary JSX fragments that wrap a single child or have no children. | Stylistic |
Selectors
Section titled “Selectors”Flint’s JSX plugin provides the following file selector:
all:**/*.{jsx,tsx}