Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": {
"no-debugger": "off",
"unicorn/filename-case": ["error", {
"cases": {
"kebabCase": false,
"camelCase": false,
"pascalCase": true,
"snakeCase": true
}
}]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
debugger
---
26 changes: 26 additions & 0 deletions crates/oxc_language_server/src/linter/error_with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ pub fn message_to_lsp_diagnostic(
// Add ignore fixes
let error_offset = message.span().start;
let section_offset = message.section_offset;

// If the error is exactly at the section offset and has 0 span length, it means that the file is the problem
// and attaching a ignore comment would not ignore the error.
// This is because the ignore comment would need to be placed before the error offset, which is not possible.
if error_offset == section_offset && message.span().end == section_offset {
return DiagnosticReport { diagnostic, fixed_content };
}

let fixed_content = add_ignore_fixes(
fixed_content,
&message.error.code,
Expand Down Expand Up @@ -265,6 +273,9 @@ fn disable_for_this_line(
let whitespace_range = {
let start = insert_offset as usize;
let end = error_offset as usize;

// make sure that end is at least start to avoid panic
let end = end.max(start);
let slice = &bytes[start..end];
let whitespace_len = slice.iter().take_while(|c| matches!(c, b' ' | b'\t')).count();
&slice[..whitespace_len]
Expand Down Expand Up @@ -608,6 +619,21 @@ mod test {
assert_eq!(fix.range.start.character, 0);
}

#[test]
fn disable_for_this_line_section_offset_start() {
// Test framework file where error is exactly at section offset
let source = "<script>\nconsole.log('hello');\n</script>";
let rope = Rope::from_str(source);
let section_offset = 8; // At the \n after "<script>"
let error_offset = 8; // Error exactly at section offset
let fix =
super::disable_for_this_line("no-console", error_offset, section_offset, &rope, source);

assert_eq!(fix.code, "// oxlint-disable-next-line no-console\n");
assert_eq!(fix.range.start.line, 1);
assert_eq!(fix.range.start.character, 0);
}

fn assert_position(source: &str, offset: u32, expected: (u32, u32)) {
let position = offset_to_position(&Rope::from_str(source), offset, source);
assert_eq!(position.line, expected.0);
Expand Down
10 changes: 10 additions & 0 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,14 @@ mod test {
);
tester.test_and_snapshot_single_file("index.js");
}

// https://github.com/oxc-project/oxc/issues/14565
#[test]
fn test_issue_14565() {
let tester = Tester::new(
"fixtures/linter/issue_14565",
Some(LintOptions { run: Run::OnSave, ..Default::default() }),
);
tester.test_and_snapshot_single_file("foo-bar.astro");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: crates/oxc_language_server/src/tester.rs
---
##########
file: fixtures/linter/issue_14565/foo-bar.astro
----------

code: "eslint-plugin-unicorn(filename-case)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/unicorn/filename-case.html"
message: "Filename should be in snake case, or pascal case\nhelp: Rename the file to 'foo_bar.astro', or 'FooBar.astro'"
range: Range { start: Position { line: 0, character: 3 }, end: Position { line: 0, character: 3 } }
related_information[0].message: ""
related_information[0].location.uri: "file://<variable>/fixtures/linter/issue_14565/foo-bar.astro"
related_information[0].location.range: Range { start: Position { line: 0, character: 3 }, end: Position { line: 0, character: 3 } }
severity: Some(Error)
source: Some("oxc")
tags: None
fixed: None
Loading