Skip to content

Commit

Permalink
Make JS Lints have lower severity (#8837)
Browse files Browse the repository at this point in the history
This hides them from Next.js for now

I'll add a test case for Next.js as well

Closes PACK-2877
  • Loading branch information
mischnic authored Jul 31, 2024
1 parent d3db2f5 commit 727d5e0
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 39 deletions.
32 changes: 21 additions & 11 deletions crates/turbopack-swc-utils/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ impl Emitter for IssueEmitter {
DiagnosticId::Error(s) => format!("error {s}").into(),
DiagnosticId::Lint(s) => format!("lint {s}").into(),
});
let is_lint = db
.code
.as_ref()
.map_or(false, |d| matches!(d, DiagnosticId::Lint(_)));

let severity = (if is_lint {
IssueSeverity::Suggestion
} else {
match level {
Level::Bug => IssueSeverity::Bug,
Level::Fatal | Level::PhaseFatal => IssueSeverity::Fatal,
Level::Error => IssueSeverity::Error,
Level::Warning => IssueSeverity::Warning,
Level::Note => IssueSeverity::Note,
Level::Help => IssueSeverity::Hint,
Level::Cancelled => IssueSeverity::Error,
Level::FailureNote => IssueSeverity::Note,
}
})
.cell();

let title;
if let Some(t) = self.title.as_ref() {
Expand All @@ -63,17 +83,7 @@ impl Emitter for IssueEmitter {
// TODO add other primary and secondary spans with labels as sub_issues

let issue = AnalyzeIssue {
severity: match level {
Level::Bug => IssueSeverity::Bug,
Level::Fatal | Level::PhaseFatal => IssueSeverity::Fatal,
Level::Error => IssueSeverity::Error,
Level::Warning => IssueSeverity::Warning,
Level::Note => IssueSeverity::Note,
Level::Help => IssueSeverity::Hint,
Level::Cancelled => IssueSeverity::Error,
Level::FailureNote => IssueSeverity::Note,
}
.cell(),
severity,
source_ident: self.source.ident(),
title: Vc::cell(title),
message: StyledString::Text(message.into()).cell(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:12:0 lint TP1001 import(FreeVar(Math)["random"]()) is very dynamic
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:12:0 lint TP1001 import(FreeVar(Math)["random"]()) is very dynamic

8 | child_process.spawnSync("node", [unknown, unknown]);
9 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:10:0 lint TP1002 require(FreeVar(Math)["random"]()) is very dynamic
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:10:0 lint TP1002 require(FreeVar(Math)["random"]()) is very dynamic

6 | child_process.spawnSync(unknown);
7 | child_process.spawnSync("node", unknown);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:15:0 lint TP1004 fs.readFileSync(FreeVar(Math)["random"]()) is very dynamic

11 |
12 | import(unknown);
13 |
14 | fs.readFileSync(unknown);
+ v-------------------v
15 + readFileSync(unknown);
+ ^-------------------^
16 |
17 | new URL(unknown, import.meta.url);
18 |
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:14:0 lint TP1004 fs.readFileSync(FreeVar(Math)["random"]()) is very dynamic
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:14:0 lint TP1004 fs.readFileSync(FreeVar(Math)["random"]()) is very dynamic

10 | require(unknown);
11 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:6:0 lint TP1005 child_process.spawnSync(FreeVar(Math)["random"]()) is very dynamic
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:6:0 lint TP1005 child_process.spawnSync(FreeVar(Math)["random"]()) is very dynamic

2 | import fs, { readFileSync } from "node:fs";
3 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:8:0 lint TP1005 child_process.spawnSync(
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:8:0 lint TP1005 child_process.spawnSync(

4 | const unknown = Math.random();
5 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:7:0 lint TP1005 child_process.spawnSync("node", FreeVar(Math)["random"]()) is very dynamic
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:7:0 lint TP1005 child_process.spawnSync("node", FreeVar(Math)["random"]()) is very dynamic

3 |
4 | const unknown = Math.random();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
suggestion - [analysis] [project]/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js /crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/input/index.js:17:0 lint TP1201 new URL(Variable(unknown##2), import.meta.url) is very dynamic

13 |
14 | fs.readFileSync(unknown);
15 | readFileSync(unknown);
16 |
+ v-------------------------------v
17 + new URL(unknown, import.meta.url);
+ ^-------------------------------^
18 |

This file was deleted.

0 comments on commit 727d5e0

Please sign in to comment.