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

🐛 Invalid line/column calculating in Vue files #3366

Closed
1 task done
maximal opened this issue Jul 7, 2024 · 5 comments · Fixed by #3494
Closed
1 task done

🐛 Invalid line/column calculating in Vue files #3366

maximal opened this issue Jul 7, 2024 · 5 comments · Fixed by #3494
Labels
A-CLI Area: CLI A-Diagnostic Area: diagnostocis L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@maximal
Copy link

maximal commented Jul 7, 2024

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.4.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.1.18"

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

Workspace:
  Open Documents:               0

What happened?

Hi!

I’m working on integrating Biome to my Code Quality Generator (@maximal/gitlab-code-quality#6) and faced an issue of invalid issue location calculating in Vue files when using --reporter=github.

Seems like Biome shows lines/columns relative to <script> position inside of the file, and not relative to the beginning of the file. Which makes almost impossible to highlight issues in GitLab CodeQuality widget and other similar instruments.

Expected result

Calculate lines and columns regarding to the beginning of the Vue file, and not regarding <script> section contents.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Sec-ant Sec-ant added A-CLI Area: CLI L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis S-Bug-confirmed Status: report has been confirmed as a valid bug labels Jul 8, 2024
@dyc3
Copy link
Contributor

dyc3 commented Jul 10, 2024

Yeah, this is kind of a limitation of how we currently support HTML-ish template languages (see also: #1726) like vue, svelte, and others. Basically, we kinda regex for where the javascript code actually is in those files, and then just format/lint that code instead of the entire file. It's very hacky.

pub static ref VUE_FENCE: Regex = Regex::new(
r#"(?ixs)(?<opening><script(?:\s.*?)?>)\r?\n(?<script>(?U:.*))</script>"#
)

Its technically possible to figure out the line offset of the script tag and then tweak the output based on that offset. IMO, whatever the short term solution for this is, it's going to be rendered unnecessary once we have proper support for HTML-ish languages, and I'm not sure if its worth the additional complexity to do that.

@Superpat
Copy link

I'd like to a least voice support for a short term solution, though I understand that dev time is always limited. Unless proper html-ish support is right around the corner, it's going to remain a pain point for whoever uses tools that allow jumping from a file:line:char to the proper location in the editor.

@ematipico
Copy link
Member

ematipico commented Jul 17, 2024

We already fix this information inside our LSP, so I don't see why we shouldn't do it here:

We generate an offset in the case of astro/svelte/vue files:

let offset = match biome_path.extension().and_then(|s| s.to_str()) {
Some("vue") => VueFileHandler::start(content.as_str()),
Some("astro") => AstroFileHandler::start(content.as_str()),
Some("svelte") => SvelteFileHandler::start(content.as_str()),
_ => None,

And then we create a new TextRange is that offset was provided.

let location = diagnostic.location();
let span = location.span.context("diagnostic location has no span")?;
let span = if let Some(offset) = offset {
TextRange::new(
span.start().add(TextSize::from(offset)),
span.end().add(TextSize::from(offset)),
)
} else {
span
};

In the case of our reporters, we just need to provide them with a new Location that contains the new TextRange.

I am happy to help anyone that wants to help to fix the bug, or wait for me to fix it.

@dyc3
Copy link
Contributor

dyc3 commented Jul 17, 2024

Oh, then in that case this probably isn't too hard to fix. I'll have time next week to fix this, but if someone wants to tackle it earlier please do.

@maximal
Copy link
Author

maximal commented Jul 17, 2024

Had I known Rust, I would’ve helped with a pull request, for now I’ll just wait (even though your code looks very clean) :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Diagnostic Area: diagnostocis L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants