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

🐛 suspicious/noRedundantUseStrict is reported for .cjs files #4665

Open
1 of 3 tasks
risu729 opened this issue Sep 23, 2024 · 6 comments
Open
1 of 3 tasks

🐛 suspicious/noRedundantUseStrict is reported for .cjs files #4665

risu729 opened this issue Sep 23, 2024 · 6 comments
Labels
A-Linter Area: linter good first issue Good for newcomers S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@risu729
Copy link
Contributor

risu729 commented Sep 23, 2024

VS Code version

1.94.0-insider

Extension version

2.3.0

Biome version

1.9.2

Operating system

  • Windows
  • macOS
  • Linux

Description

The extension reports an error for use strict directive in .cjs files with suspicious/noRedundantUseStrict.

Steps to reproduce

  1. Create a file with .cjs exntension.
  2. Add use strict directive.
  3. Error is shown as a problem.

Expected behavior

No errors are shown as documents says.

Instead, .cjs files are considered “scripts” and the directive "use strict" is accepted and advised.

Does this issue occur when using the CLI directly?

No

Link to a minimal reproduction

https://github.com/risu729/biome-repro-1727086476220

Logs

CLI:
  Version:                      1.9.2
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.9.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.8.3"

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

Workspace:
  Open Documents:               0

Discovering running Biome servers...

Running Biome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i The client isn't connected to any server but rage discovered this running Biome server.

Server:
  Version:                      1.9.2
  Name:                         biome_lsp
  CPU Architecture:             x86_64
  OS:                           linux

Workspace:
  Open Documents:               0

Other Active Server Workspaces:

Workspace:
  Open Documents:               2
  Client Name:                  Visual Studio Code - Insiders
  Client Version:               1.94.0-insider

Biome Server Log:

! Please review the content of the log file before sharing it publicly as it may contain sensitive information:
  * Path names that may reveal your name, a project name, or the name of your employer.
  * Source code

┐biome_cli::commands::daemon::Running Server{pid=9130}
├─ INFO biome_cli::service::unix Trying to connect to socket /home/risu/.cache/biome/biome-socket-1.9.2
├─ INFO biome_lsp::server Starting Biome Language Server...
├─ WARN biome_lsp::server The Biome Server was initialized with the deprecated `root_path` parameter: this is not supported, use `root_uri` instead
├─ INFO biome_lsp::server Attempting to load the configuration from 'biome.json' file
├─ INFO biome_lsp::session Detected workspace folder.
├─ INFO biome_lsp::session Attempt to load the configuration file in Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/home/risu/github/use-strict-biome/biome-repro-1727086476220", query: None, fragment: None }
└─┐biome_fs::fs::os::OsFileSystem::open_with_options{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/biome.json", options=OpenOptions { read: true, write: false, truncate: false, create: false, create_new: false }}
┌─┘
└─┐biome_fs::fs::os::OsFile::read_to_string{}
┌─┘
└─┐biome_json_parser::parse{}
┌─┘
├─ INFO biome_lsp::session Configuration loaded successfully from disk.
├─ INFO biome_lsp::session Update workspace settings.
├─ DEBUG biome_service::workspace::server Compare the current project with the new one None Some("/home/risu/github/use-strict-biome/biome-repro-1727086476220") true
└─┐biome_fs::fs::os::OsFileSystem::open_with_options{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/package.json", options=OpenOptions { read: true, write: false, truncate: false, create: false, create_new: false }}
┌─┘
└─┐biome_fs::fs::os::OsFile::read_to_string{}
┌─┘
└─┐biome_json_parser::parse{}
┌─┘
└─┐biome_lsp::handlers::text_document::did_open{text_document_uri=file:///home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs, text_document_language_id=javascript}
  └─┐biome_service::file_handlers::try_from_language_id{language_id="javascript"}
  ┌─┘
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  ├─ DEBUG biome_service::workspace::server File capabilities: Js(JsFileSource { language: JavaScript, variant: Jsx, module_kind: Module, version: ES2022, embedding_kind: None }) BiomePath { path: "/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs", kind: FileKinds(BitFlags<FileKind>(0b10000, Handleable)), was_written: false }
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  ├─ DEBUG biome_service::workspace The file has the following feature sets: 
  │ {Format: Supported, Search: Supported, Assists: Supported, Lint: Supported, OrganizeImports: Supported}
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  ├─ DEBUG biome_service::workspace::server File capabilities: Js(JsFileSource { language: JavaScript, variant: Jsx, module_kind: Module, version: ES2022, embedding_kind: None }) BiomePath { path: "/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs", kind: FileKinds(BitFlags<FileKind>(0b10000, Handleable)), was_written: false }
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  └─┐biome_js_parser::parse::parse{}
  ┌─┘
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  ├─ DEBUG biome_service::workspace::server File capabilities: Js(JsFileSource { language: JavaScript, variant: Jsx, module_kind: Module, version: ES2022, embedding_kind: None }) BiomePath { path: "/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs", kind: FileKinds(BitFlags<FileKind>(0b10000, Handleable)), was_written: false }
  └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
    ┌─┘
    └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
    ┌─┘
  ┌─┘
  └─┐biome_service::workspace::server::Pulling diagnostics{categories=RuleCategories(BitFlags<Categories>(0b111, Syntax | Lint | Action))}
    └─┐biome_service::file_handlers::try_from_path{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
      └─┐biome_service::file_handlers::try_from_well_known{path="/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs"}
      ┌─┘
      └─┐biome_service::file_handlers::try_from_extension{extension="cjs"}
      ┌─┘
    ┌─┘
    └─┐biome_service::file_handlers::javascript::Linting JavaScript file{path=BiomePath { path: "/home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs", kind: FileKinds(BitFlags<FileKind>(0b10000, Handleable)), was_written: false }, language=Js(JsFileSource { language: JavaScript, variant: Jsx, module_kind: Module, version: ES2022, embedding_kind: None })}
      ├─ INFO biome_service::file_handlers::javascript Analyze file /home/risu/github/use-strict-biome/biome-repro-1727086476220/index.cjs
      ├─ DEBUG biome_rowan::ast::batch pushing change...
      ├─ DEBUG biome_rowan::ast::batch pushing change...
    ┌─┘
  ┌─┘
  ├─ INFO biome_service::workspace::server Pulled 1 diagnostic(s)
┌─┘
├─ INFO biome_lsp::session Loaded client configuration: Object {
│     "enabled": Bool(true),
│     "lspBin": String(""),
│     "searchInPath": Bool(true),
│     "rename": Bool(false),
│ }
├─ INFO biome_lsp::session Unregister capabilities "workspace/didChangeConfiguration, textDocument/rangeFormatting, textDocument/onTypeFormatting, textDocument/rename, textDocument/formatting, workspace/didChangeWatchedFiles"
├─ INFO biome_lsp::session Register capabilities "workspace/didChangeConfiguration, textDocument/rangeFormatting, textDocument/onTypeFormatting, textDocument/formatting, workspace/didChangeWatchedFiles"
@risu729
Copy link
Contributor Author

risu729 commented Sep 23, 2024

might be related to biomejs/biome-vscode#338

@nhedger
Copy link
Member

nhedger commented Nov 30, 2024

This is likely not an issue with the extension. Diagnostics are created by the LSP server in the main repository.

@nhedger nhedger transferred this issue from biomejs/biome-vscode Nov 30, 2024
@ematipico
Copy link
Member

ematipico commented Dec 5, 2024

That's expected @risu729 . Your package.json files have a type module, so Biome assumes that files are ESM.

Is there a reason to have a cjs file inside a ESM project?

@ematipico ematipico added S-Needs response Status: await response from OP S-Needs discussion Status: needs a discussion to understand criteria labels Dec 5, 2024
@risu729
Copy link
Contributor Author

risu729 commented Dec 5, 2024

Thank you for your response!
Some linters only support .cjs but not .mjs (or .js with esm) for config files, unfortunately.

Also, I think this is a bug because the LSP server and the CLI behaviour are inconsistent.

@ematipico ematipico added good first issue Good for newcomers S-Help-wanted Status: you're familiar with the code base and want to help the project A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug and removed S-Needs response Status: await response from OP S-Needs discussion Status: needs a discussion to understand criteria labels Dec 5, 2024
@ematipico
Copy link
Member

ematipico commented Dec 5, 2024

This bug should be easy to fix. If a file is a .cjs, the rule shouldn't be applied/triggered, regardless of what we have in the manifest.

@risu729
Copy link
Contributor Author

risu729 commented Dec 5, 2024

Yes, it seems it is implemented so, which should be why CLI doesn't report an error.
However, the VS Code extension (or LSP server) reports the error which is weird. I guess the filename cannot be retrieved properly but I don't understand about their implementations.

if index + 1 == directives_len
&& parent.is_script()
&& file_source.is_script()
&& outer_most.is_none()
{
break;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter good first issue Good for newcomers S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

No branches or pull requests

3 participants