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,9 @@
{
"plugins": ["react"],
"categories": {
"correctness": "off"
},
"rules": {
"react/exhaustive-deps": "warn"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { useEffect } from 'react';

function Component() {
const emit = (event) => console.log(event);
const EVENTS = { CLEAR: 'clear' };

useEffect(() => {
emit(EVENTS.CLEAR);
// oxlint-disable-next-line exhaustive-deps
}, []);

return null;
}
11 changes: 11 additions & 0 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,17 @@ mod test {
Tester::new().with_cwd("fixtures/dot_folder".into()).test_and_snapshot(&[]);
}

#[test]
fn test_exhaustive_deps_disable_directive_issue_13311() {
// Test that exhaustive-deps diagnostics are reported at the dependency array
// so that disable directives work correctly
// Issue: https://github.com/oxc-project/oxc/issues/13311
let args = &["test.jsx"];
Tester::new()
.with_cwd("fixtures/exhaustive_deps_disable_directive_issue_13311".into())
.test_and_snapshot(args);
}

// ToDo: `tsgolint` does not support `big-endian`?
#[test]
#[cfg(not(target_endian = "big"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: test.jsx
working directory: fixtures/exhaustive_deps_disable_directive_issue_13311
----------
Found 0 warnings and 0 errors.
Finished in <variable>ms on 1 file using 1 threads.
----------
CLI result: LintSucceeded
----------
22 changes: 8 additions & 14 deletions crates/oxc_linter/src/fixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,14 @@ impl<'new> CloneIn<'new> for Message<'_> {
impl<'a> Message<'a> {
#[expect(clippy::cast_possible_truncation)] // for `as u32`
pub fn new(error: OxcDiagnostic, fixes: PossibleFixes<'a>) -> Self {
let (start, end) = if let Some(labels) = &error.labels {
let start = labels
.iter()
.min_by_key(|span| span.offset())
.map_or(0, |span| span.offset() as u32);
let end = labels
.iter()
.max_by_key(|span| span.offset() + span.len())
.map_or(0, |span| (span.offset() + span.len()) as u32);
(start, end)
} else {
(0, 0)
};
Self { error, span: Span::new(start, end), fixes, fixed: false }
let span = error
.labels
.as_ref()
.and_then(|labels| labels.iter().find(|span| span.primary()).or_else(|| labels.first()))
.map(|span| Span::new(span.offset() as u32, (span.offset() + span.len()) as u32))
.unwrap_or_default();

Self { error, span, fixes, fixed: false }
}

/// move the offset of all spans to the right
Expand Down
Loading