Eslint-plugin-react: [react/jsx-boolean-value] enforce assign a `true` value for boolean props

Created on 27 Aug 2017  路  4Comments  路  Source: yannickcr/eslint-plugin-react

In Props Default to "True" of official docs (https://facebook.github.io/react/docs/jsx-in-depth.html#props-default-to-true):

In general, we don't recommend using this because it can be confused with the ES6 object shorthand {foo} which is short for {foo: foo} rather than {foo: true}. This behavior is just there so that it matches the behavior of HTML.

I think explicitly using {true} to a boolean prop better:

// good
<Foo bar={true}>

// bad
<Foo bar>

Is there any lint rule to enforce that?

question

Most helpful comment

@ljharb thanks. I got confused with error/warn/off and always/never.

"react/jsx-boolean-value": [2, "always"],

Now it's OK.

All 4 comments

The airbnb guide requires that the ={true} be omitted; you can configure jsx-boolean-value however you like.

How can I check <Foo bar> to be consider an error with eslint rule react/jsx-boolean-value and forcing to use <Foo bar={true}>?

@xareelee if you read the link I provided, you can configure it with "always" or "never".

@ljharb thanks. I got confused with error/warn/off and always/never.

"react/jsx-boolean-value": [2, "always"],

Now it's OK.

Was this page helpful?
0 / 5 - 0 ratings