Skip to content

vscode/lsp: Unsafe quick-fix for applying a file-wide disable-directive with file using hashbang #17550

Description

@connorshea

What version of Oxlint are you using?

1.36.0

What command did you run?

N/A

What does your .oxlintrc.json config file look like?

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": [
    "eslint"
  ],
  "categories": {
    "correctness": "off"
  },
  "rules": {
    "no-console": "error"
  }
}

What happened?

Basically, when a file is a node script with a #!/usr/bin/env node as the first line, applying the quick fix for "disable rule for whole file" creates an invalid file. If we have a hashbang line, we should apply the oxlint-disable on the second line of the file.

I have a reproduction repro here: https://github.com/connorshea/oxlint-disable-directive-issue-repro

Reproduction steps:

  • git clone https://github.com/connorshea/oxlint-disable-directive-issue-repro
  • cd oxlint-disable-directive-issue-repro
  • npm install
  • Open the repo in VS Code (or another LSP-based editor that supports quick fixes)
  • Open index.js, which looks like this:
#!/usr/bin/env node

// If I try to apply the "disable rule for whole file" fix here,
// it will go to the top of the file. I want to keep the
// `#!/usr/bin/env node` line as the first thing in the file
// so the file is valid.
console.log("this isn't allowed :)");

On the console.log line, there is a diagnostic which can be quick-fixed:

Image

If you fix it by applying the "disable no-console for this whole file" quick fix, the result is this code, which is invalid:

// oxlint-disable no-console
#!/usr/bin/env node

// If I try to apply the "disable rule for whole file" fix here,
// it will go to the top of the file. I want to keep the
// `#!/usr/bin/env node` line as the first thing in the file
// so the file is valid.
console.log("this isn't allowed :)");

Metadata

Metadata

Assignees

Labels

A-editorArea - Editor and Language ServerA-linterArea - Linter

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions