4

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
  • What is your Atom setting for the eslint executable? You might try pointing it directly to your module folder eg ~/node_modules/eslint/bin – Papasmile Jan 20 '18 at 19:34
  • @Papasmile My .eslintrc path is set to `~/.eslintrc.js` where my file actually is. There's no problem in reading or accessing that file by any of the projects. It's just that it is not able to detect `eslint-config-google`. – Aakash Verma Jan 20 '18 at 19:43
  • ah, got ya. I think atom does not use global plugins, see https://github.com/AtomLinter/linter-eslint/issues/110 – Papasmile Jan 20 '18 at 20:26
  • @Papasmile It did, man. Please review my answer. – Aakash Verma Jan 20 '18 at 20:46
  • You have 'use global' turned off, right? So it's technically using a 'local' plugin, but it seems too have had a hard time finding it for some reason... cool that adding it $PATH did the trick. – Papasmile Jan 20 '18 at 21:01
  • I don't have a copy of `.eslintrc` in local so it must be the global file that it is referencing using the `.eslintrc Path`. Right? – Aakash Verma Jan 20 '18 at 21:09
  • 1
    Just saying if 'use global' is turned off it thinks you have a local package installed and you've added your globally installed packages to your runtime using $PATH so it looks like a local file.... anyway all that is a bit silly so +1 for posting your experience to https://github.com/AtomLinter/linter-eslint/issues/603 that's probably a good place to figure out a root cause :) – Papasmile Jan 20 '18 at 21:27
  • @Papasmile Got it. There's only so much you can ever contribute :) – Aakash Verma Jan 21 '18 at 04:56

1 Answers1

1

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 .

Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
  • There's one more untested way [here](https://github.com/AtomLinter/linter-eslint/issues/257) if you refer to @darkred's comment. – Aakash Verma Jan 21 '18 at 04:59