Create React App - console lint warnings don't

2019-08-29 23:47发布

问题:

I've got a sort of weird problem, that I don't see any mention of elsewhere.

Create React App by default seems to log lint warning in the terminal when running yarn start and also in the Chrome console. All good. Makes sense, and I've seen discussions of whether this functionality should exist, and how it should work.

My issue is that those warnings seem not to match my .eslintrc settings at all!

As in, if I run yarn lint, which runs eslint using my settings, I see none of the warnings that show up in the console and terminal when I start my app.

For example, I have this rule turned off in my .eslintrc file:

"radix": 0,

And, consequently, there's no radix warning when I run yarn lint.

(Just in response to the answer below. I've tried a variety of options for this particular rule, including "as-needed". But I wanted to turn the rule off entirely, which I've evidently accomplished, because running yarn lint shows no errors related to radix at all).

But when I start the app, I see this in yellow warning boxes in the console:

Anybody know why my .eslintrc file is being ignored here, and how to get these warnings to represent the rules I've set?

回答1:

According to the docs, you should pass either "always" or "as-needed". The latter should disable those warnings.

...
"radix": "as-needed",
...

EDIT: According to this source, you will have to eject your create-react-app to edit the ESLint settings.