JSX Rules
JSX formatting, className handling, children, logical expressions, and ternaries
On This Page
classname-dynamic-at-end
Dynamic expressions in className must be at the end of class strings
Why: Static classes should come first for consistent Tailwind ordering
<div className={`flex items-center gap-4 ${className}`} /><div className={`${className} flex items-center gap-4`} />"code-style/classname-dynamic-at-end": "error"classname-multiline
Long className strings broken into multiple lines
Why: Long class strings are hard to read and review
Options
| Option | Type | Default | Description |
|---|---|---|---|
maxLength | integer | 80 | Maximum line length for class strings |
"code-style/classname-multiline": ["error", { maxLength: 80 }]<div className=" flex items-center justify-center rounded-lg p-4 "/><div className="flex items-center justify-center rounded-lg p-4 font-bold" />"code-style/classname-multiline": "error"classname-no-extra-spaces
No extra/leading/trailing spaces in class strings
Why: Extra spaces are usually unintentional
<div className="flex items-center gap-4" /><div className="flex items-center gap-4" />"code-style/classname-no-extra-spaces": "error"classname-order
Tailwind class ordering in variables, objects, and return statements
Why: Complements tailwindcss/classnames-order for non-JSX contexts
const btn = "flex items-center bg-blue-500 hover:bg-blue-600";const btn = "hover:bg-blue-600 bg-blue-500 flex items-center";"code-style/classname-order": "error"jsx-children-on-new-line
Multiple JSX children: each on own line
Why: Individual lines make the component structure clear
<Container> <Header /> <Content /> <Footer /></Container><Container><Header /><Content /><Footer /></Container>"code-style/jsx-children-on-new-line": "error"jsx-closing-bracket-spacing
No space before > or /> in JSX tags
Why: Standard JSX convention
<Button /><Input type="text" /><Button / ><Input type="text" / >"code-style/jsx-closing-bracket-spacing": "error"jsx-element-child-new-line
Nested JSX elements on new lines; text children can stay inline
Why: New lines make nesting visible
<Button> <Icon name="check" /></Button><Button><Icon name="check" /></Button>"code-style/jsx-element-child-new-line": "error"jsx-logical-expression-simplify
Remove unnecessary parens around conditions and JSX in logical expressions
Why: Extra parentheses add visual noise
{isLoading && <Spinner />}{(isLoading) && (<Spinner />)}"code-style/jsx-logical-expression-simplify": "error"jsx-parentheses-position
Opening ( for multiline JSX on same line as return/=>
Why: Parenthesis on new line wastes space
const Card = () => ( <div className="card"> <h1>Title</h1> </div>);const Card = () => ( <div className="card"> <h1>Title</h1> </div> );"code-style/jsx-parentheses-position": "error"jsx-prop-naming-convention
Props: camelCase for regular, kebab-case for data-*/aria-*
Why: Consistent prop naming follows React conventions
<Button onClick={handleClick} isDisabled={false} /><Button data-testid="submit" aria-label="Submit" /><Button on_click={handler} is_disabled={false} />"code-style/jsx-prop-naming-convention": "error"jsx-simple-element-one-line
Collapse simple JSX with single text/expression child to one line
Why: Simple elements don't need multi-line formatting
<Button>{buttonText}</Button><Title>Welcome</Title><Button> {buttonText}</Button>"code-style/jsx-simple-element-one-line": "error"jsx-string-value-trim
No leading/trailing whitespace inside JSX string attribute values
Why: Whitespace in attribute values is usually unintentional
<Button className="primary" /><Button className=" primary " />"code-style/jsx-string-value-trim": "error"jsx-ternary-format
Simple ternaries on one line; complex branches get parens with indentation
Why: Consistent ternary formatting makes conditional rendering predictable
{isLoading ? <Spinner /> : <Content />} {isLoading ? ( <Spinner size="large" />) : ( <Content> <Header /> </Content>)}{isLoading ? <Spinner /> : <Content />}"code-style/jsx-ternary-format": "error"no-empty-lines-in-jsx
No empty lines between children or after opening/before closing tags
Why: Empty lines inside JSX break the component's visual structure
<div> <Header /> <Content /> <Footer /></div><div> <Header /> <Content /></div>"code-style/no-empty-lines-in-jsx": "error"