Create-react-app: Disable no-mixed-operators rule

Created on 13 Dec 2017  路  9Comments  路  Source: facebook/create-react-app

Please consider adding options in the config to disable (or add) certain linting rules. The default options are very aggressive and I end up with a lot of warnings both in command line output and in browser console. My main nemesis is no-mixed-operators, since I often use the x && y || z construct as an alternative to ternary operator. It is too common to put disable comments every time.

I can comment out the rules in the plugin, but that doesn't seem to be a good solution since it won't work well with updates.

On a side note, what are the implications of ejecting? The manual doesn't make that very clear. I understand that I can't go back to "managed" state, but what are the benefits of staying in that state?

question stale

All 9 comments

We're looking at removing no-mixed-operators in an upcoming release, but we're not yet considering allowing users to modify eslint config.

I'm sorry this is a pain point, but we curate the ESLint config to point out errors; & some of our users don't know operator precedence so this is very helpful to them.

The error would go away with the following: (x && y) || z. This is the default Prettier formats to for clarity purposes.

As for implications of ejecting, you are basically freezing your development tooling in time unless you feel comfortable completely managing it yourself.

You will no longer be able to benefit from any of the updates we push, which means you will miss out on our upgrade to Babel 7, webpack 4, and other speed improvements. You can do these upgrades yourself, but they require a high degree of understanding the interoperability between the tools.

Can you please suggest an improvement to our documentation?

You mean the part about ejecting? The docs didn't mention what you lose by doing so, but I think you pretty much answered my question, if it's only about not being able to update.

Also, I think you can "inject" by simply creating a new project and copying over sources folder and a couple other files, since there's nothing else to set up?

I think you can disable it adding a .eslintrc file in the project root folder and overwritting the create-react-app default rules like this:

{
  "extends": "react-app",
  "rules": {
   "no-mixed-operators": 0 // <- turn the eslint rule off by adding "off" or 0
  }
}

Hope this helps

since I often use the x && y || z construct as an alternative to ternary operator

What's the problem with explicitly using parens in these expressions to clarify the meaning? Seems like it's not a lot of extra typing and makes the code less confusing.

I renamed the issue because we look at the rules on a case-by-case basis. We don't plan to make them configurable.

I compile typescript into the src folder which react-scripts then picks up.

IMO the rules should be setup in such a way as to support generated code.

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adrice727 picture adrice727  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

onelson picture onelson  路  3Comments

Evan-GK picture Evan-GK  路  3Comments

Aranir picture Aranir  路  3Comments