SublimeLinter / SublimeLinter-eslint

This linter plugin for SublimeLinter provides an interface to ESLint
MIT License
865 stars 88 forks source link

cwd not working in a monorepo? #320

Closed IPWright83 closed 2 years ago

IPWright83 commented 2 years ago

I might be wrong and just missing config, but I'm trying to get a monorepo working with eslint and I can't seem to get SublimeLinter-eslint working correctly, which I think comes down to the CWD. From my question this should be set based on the package.json. So my structure is as follows:

webclient
--\apps
----\main
------\package.json
.eslintrc
package.json

However if I'm interpreting the logs correctly, it looks like the CWD is just being set to the root webclient.

SublimeLinter: sublime_linter.py:345  Delay linting 'index.ts' for 0.3s
INFO:SublimeLinter.sublime_linter:Delay linting 'index.ts' for 0.3s
SublimeLinter: linter.py:1127         eslint: Checking lint mode 'background' vs lint reason 'on_modified'.  Ok.
INFO:SublimeLinter.plugin.eslint:eslint: Checking lint mode 'background' vs lint reason 'on_modified'.  Ok.
SublimeLinter: #4 linter.py:1144      eslint: linting 'index.ts'
INFO:SublimeLinter.plugin.eslint:eslint: linting 'index.ts'
SublimeLinter: #4 linter.py:922       eslint: wanted executable is '/home/ian/.nvm/versions/node/v16.14.0/bin/eslint_d'
INFO:SublimeLinter.plugin.eslint:eslint: wanted executable is '/home/ian/.nvm/versions/node/v16.14.0/bin/eslint_d'
SublimeLinter: #4 linter.py:1702      Running ...

  /home/ian/src/webclient  (working dir)
  $ cat apps/main/src/views/solutions/pages/occupancy/index.ts | /home/ian/.nvm/versions/node/v16.14.0/bin/eslint_d --format json --stdin --cache --stdin-filename /home/ian/src/webclient/apps/main/src/views/solutions/pages/occupancy/index.ts

  Modified environment:

  {'PATH': '/home/ian/.nvm/versions/node/v16.14.0/bin/'}

  Type: `import os, pprint; pprint.pprint(os.environ.copy())` in the Sublime console to get the full environment.

INFO:SublimeLinter.plugin.eslint:Running ...

  /home/ian/src/webclient  (working dir)
  $ cat apps/main/src/views/solutions/pages/occupancy/index.ts | /home/ian/.nvm/versions/node/v16.14.0/bin/eslint_d --format json --stdin --cache --stdin-filename /home/ian/src/webclient/apps/main/src/views/solutions/pages/occupancy/index.ts

  Modified environment:

  {'PATH': '/home/ian/.nvm/versions/node/v16.14.0/bin/'}

  Type: `import os, pprint; pprint.pprint(os.environ.copy())` in the Sublime console to get the full environment.
IPWright83 commented 2 years ago

This wasn't actually down to CWD - though it looked like it. It was down to some TypeScript path aliasing that was causing the problem.

kaste commented 2 years ago

From https://github.com/SublimeLinter/SublimeLinter-eslint/issues/317#issuecomment-1159571585

Typically, the cwd is where package.json is. The default is here SublimeLinter/SublimeLinter@8ebb2f0/lint/linter.py#L1039

Your configuration of SublimeLinter is not the typical case here as you're setting executable manually. In that case the place of package.json will not be resolved and cwd is set to the first open folder the file is part of.

I think we should log that so users do understand that when you touch executable you opt-out of the other automatic stuff as well.

You maybe set this because you want eslint_d. The latest version of this plugin detects eslint_d installations and prefers them automatically. So maybe setting executable is not necessary anymore.

kaste commented 2 years ago

Do you know why you have all log lines twice:

SublimeLinter: sublime_linter.py:345  Delay linting 'index.ts' for 0.3s
INFO:SublimeLinter.sublime_linter:Delay linting 'index.ts' for 0.3s

The first line comes from the SublimeLinter logger but who listens for our logger and prints it again?

IPWright83 commented 2 years ago

Ooh, I didn't know you now detect eslint_d automatically - how can I verify that's working correctly? Just wondering how you locate the file as mines nested in an .nvm directory. I'd be surprised if that's found automatically?

I don't actually know what's logging that - I have been manually trying to hack around in the linter, but didn't add that line. I'll try re-installing later and see if the logging disappears.

kaste commented 2 years ago

nvm may be not supported yet. Only global or local installations. Using nvm you have the PATH problems because we would need to read the PATH environment variable per working dir. https://github.com/SublimeLinter/SublimeLinter/issues/1795 would solve that.

You can just try and see it in the logs if it chooses eslint_d.