Skip to content

Commit

Permalink
Merge branch 'main' into async_method
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Jan 11, 2024
2 parents 3482938 + 7042ef0 commit 0ccbf36
Show file tree
Hide file tree
Showing 29 changed files with 679 additions and 311 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

### CLI

- Fix [#1512](https://github.com/biomejs/biome/issues/1512) by skipping verbose diagnostics from the count. Contributed by @ematipico
- Don't handle CSS files, the formatter isn't ready yet. Contributed by @ematipico

### Configuration

### Editors
Expand All @@ -24,6 +27,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

- Fix [#1406](https://github.com/biomejs/biome/issues/1406). Ensure comments before the `async` keyword are placed before it. Contributed by @ah-yu

- Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep

### JavaScript APIs

### Linter
Expand Down Expand Up @@ -63,9 +68,9 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

- Fix [#1335](https://github.com/biomejs/biome/issues/1335). [noUselessFragments](https://biomejs.dev/linter/rules/no-useless-fragments/) now ignores code action on component props when the fragment is empty. Contributed by @vasucp1207

- [useConsistentArrayType](https://biomejs.dev/rules/use-consistent-array-type) was accidentally placed in the `style` rule group instead of the `nursery` group. It is now correctly placed under `nursery`.
- [useConsistentArrayType](https://biomejs.dev/linter/rules/use-consistent-array-type) was accidentally placed in the `style` rule group instead of the `nursery` group. It is now correctly placed under `nursery`.

- Fix [#1483](https://github.com/biomejs/biome/issues/1483). [useConsistentArrayType](https://biomejs.dev/rules/use-consistent-array-type) now correctly handles its option. Contributed by @Conaclos
- Fix [#1483](https://github.com/biomejs/biome/issues/1483). [useConsistentArrayType](https://biomejs.dev/linter/rules/use-consistent-array-type) now correctly handles its option. Contributed by @Conaclos

- Fix [#1502](https://github.com/biomejs/biome/issues/1502). [useArrowFunction](https://biomejs.dev/rules/) now correctly handle functions that return a (comma) sequence expression. Contributed by @Conaclos

Expand All @@ -83,6 +88,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
+ f(() => (0, 1), "")
```

- Fix [#1473](https://github.com/biomejs/biome/issues/1473): [useHookAtTopLevel](https://biomejs.dev/linter/rules/use-hook-at-top-level/) now correctly handles React components and hooks that are nested inside other functions. Contributed by @arendjr


## 1.5.0 (2024-01-08)

Expand Down
121 changes: 60 additions & 61 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use biome_service::{
};
use crossbeam::channel::{unbounded, Receiver, Sender};
use rustc_hash::FxHashSet;
use std::sync::atomic::AtomicU64;
use std::{
ffi::OsString,
io,
Expand Down Expand Up @@ -246,10 +247,10 @@ struct DiagnosticsPrinter<'ctx> {
/// Execution of the traversal
execution: &'ctx Execution,
/// The maximum number of diagnostics the console thread is allowed to print
max_diagnostics: u16,
max_diagnostics: u64,
/// The approximate number of diagnostics the console will print before
/// folding the rest into the "skipped diagnostics" counter
remaining_diagnostics: AtomicU16,
remaining_diagnostics: AtomicU64,
/// Mutable reference to a boolean flag tracking whether the console thread
/// printed any error-level message
errors: AtomicUsize,
Expand All @@ -260,18 +261,23 @@ struct DiagnosticsPrinter<'ctx> {
verbose: bool,
/// The diagnostic level the console thread should print
diagnostic_level: Severity,

not_printed_diagnostics: AtomicU64,
printed_diagnostics: AtomicU64,
}

impl<'ctx> DiagnosticsPrinter<'ctx> {
fn new(execution: &'ctx Execution) -> Self {
Self {
errors: AtomicUsize::new(0),
warnings: AtomicUsize::new(0),
remaining_diagnostics: AtomicU16::new(0),
remaining_diagnostics: AtomicU64::new(0),
execution,
diagnostic_level: Severity::Hint,
verbose: false,
max_diagnostics: 20,
not_printed_diagnostics: AtomicU64::new(0),
printed_diagnostics: AtomicU64::new(0),
}
}

Expand All @@ -281,7 +287,7 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
}

fn with_max_diagnostics(mut self, value: u16) -> Self {
self.max_diagnostics = value;
self.max_diagnostics = value as u64;
self
}

Expand All @@ -298,15 +304,45 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
self.warnings.load(Ordering::Relaxed)
}

/// Checks if the diagnostic we received from the thread should be considered or not. Logic:
/// - it should not be considered if its severity level is lower than the one provided via CLI;
/// - it should not be considered if it's a verbose diagnostic and the CLI **didn't** request a `--verbose` option.
fn should_skip_diagnostic(&self, severity: Severity, diagnostic_tags: DiagnosticTags) -> bool {
if severity < self.diagnostic_level {
return true;
}

if diagnostic_tags.is_verbose() && !self.verbose {
return true;
}

false
}

/// Count the diagnostic, and then returns a boolean that tells if it should be printed
fn should_print(&self) -> bool {
let printed_diagnostics = self.printed_diagnostics.load(Ordering::Relaxed);
let should_print = printed_diagnostics < self.max_diagnostics;
if should_print {
self.printed_diagnostics.fetch_add(1, Ordering::Relaxed);
self.remaining_diagnostics.store(
self.max_diagnostics.saturating_sub(printed_diagnostics),
Ordering::Relaxed,
);
} else {
self.not_printed_diagnostics.fetch_add(1, Ordering::Relaxed);
}

should_print
}

fn run(
&self,
receiver: Receiver<Message>,
interner: Receiver<PathBuf>,
console: &'ctx mut dyn Console,
) {
let mut paths: FxHashSet<String> = FxHashSet::default();
let mut printed_diagnostics: u16 = 0;
let mut not_printed_diagnostics = 0;
let mut total_skipped_suggested_fixes = 0;

let mut diagnostics_to_print = vec![];
Expand All @@ -322,27 +358,18 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
Message::ApplyError(error) => {
// *errors += 1;
self.errors.fetch_add(1, Ordering::Relaxed);
if error.severity() < self.diagnostic_level {
if self.should_skip_diagnostic(error.severity(), error.tags()) {
continue;
}
let should_print = printed_diagnostics < self.max_diagnostics;
if should_print {
printed_diagnostics += 1;
self.remaining_diagnostics.store(
self.max_diagnostics.saturating_sub(printed_diagnostics),
Ordering::Relaxed,
);
} else {
not_printed_diagnostics += 1;
}
let should_print = self.should_print();
if self.execution.should_report_to_terminal() && should_print {
diagnostics_to_print.push(Error::from(error));
}
}

Message::Error(mut err) => {
let location = err.location();
if err.severity() < self.diagnostic_level {
if self.should_skip_diagnostic(err.severity(), err.tags()) {
continue;
}
if err.severity() == Severity::Warning {
Expand Down Expand Up @@ -376,16 +403,7 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
}
}

let should_print = printed_diagnostics < self.max_diagnostics;
if should_print {
printed_diagnostics += 1;
self.remaining_diagnostics.store(
self.max_diagnostics.saturating_sub(printed_diagnostics),
Ordering::Relaxed,
);
} else {
not_printed_diagnostics += 1;
}
let should_print = self.should_print();

if self.execution.should_report_to_terminal() && should_print {
diagnostics_to_print.push(err);
Expand All @@ -398,13 +416,14 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
diagnostics,
skipped_diagnostics,
} => {
not_printed_diagnostics += skipped_diagnostics;
self.not_printed_diagnostics
.fetch_add(skipped_diagnostics, Ordering::Relaxed);

// is CI mode we want to print all the diagnostics
if self.execution.is_ci() {
for diag in diagnostics {
let severity = diag.severity();
if severity < self.diagnostic_level {
if self.should_skip_diagnostic(severity, diag.tags()) {
continue;
}

Expand All @@ -421,29 +440,17 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
} else {
for diag in diagnostics {
let severity = diag.severity();
if severity < self.diagnostic_level {
if self.should_skip_diagnostic(severity, diag.tags()) {
continue;
}
if severity == Severity::Error {
self.errors.fetch_add(1, Ordering::Relaxed);

// *errors += 1;
}
if severity == Severity::Warning {
// *warnings += 1;
self.warnings.fetch_add(1, Ordering::Relaxed);
}

let should_print = printed_diagnostics < self.max_diagnostics;
if should_print {
printed_diagnostics += 1;
self.remaining_diagnostics.store(
self.max_diagnostics.saturating_sub(printed_diagnostics),
Ordering::Relaxed,
);
} else {
not_printed_diagnostics += 1;
}
let should_print = self.should_print();

if self.execution.should_report_to_terminal() && should_print {
let diag =
Expand Down Expand Up @@ -472,20 +479,11 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
Severity::Hint
};

if severity < self.diagnostic_level {
if self.should_skip_diagnostic(severity, DiagnosticTags::empty()) {
continue;
}

let should_print = printed_diagnostics < self.max_diagnostics;
if should_print {
printed_diagnostics += 1;
self.remaining_diagnostics.store(
self.max_diagnostics.saturating_sub(printed_diagnostics),
Ordering::Relaxed,
);
} else {
not_printed_diagnostics += 1;
}
let should_print = self.should_print();

if self.execution.should_report_to_terminal() && should_print {
if self.execution.is_ci() {
Expand Down Expand Up @@ -565,16 +563,17 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {

if self.execution.is_check() && total_skipped_suggested_fixes > 0 {
console.log(markup! {
<Warn>"Skipped "{total_skipped_suggested_fixes}" suggested fixes.\n"</Warn>
<Info>"If you wish to apply the suggested (unsafe) fixes, use the command "<Emphasis>"biome check --apply-unsafe\n"</Emphasis></Info>
})
<Warn>"Skipped "{total_skipped_suggested_fixes}" suggested fixes.\n"</Warn>
<Info>"If you wish to apply the suggested (unsafe) fixes, use the command "<Emphasis>"biome check --apply-unsafe\n"</Emphasis></Info>
})
}

let not_printed_diagnostics = self.not_printed_diagnostics.load(Ordering::Relaxed);
if !self.execution.is_ci() && not_printed_diagnostics > 0 {
console.log(markup! {
<Warn>"The number of diagnostics exceeds the number allowed by Biome.\n"</Warn>
<Info>"Diagnostics not shown: "</Info><Emphasis>{not_printed_diagnostics}</Emphasis><Info>"."</Info>
})
<Warn>"The number of diagnostics exceeds the number allowed by Biome.\n"</Warn>
<Info>"Diagnostics not shown: "</Info><Emphasis>{not_printed_diagnostics}</Emphasis><Info>"."</Info>
})
}
}
}
Expand Down
72 changes: 70 additions & 2 deletions crates/biome_cli/tests/cases/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::run_cli;
use crate::snap_test::{assert_cli_snapshot, SnapshotPayload};
use crate::{run_cli, UNFORMATTED};
use biome_console::{BufferConsole, LogLevel};
use biome_fs::MemoryFileSystem;
use biome_service::DynRef;
use bpaf::Args;
use std::path::Path;
use std::path::{Path, PathBuf};

const TEST_CONTENTS: &str = "debugger;";

Expand Down Expand Up @@ -69,3 +69,71 @@ fn logs_the_appropriate_messages_according_to_set_diagnostics_level() {
result,
));
}

#[test]
fn max_diagnostics_no_verbose() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

for i in 0..10 {
let file_path = PathBuf::from(format!("src/folder_{i}/package.json"));
fs.insert(file_path, "{}".as_bytes());
}
let file_path = PathBuf::from("src/file.js".to_string());
fs.insert(file_path, UNFORMATTED.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("ci"), ("--max-diagnostics"), ("10"), ("src")].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

for i in 0..10 {
let file_path = PathBuf::from(format!("src/folder_{i}/package.json"));
fs.remove(Path::new(&file_path));
}

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"max_diagnostics_no_verbose",
fs,
console,
result,
));
}

#[test]
fn max_diagnostics_verbose() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

for i in 0..8 {
let file_path = PathBuf::from(format!("src/folder_{i}/package.json"));
fs.insert(file_path, "{}".as_bytes());
}
let file_path = PathBuf::from("src/file.js".to_string());
fs.insert(file_path, UNFORMATTED.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("ci"), ("--max-diagnostics=10"), "--verbose", ("src")].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

for i in 0..8 {
let file_path = PathBuf::from(format!("src/folder_{i}/package.json"));
fs.remove(Path::new(&file_path));
}

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"max_diagnostics_verbose",
fs,
console,
result,
));
}
2 changes: 2 additions & 0 deletions crates/biome_cli/tests/cases/overrides_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ fn does_include_file_with_different_overrides() {
}

#[test]
#[ignore = "Enable when we are ready to handle CSS files"]
fn does_include_file_with_different_languages() {
let mut console = BufferConsole::default();
let mut fs = MemoryFileSystem::default();
Expand Down Expand Up @@ -291,6 +292,7 @@ fn does_include_file_with_different_languages() {
}

#[test]
#[ignore = "Enable when we are ready to handle CSS files"]
fn does_include_file_with_different_languages_and_files() {
let mut console = BufferConsole::default();
let mut fs = MemoryFileSystem::default();
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ fn applies_custom_quote_style() {
}

#[test]
#[ignore = "Enable when we are ready to handle CSS files"]
fn applies_custom_css_quote_style() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
Expand Down
Loading

0 comments on commit 0ccbf36

Please sign in to comment.