SublimeLinter / SublimeLinter-jshint

SublimeLinter plugin for JavaScript, using jshint.
MIT License
460 stars 46 forks source link

Doesn't find any .jshintrc when file is not saved anywhere #114

Closed SCdF closed 6 years ago

SCdF commented 6 years ago

To reproduce:

Open up a new ST window. Change the syntax to JavaScript. Type:

const foo = 42;

Note that the linter complains because you have to use ES6 to use const.

Now try to fix this with an external .jshintrc:

{
  "esversion": 6
}

Putting this in your home directory doesn't help, and putting one at / didn't help either. AFAICT there is no place you can put a default jshintrc file that jshint will actually find when the file is unsaved.

Apologies if there is nothing this plugin can do, it's not clear to me if the bug is in jshint, this plugin or sublime-linter in general.

kaste commented 6 years ago

Hi @SCdF !

Proposed fix is at #115 . Please check it! Generally, the problem for unsaved buffers is that we cannot pass in ... well ... a filename, and jshint needs that to find a config automatically. In the PR I pass a fake filename ${folder}/unsaved.js to jshint. (From reading their code I need to make up a filename not just a starting folder bc they call dirname on whatever you pass in.)

kaste commented 6 years ago

${folder} resolves to an open project folder within Sublime. From there it will go up til root for search.

SCdF commented 6 years ago

@kaste nice! This works for me, though I only have MacOS to test on.

kaste commented 6 years ago

Does that change make sense. I don't know jshint well enough, but using a fake file here means it cannot resolve imports etc.

Other options are to just provide a --config, or to exclude unnamed/unsaved files.

SCdF commented 6 years ago

Yeah I guess it depends on the situation. When you create a new file in an existing project it makes sense to be alongside whatever you just had open as a best guess. If that always works even in a completely empty project (ie start sublime without any context and just typing into a new file) then that's ideal!

kaste commented 6 years ago

A typical no-risk-no-fun merge.