elicwhite / ESLint-Formatter

Sublime Text 3 Plugin to Autoformat with Eslint
MIT License
139 stars 20 forks source link

local eslint won't work without a sublime-project file #33

Open coodoo opened 7 years ago

coodoo commented 7 years ago

I've got this config for eslint-formatter in settings > user:

{
  // The location to search for a locally installed eslint package.
  // These are all relative paths to a project's directory.
  // If this is not found, it will try to fallback to a global package
  // (see 'eslint_path' below)
  "local_eslint_path": {
    "windows": "node_modules/eslint/bin/eslint.js",
    "linux": "node_modules/.bin/eslint",
    "osx": "node_modules/.bin/eslint"
  }
}

but seems without a sublime-project file as below, format this view won't work, always complained about eslint binary not found.

Just wondering is a sublime-project file necessary to make it work?

{
    "folders":
    [
        {
            "path": "."
        }
    ]
}
npetruzzelli commented 7 years ago

Are you opening a folder instead of a project? I don't know if you are running into the same thing I did, but I'll share just in case.

For example:

C:\code\project-1\node_modules\
C:\code\project-2\node_modules\
C:\code\project-3\node_modules\

is your top most folder in sublime code or project-#?

Sometimes I have "code" open if I want to reference other projects quickly. Keep in mind, these are not Sublime Projects (directories with a configuration file specific to the SublimeText editor). In this case, it won't work and Sublime will likely give you an error like this:

Error: module.js:487
  throw err;
  ^

Error: Cannot find module
'C:\Users\username\AppData\Roaming\npm\node_modules\eslint\bin\eslint'

... and some stack information. This means it couldn't find the local module, attempted to fall back to the global one and failed. In my case, I don't have it installed globally, so this is expected.

Now, if I open folder with project-# as my top most directory, it works. It appears the local path is relative to the top most directory in the absence of a Sublime Project.

I am not a Python developer, so I can't dig through the code to confirm or deny this, but I don't think this plugin searches ancestor directories from the file being processed to automatically try a local path or try to find a local installation.

npetruzzelli commented 7 years ago

I'll add that for whatever reason, I don't have this problem with SublimeLinter-eslint. For some reason, it just works. How it locates executables is probably very different from how ESLint-Formatter does it.

http://sublimelinter.readthedocs.io/en/latest/usage.html#how-linter-executables-are-located