Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Jan 6, 2025
2 parents 93d1d43 + 2505123 commit 4e9fbc3
Show file tree
Hide file tree
Showing 24 changed files with 500 additions and 110 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"instanceof",
"isnan",
"itertools",
"jsxmember",
"kosaraju",
"msvc",
"musleabihf",
Expand Down
32 changes: 32 additions & 0 deletions __test__/check_oxlint/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`No phantom dependencies 1`] = `
[
{
"code": "eslint-plugin-unicorn(no-instanceof-array)",
"fileName": "index.js",
"help": "The instanceof Array check doesn't work across realms/contexts, for example, frames/windows in browsers or the vm module in Node.js.",
"labels": [
{
"loc": {
"end": {
"col": 27,
"line": 2,
},
"start": {
"col": 5,
"line": 2,
},
},
"span": {
"length": 22,
"offset": 14,
},
},
],
"message": "Use \`Array.isArray()\` instead of \`instanceof Array\`.",
"severity": "error",
"url": "https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-instanceof-array.html",
},
]
`;
2 changes: 2 additions & 0 deletions __test__/check_oxlint/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 你好
if (param instanceof Array) console.log(456);
21 changes: 21 additions & 0 deletions __test__/check_oxlint/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect, test } from "vitest";
import { checkOxlint } from "../../index";
import { fileURLToPath } from "node:url";
import path from "node:path";
import { dirname } from "node:path";

const __filename = fileURLToPath(import.meta.url);

test("No phantom dependencies", async () => {
const cwd = path.resolve(dirname(__filename), "fixtures");
const res = await checkOxlint(
JSON.stringify({
rules: {
"unicorn/no-instanceof-array": "error",
},
}),
{ cwd },
);

console.log(res.at(0)?.labels);
});
22 changes: 17 additions & 5 deletions crates/check_oxlint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fmt::Display, rc::Rc, sync::Arc};

use beans::{Location, Span};
use napi_derive::napi;
use oxc_diagnostics::Severity;
use oxc_linter::{FixKind, LinterBuilder, Oxlintrc};
Expand All @@ -17,6 +18,7 @@ pub struct CheckOxlintLabelsSpan {
#[derive(Debug, Clone, Serialize)]
pub struct CheckOxlintLabelsResponse {
pub span: CheckOxlintLabelsSpan,
pub loc: Location,
}

#[napi(object)]
Expand Down Expand Up @@ -62,6 +64,8 @@ pub fn check_oxlint(
));
let semantic = Rc::new(semantic);

let source_text = semantic.source_text();

let diagnostics = linter.run(&path, semantic, module_record);

let responses = diagnostics
Expand All @@ -84,11 +88,19 @@ pub fn check_oxlint(
.as_ref()
.map(|v| {
v.iter()
.map(|l| CheckOxlintLabelsResponse {
span: CheckOxlintLabelsSpan {
offset: l.offset() as u32,
length: l.len() as u32,
},
.map(|l| {
let loc = Location::with_source(&source_text, Span {
start: l.offset() as u32,
end: l.offset() as u32 + l.len() as u32,
});

return CheckOxlintLabelsResponse {
span: CheckOxlintLabelsSpan {
offset: l.offset() as u32,
length: l.len() as u32,
},
loc,
};
})
.collect::<Vec<_>>()
})
Expand Down
10 changes: 10 additions & 0 deletions crates/check_oxlint/tests/snapshots/oxlint_test__console.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 0,
"length": 11
},
"loc": {
"start": {
"line": 1,
"col": 1
},
"end": {
"line": 1,
"col": 12
}
}
}
]
Expand Down
10 changes: 10 additions & 0 deletions crates/check_oxlint/tests/snapshots/oxlint_test__debugger.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 0,
"length": 9
},
"loc": {
"start": {
"line": 1,
"col": 1
},
"end": {
"line": 1,
"col": 10
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@ snapshot_kind: text
"span": {
"offset": 16,
"length": 6
},
"loc": {
"start": {
"line": 1,
"col": 17
},
"end": {
"line": 1,
"col": 23
}
}
},
{
"span": {
"offset": 24,
"length": 3
},
"loc": {
"start": {
"line": 1,
"col": 25
},
"end": {
"line": 1,
"col": 28
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 23,
"length": 44
},
"loc": {
"start": {
"line": 2,
"col": 10
},
"end": {
"line": 4,
"col": 3
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 12,
"length": 5
},
"loc": {
"start": {
"line": 1,
"col": 13
},
"end": {
"line": 1,
"col": 18
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 26,
"length": 3
},
"loc": {
"start": {
"line": 3,
"col": 3
},
"end": {
"line": 3,
"col": 6
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@ snapshot_kind: text
"span": {
"offset": 6,
"length": 1
},
"loc": {
"start": {
"line": 1,
"col": 7
},
"end": {
"line": 1,
"col": 8
}
}
},
{
"span": {
"offset": 11,
"length": 1
},
"loc": {
"start": {
"line": 2,
"col": 1
},
"end": {
"line": 2,
"col": 2
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 4,
"length": 8
},
"loc": {
"start": {
"line": 1,
"col": 5
},
"end": {
"line": 1,
"col": 13
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@ snapshot_kind: text
"span": {
"offset": 6,
"length": 1
},
"loc": {
"start": {
"line": 1,
"col": 7
},
"end": {
"line": 1,
"col": 8
}
}
},
{
"span": {
"offset": 13,
"length": 1
},
"loc": {
"start": {
"line": 2,
"col": 1
},
"end": {
"line": 2,
"col": 2
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 4,
"length": 13
},
"loc": {
"start": {
"line": 1,
"col": 5
},
"end": {
"line": 1,
"col": 18
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 4,
"length": 4
},
"loc": {
"start": {
"line": 1,
"col": 5
},
"end": {
"line": 1,
"col": 9
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ snapshot_kind: text
"span": {
"offset": 7,
"length": 8
},
"loc": {
"start": {
"line": 2,
"col": 1
},
"end": {
"line": 2,
"col": 9
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@ snapshot_kind: text
"span": {
"offset": 11,
"length": 3
},
"loc": {
"start": {
"line": 2,
"col": 2
},
"end": {
"line": 2,
"col": 5
}
}
},
{
"span": {
"offset": 21,
"length": 3
},
"loc": {
"start": {
"line": 3,
"col": 2
},
"end": {
"line": 3,
"col": 5
}
}
}
]
Expand Down
Loading

0 comments on commit 4e9fbc3

Please sign in to comment.