standard / vscode-standard

VS Code extension for JavaScript Standard Style (`standard`) with automatic fixing

Home Page:https://marketplace.visualstudio.com/items?itemName=standard.vscode-standard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plugin does not read package.json for global values

ckuiawa opened this issue · comments

What version of this package are you using?. 1.3.0

What operating system, Node.js, and npm version?
Mac OSX 10.15.5
Node: 12.61.1
NPM: 6.13.4

What happened?
I have VSC opened to the root of my src folder, and inside that folder are a few github projects. Inside one of those projects is a package.json file that defines global values for standardjs.
"standard": { "globals": [ "describe", "beforeAll", "afterAll", "beforeEach", "afterEach", "it", "expect", "jasmine", "fail", "spyOn", "xdescribe", "xit", "fdescribe", "fit" ] }
When I look at spec files within that project, I am getting:
" 'describe' is not defined (no-undef) standard (no-undef)"
Likewise for it, expect, spyOn, etc.

What did you expect to happen?
I expect that when I'm looking at spec files within that project that the plugin would detect the settings in project.json so that describe, it, expect, spyOn, etc would not be marked as undefined.

Are you willing to submit a pull request to fix this bug?
With some help, yes.

Is there any idea on detecting package.json for sub-directory project in vscode?

Seems like this could be fixed by setting the cwd (current working directory) to the folder containing the file we're linting, instead of the root of the vscode project (which is what I assume it currently is -- though I haven't checked).

I've checked already and currently it's using the root of the vscode workspace.
Should I take the package.json file that's the nearest to the file we're linting?

standard will automatically find the nearest package.json file by searching upwards in the directory hierarchy starting from the cwd. So if we just set the cwd before invoking standard then this should be fixed. The question is – does this break any other use cases?

It's related to this bug #118, what about if we do like this

  • use 'standard.workingDirectories' as cwd if there's
  • use 'dirname(file)' as cwd, tested and it's working for both just single project folder as workspace and workspace with multi directory/project
    Is there any other specific use case that i need to think of?