Search code examples
javascriptatom-editoreslintlintereslintrc

eslint-config-google doesn't detect globally installed eslint


Whenever I try to install eslint-config-google globally via

npm install -g eslint-config-google

I get

npm WARN eslint-config-google@0.9.1 requires a peer of eslint@>=4.1.1 but none is installed.
You must install peer dependencies yourself.

But when I do eslint --v just to reconfirm, I get v4.16.0.

I don't know where I am going wrong.


Dependant question: Also, I have a global default .eslintrc file in my ~(home) folder which I point to from the linter - eslint package in Atom. When I save any .js file on Atom, I get

Cannot find module 'eslint-config-google' Referenced from: /Users/aakashverma/.eslintrc.js

This is my .eslintrc.js file in ~:

module.exports = {
  "extends": ["eslint:recommended", "google"],
  "rules": {
    "indent": [
      "error",
      4
    ],
    "linebreak-style": [
      "error",
      "unix"
    ],
    "quotes": [
      "error",
      "single"
    ],
    "semi": [
      "error",
      "always"
    ],
    // allow console and debugger in development
    'no-console': process.env.NODE_ENV === 'production' ? 2 : 0,
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
  }
}

This kind of talks about it.


Solution

  • Okay, I am not sure if this was a cache problem or something but I don't think it was because I kept restarting Atom and zsh but here's how it worked:

    In Atom, I changed .eslintrc Path to ~/.eslintrc.js and Use global ESlint installation to `checked.

    And this is my .eslintrc in the home folder as pointed to in Atom

    enter image description here

    And lastly, to make it work with Use global ESlint installation turned on, I included both eslint-config-google and eslint in my $PATH variable this way

    /usr/local/bin
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    /Users/aakashverma/.nvm/versions/node/v9.4.0/lib/node_modules/eslint/
    /Users/aakashverma/.nvm/versions/node/v9.4.0/lib/node_modules/eslint-config-google/
    

    Refer to the answer by @ginna here and my comment here .