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.

lint-staged is not taking .eslintrc.js configuration.

See original GitHub issue

[BUG]

Description

I have created 2 package.json npm scripts:

     "lint-staged:test": "lint-staged",
     "eslint:test": "eslint --fix src/global/AppRouter/AppRouter.tsx",

My configuration for lint-staged looks like;

"lint-staged": {
    "*.tsx": [
      "eslint --fix",
      "git add"
    ]
  }

By running yarn eslint:test or npm run eslint:test I’ve got no errors. Like on the image attached: image

But by running second command (“lint-staged:test”) I’ve got some errors related with the file that was checked with the first command. Image shows it: image

Those are my rules for eslint (.eslinrc.js file):

module.exports = {
  parser: '@typescript-eslint/parser', // Specifies the ESLint parser
  extends: ['plugin:@typescript-eslint/recommended', 'plugin:react/recommended', 'plugin:prettier/recommended'],
  parserOptions: {
    ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
    sourceType: 'module', // Allows for the use of imports
    ecmaFeatures: {
      jsx: true, // Allows for the parsing of JSX
    },
  },
  rules: {
    // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
    // e.g. "@typescript-eslint/explicit-function-return-type": "off",

    // note you must disable the base rule as it can report incorrect errors
    indent: 'off',
    '@typescript-eslint/indent': ['error', 2],
  },
  settings: {
    react: {
      version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
    },
  },
};

which are applied for the first command but are not applied for lint-staged.

Some possible solutions?

Environment

  • OS: Windows 10,
  • Node.js: v10.13.0,
  • lint-staged: 9.2.1,
  • eslint: 5.3.0",

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:21
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
emhagmancommented, Feb 11, 2021

I started running into this issue too and running the eslint --fix command by itself works but when run via lint-staged the config seems to be being dropped

9reactions
husseinbobcommented, Feb 13, 2020

I think I found the issue. my changes to .eslintrc.js also needed to be staged, by the looks of it? either way, git adding the eslintrc file stopped the error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

lint-staged - npm
Configure lint -staged to run linters and other tasks: for example: { "*.js": "eslint" } to run ESLint for all staged JS files;...
Read more >
Eslint husky and lint staged does not work - Stack Overflow
I set in my react js application husky:.
Read more >
Setting up ESLint, Prettier, and Husky with lint-staged for your ...
Otherwise, select Base which is the basic ESLint configuration that comes with Next.js. Once you select any of the options, it will install ......
Read more >
Basic Features: ESLint - Next.js
js. If you do not have ESLint already configured in your application, we recommend using next lint to set up ESLint along with...
Read more >
Set up a Next.js project with ESLint, Prettier, Husky, and Lint ...
ESLint ; Prettier; Husky; Lint Staged ... and minimal configuration that I have recently started using for Next.js ... 6 "no-console": "warn".
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