Skip to content

Commit

Permalink
fix: do not panic linting files with UTF-8 BOM (#24136)
Browse files Browse the repository at this point in the history
Closes #24122
  • Loading branch information
dsherret authored and nathanwhit committed Jun 13, 2024
1 parent 5a72416 commit d2a8619
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ license = "MIT"
repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.39.0", features = ["transpiling"] }
deno_ast = { version = "=0.39.1", features = ["transpiling"] }
deno_core = { version = "0.284.0" }

deno_bench_util = { version = "0.149.0", path = "./bench_util" }
Expand Down
4 changes: 2 additions & 2 deletions cli/tools/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async fn lint_files(
deno_core::unsync::spawn(async move {
run_parallelized(paths, {
move |file_path| {
let file_text = fs::read_to_string(&file_path)?;
let file_text = deno_ast::strip_bom(fs::read_to_string(&file_path)?);

// don't bother rechecking this file if it didn't have any diagnostics before
if incremental_cache.is_file_same(&file_path, &file_text) {
Expand Down Expand Up @@ -510,7 +510,7 @@ fn lint_stdin(
linter
.lint_file(LintFileOptions {
specifier: specifier_from_file_path(file_path)?,
source_code: source_code.clone(),
source_code: deno_ast::strip_bom(source_code),
media_type: MediaType::TypeScript,
config,
})
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/lint/bom/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "lint mod.ts",
"exitCode": 1,
"output": "mod.out"
}
12 changes: 12 additions & 0 deletions tests/specs/lint/bom/mod.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[no-unused-vars]: `t` is never used
--> [WILDLINE]
|
4 | const t = 5;
| ^
= hint: If this is intentional, prefix it with an underscore like `_t`

docs: https://lint.deno.land/rules/no-unused-vars


Found 1 problem
Checked 1 file
4 changes: 4 additions & 0 deletions tests/specs/lint/bom/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// this file is saved as UTF8 with BOM
console.log("Hello, world!");

const t = 5;

0 comments on commit d2a8619

Please sign in to comment.