Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation only triggers if package.json is in workspace root #536

Open
missinglink opened this issue Oct 25, 2023 · 1 comment
Open

validation only triggers if package.json is in workspace root #536

missinglink opened this issue Oct 25, 2023 · 1 comment

Comments

@missinglink
Copy link

missinglink commented Oct 25, 2023

Here's what I did

settings.json
{
    "standard.enable": true,
    "standard.usePackageJson": true,
    "standard.autoFixOnSave": true,
    "standard.enableGlobally": false,
    "standard.validate": [
        "javascript",
        "javascriptreact"
    ]
}
package.json
{
  "devDependencies": {
    "standard": "^17.1.0"
  }
}

Create a two-level directory structure: parent -> example

Screenshot 2023-10-25 at 14 02 11

What I expected to happen

I expected validation to be enabled when my package.json was not in the root of the Workspace.

What seems to have happened

It works if I remove the parent directory such that the package.json is now in the Workspace root.
It doesn't work when the package.json is nested below the root.

ie. this directory layout works:
Screenshot 2023-10-25 at 14 01 33

Explanation

This is the coded behaviour here:

if (
!isEnabledGlobally &&
usePackageJson &&
Workspace.workspaceFolders?.length === 1
) {
const workspacePath = Workspace.workspaceFolders[0].uri.fsPath
const packageJsonPath = path.join(workspacePath, 'package.json')

Possible Workaround

Enabling "standard.enableGlobally": true allows the two-level directory structure to be validated.

This isn't acceptable in my situation as, even though I have only one top-level directory, only some of my second-level directories follow this style guide and I can't enable it for all those directories.

Suggested Fix

Instead of assuming that the package.json file is in the root of the Workspace it might be better to 'walk down' the textDocument.path until a directory with a package.json file is found (in the same way npm walks down until it finds the module root).

Closing notes

There is some code which mandates that workspace only has one top-level directory (Workspace.workspaceFolders?.length === 1), this is actually unrelated to this issue, since I do only have one top-level directory in my example.

@missinglink
Copy link
Author

related #263 cc/ @theoludwig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant