biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
14.54k stars 455 forks source link

💅 `noUndeclaredDependencies` - works fine during check, reports false-positives in WebStorm, VSCode and during precommit hook using lefthook #2475

Open ipanasenko opened 5 months ago

ipanasenko commented 5 months ago

Environment information

CLI:
  Version:                      1.7.0
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.19.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.2.4"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Linter:
  Recommended:                  true
  All:                          false
  Rules:                        a11y/noSvgWithoutTitle = "off"
                                a11y/useKeyWithClickEvents = "off"
                                a11y/useKeyWithMouseEvents = "off"
                                a11y/useValidAnchor = "off"
                                complexity/noExcessiveNestedTestSuites = "error"
                                complexity/noUselessLoneBlockStatements = "error"
                                complexity/noUselessTernary = "error"
                                correctness/noInvalidUseBeforeDeclaration = "off"
                                correctness/noNewSymbol = "error"
                                correctness/noUnusedImports = "error"
                                correctness/noUnusedPrivateClassMembers = "error"
                                correctness/noUnusedVariables = "error"
                                correctness/useExhaustiveDependencies = "off"
                                correctness/useHookAtTopLevel = "error"
                                nursery/noConstantMathMinMaxClamp = "error"
                                nursery/noEvolvingAny = "error"
                                nursery/noFlatMapIdentity = "error"
                                nursery/noMisplacedAssertion = "error"
                                nursery/noUndeclaredDependencies = "off"
                                performance/noDelete = "off"
                                style/noNegationElse = "error"
                                style/noNonNullAssertion = "off"
                                style/noRestrictedGlobals = "error"
                                style/noShoutyConstants = "error"
                                style/noUnusedTemplateLiteral = "off"
                                style/useBlockStatements = "error"
                                style/useCollapsedElseIf = "error"
                                style/useForOf = "error"
                                style/useImportType = "error"
                                style/useNodejsImportProtocol = "error"
                                style/useNumberNamespace = "error"
                                style/useShorthandAssign = "error"
                                style/useShorthandFunctionType = "error"
                                style/useSingleCaseStatement = "error"
                                suspicious/noConsoleLog = "error"
                                suspicious/noRedeclare = "off"
                                suspicious/noSkippedTests = "off"

Workspace:
  Open Documents:               0

Rule name

noUndeclaredDependencies

Playground link

not applicable

Expected result

I don't really know what additional info to provide. I will try to create a reproducible repo, but for now this all I have.

Note that this is a monorepo. Dependencies are declared NOT in root package.json file.

/package.json
/apps
    /app-1
        /package.json      <- dependencies used in `File.tsx` are declared here
            /src
                /File.tsx

When running npx biome check I see no errors. But at the same time WebStorm and VSCode highlight imports as errors, and I see the same error during precommit hook.

npx biome check:

image

git commit:

image

WebStorm: image

Let me know if I need to provide more info, thank you!

Code of Conduct

GabenGar commented 5 months ago

Within the monorepo setting include biome.json at the root of your monorepo. Third-party tools cannot into multi-root setups like monorepos and cannot read multiple biome config files. It sucks, especially if you use different configs for different projects within the monorepo, but so far it is the least problematic setup.

ipanasenko commented 5 months ago

I have single biome.json and it's is in the repo root. I don't have Biome configuration issue, it just reports things differently in IDE/precommit hook and from CLI

Sec-ant commented 5 months ago

I think this is because the root directory detection (cwd) has different results in CLI, LSP and git hooks. I will look into this issue.

Sec-ant commented 3 months ago

I did some debugging but couldn't find time to implement the fix, others are welcome to tackle it. Here is what I found:

  1. The problem is not only about LSP, it also happens in CLI commands, see #3202
  2. The reason is that we associate only one manifest file for each project. It will only resolve it once from the workspace root or working directory. However we can have many manifest files in a project like a monorepo in this issue. Relative code at https://github.com/biomejs/biome/blob/42bc279a7282be7bc11778204ec1bc8a822a3703/crates/biome_cli/src/commands/mod.rs#L555 and https://github.com/biomejs/biome/blob/42bc279a7282be7bc11778204ec1bc8a822a3703/crates/biome_lsp/src/session.rs#L552
  3. To fix it we may need to revamp the structure of the project/workspace internal structure.
aminya commented 1 week ago

For me, it fails to detect dependencies in a pnpm monorepo workspace even from CLI. It also errors out in VsCode.