0

I am facing an issue which is similar to this one and since I don't have enough reputations I wasn't able to comment and this question was asked almost a year ago. And since CRA have frequent updates and its been a year I might have missed if the issues have been resolved and the mentioned question didn't have any solution in it. So here's the problem Im facing:

Instead of adding eslint-disable comments to every other file, I have turned off the no-sparse-array rule in my .eslintrc, my vscode seems to follow my customizable eslint configuration and doesn't show lightbulb or error over the respected lines of code

.eslinrc

"rules": {
    "no-sparse-arrays": "off",
     ....
     ....
  },

I am calling a method in which instead of passing undefined for more than two times for skipping parameters I used sparse array so that the method and its parameters are readable

post(SERVICE_URLS.forgotPassword(), payload, ...[,,,], false)

Here, Im setting three of the parameters as undefined, With customized eslint configuration I dont see errors / warnings over this line. But in the browser console and in the terminal running the npm run start, I can still see the error

Line 15: Unexpected comma in middle of array no-sparse-arrays

In my understanding, as the react app is bootstrapped with CRA, CRA is not following the customized configuration and as a result I can still see the warning. OR I might be missing something. Is there a workaround for this or Do I have to go for react-app-rewired or react-app-rewire-eslint to solve this problem?

Ayesha Iftikhar
  • 1,028
  • 2
  • 11
  • 27
  • If you want to customize your app created by `create-react-app` you might have to eject it with `npm run eject`. Be careful to use git and commit your changes before, since this is non-reversible. – Einar Ólafsson Jul 31 '19 at 10:31
  • Instead of `"no-sparse-arrays": "off"`, it should be `"no-sparse-arrays": 0` – Patrick Hund Jul 31 '19 at 10:47
  • 1
    Hey @PatrickHund it does the same. Please follow this link for configuring rules https://eslint.org/docs/user-guide/configuring#configuring-rules . "off" or 0 - turn the rule off "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code) "error" or 2 - turn the rule on as an error (exit code is 1 when triggered) – Ayesha Iftikhar Jul 31 '19 at 12:13
  • Hey @EinarÓlafsson thanks for getting in touch with me. I specifically dont want to eject my app. since this issue doesn't appear If Im configuring my own webpack configuration and managing my own dependencies. I wanted to know the solution specific to create react app. – Ayesha Iftikhar Jul 31 '19 at 12:28
  • @AyeshaIftikhar OK, thanks for pointing this out, I didn't know you could do it like this. Would it be acceptable for you to turn off the rule only for the offending line of code, or the module that contains it? – Patrick Hund Jul 31 '19 at 13:07
  • @PatrickHund yes I tried that when I turned the rule off in .eslintrc I no longer see warining or error over the offending line of code. But the problem is when I run the app with react scripts, when running `npm run start` , CRA ignores this turning off of the rule and still shows me warning in the terminal and in the browser console. Im actually trying to understand why is CRA ignoring my custom configuration and If theres a work around for it. If you have any blog post or documentation link regarding this please share them with me. – Ayesha Iftikhar Aug 01 '19 at 06:19
  • By any chance, have you found the fix to this issue? I'm currently encountering this and I have no idea how to remove the errors. – Normz Nov 24 '20 at 03:04

0 Answers0