Skip to content

Rule Idea: Enforce boolean literals for "booleanish" HTML attributes such as aria-hidden #986

Open
@jdufresne

Description

The following forms are both correct and equivalent:

<i className="fa fa-camera-retro fa-lg" aria-hidden="true" />
<i className="fa fa-camera-retro fa-lg" aria-hidden={true} />
// OR
<i className="fa fa-camera-retro fa-lg" aria-hidden />

This proposal is that a rule would prefer the 2nd form. That is, use the more specific literal type for these attributes. This would only apply when using a literal. There are several aria-* that are booleanish. This rule could apply to all of them.

The benefit is a more consistent codebase that avoids flip-flopping on style. As well, using a boolean in a true/false context feels more natural and explicit in intent.

The types defined by @types/react at:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/5b5ec4e409bcd8d422efc505db5b0223c0c5af56/types/react/index.d.ts#L2591-L2812

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions