question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to disable ESLint in specific contexts (but not everywhere)

See original GitHub issue

Is your proposal related to a problem?

On my project, ESLint’s feedback is most valuable from 1) our editors, and 2) CI. It’s not very useful when lint errors appear in the browser when connected to the dev server. (in fact, it slows me down!)

Describe the solution you’d like

I’d like to disable ESLint in the dev server, without affecting how ESLint behaves in other contexts. (e.g., eslint on the command line and in VS Code should be unafffected).

This could be via an environment var, e.g. DISABLE_LINT=1 react-scripts start.

Describe alternatives you’ve considered

I’ve looked through react-script’s webpack config to check if there was already a way to do this, but couldn’t find one: https://github.com/facebook/create-react-app/blob/027b03ba8d689e619a912ed0d72c3a11ef22ac2f/packages/react-scripts/config/webpack.config.js#L749-L767

I’ve also looked into whether there was already a global disable available from ESLint or its webpack plugin, and couldn’t find anything.

Additional context

I know CRA aims to limit the available configuration options, but it seems reasonable for this one to go in Advanced Configuration.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:33
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

18reactions
jrrcommented, Oct 30, 2020

I have a terrible, no good, really bad workaround: use an executable .eslintrc.js file and emit config conditionally.

It’s not a true disable, but you can make it do very nearly nothing:

const realConfig = {/* ...  */};

const nopConfig = {
  /*

  This config is meant to do nothing.

  It exists because there's no good way to disable ESLint in Create React App:
  https://github.com/facebook/create-react-app/issues/9929

  So the workaround here is to craft a config that does as little as possible,
  and then conditionally use it.

  */

  ignorePatterns: ["**/*.ts", "**/*.tsx", "./*.js", "config/*.js"],
};

module.exports = process.env.DISABLE_ESLINT ? nopConfig : realConfig;

Note that you can’t ignore all files lest ESLint get upset, with an error like All files matched by '/foo/bar/src/.' are ignored., but you can drop in an empty dummy file to placate it.

7reactions
sahilrajput03commented, Nov 6, 2020

Hey its there’s a simple solution to fix this in cra4, check out my guide on this topic(for cra4 only).

https://gist.github.com/sahilrajput03/bdd1f1d686da2e919eac647c89d87310

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turning off eslint rule for a specific file - Stack Overflow
1) Disabling "All rules" · You can go with 1.2 and add /* eslint-disable */ on top of the files, one by one....
Read more >
Configuration Files - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How to disable ESLint for some lines, files or folders
But, sometimes it's necessary to disable it. In this tutorial, you'll learn how to turn off ESLint for certain directories and files.
Read more >
12 essential ESLint rules for React - LogRocket Blog
Introduction. ESLint has a comprehensive set of rules for JavaScript code that cover stylistic choices and prevent common bugs.
Read more >
ESLint | WebStorm Documentation - JetBrains
To configure ESLint automatically in the current project, open the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Languages & Frameworks | ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found