Skip to content

Commit

Permalink
Merge branch 'main' into fix/biomejs#3298
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo-ebata authored Jul 20, 2024
2 parents c5c8013 + 1fa96f3 commit 8aeebc5
Show file tree
Hide file tree
Showing 108 changed files with 2,359 additions and 554 deletions.
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

34 changes: 31 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### CLI

#### Bug fixes

- When a `--reporter` is provided, and it's different from the default one, the value provided by via `--max-diagnostics` is ignored and **the limit is lifted**. Contributed by @ematipico

#### New features

- Add `--graphql-linter-enabled` option, to control whether the linter should enabled or not for GraphQL files. Contributed by @ematipico
- Add `--graphql-linter-enabled` option, to control whether the linter should be enabled or not for GraphQL files. Contributed by @ematipico
- The option `--max-diagnostics` now accept a `none` value, which lifts the limit of diagnostics shown. Contributed by @ematipico

### Configuration

Expand All @@ -40,6 +45,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Formatter

#### Bug fixes

- Keep the parentheses around `infer` declarations in type unions and type intersections ([#3419](https://github.com/biomejs/biome/issues/3419)). Contributed by @Conaclos

### JavaScript APIs

### Linter
Expand All @@ -48,7 +57,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Add support for GraphQL linting. Contributed by @ematipico
- Add [nursery/noDynamicNamespaceImportAccess](https://biomejs.dev/linter/no-dynamic-namespace-import-access/). Contributed by @minht11
- [noUndeclaredVariables](https://biomejs.dev/linter/rules/no-undeclared-variables/) n longer report a direct reference to an enum member ([#2974](https://github.com/biomejs/biome/issues/2974)).
- [noUndeclaredVariables](https://biomejs.dev/linter/rules/no-undeclared-variables/) no longer reports a direct reference to an enum member ([#2974](https://github.com/biomejs/biome/issues/2974)).

In the following code, the `A` reference is no longer reported as an undeclared variable.

Expand All @@ -62,6 +71,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
Contributed by @Conaclos

- Add [nursery/noIrregularWhitespace](https://biomejs.dev/linter/rules/no-irregular-whitespace). Contributed by @michellocana
- Add [nursery/useTrimStartEnd](https://biomejs.dev/linter/rules/use-trim-start-end/). Contributed by @chansuke

#### Enhancements

Expand Down Expand Up @@ -98,6 +108,24 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- Fix [[#3149](https://github.com/biomejs/biome/issues/3149)] crashes that occurred when applying the `noUselessFragments` unsafe fixes in certain scenarios. Contributed by @unvalley
- `noExcessiveNestedTestSuites`: Fix another edge case where the rule would alert on heavily nested zod schemas. Contributed by @dyc3

- `noExtraNonNullAssertion` no longer reports a single non-null assertion enclosed in parentheses ([#3352](https://github.com/biomejs/biome/issues/3352)). Contributed by @Conaclos

- `useAdjacentOverloadSignatures` no longer reports a `#private` class member and a public class member that share the same name ([#3309](https://github.com/biomejs/biome/issues/3309)).

The following code is no longer reported:

```js
class C {
#f() {}
g() {}
f() {}
}
```

Contributed by @Conaclos

- [useNamingConvention](https://biomejs.dev/linter/rules/use-naming-convention/) now accepts applying custom convention on abstract classes. Contributed by @Conaclos

### Parser

#### Bug fixes
Expand All @@ -111,7 +139,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
}
}
```
- Fix [#3410](https://github.com/biomejs/biome/issues/3410) by correctly parsing break statements containing keywords.
- Fix [#3410](https://github.com/biomejs/biome/issues/3410) by correctly parsing break statements containing keywords.
```js
out: while (true) {
break out;
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,12 @@ pub enum Never {}

/// Type alias of [ops::ControlFlow] with the `B` generic type defaulting to [Never]
///
/// By default the analysis loop never breaks, so it behaves mostly like
/// By default, the analysis loop never breaks, so it behaves mostly like
/// `let b = loop {};` and has a "break type" of `!` (the `!` type isn't stable
/// yet so I'm using an empty enum instead but they're identical for this
/// yet, so I'm using an empty enum instead, but they're identical for this
/// purpose)
///
/// In practice it's not really a `loop` but a `for` because it's iterating on
/// In practice, it's not really a `loop` but a `for` because it's iterating on
/// all nodes in the syntax tree, so when it reaches the end of the iterator
/// the loop will exit but without producing a value of type `B`: for this
/// reason the `analyze` function returns an `Option<B>` that's set to
Expand Down
82 changes: 78 additions & 4 deletions crates/biome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ pub struct CliOptions {
#[bpaf(long("config-path"), argument("PATH"), optional)]
pub config_path: Option<String>,

/// Cap the amount of diagnostics displayed.
/// Cap the amount of diagnostics displayed. When `none` is provided, the limit is lifted.
#[bpaf(
long("max-diagnostics"),
argument("NUMBER"),
fallback(20),
argument("none|<NUMBER>"),
fallback(MaxDiagnostics::default()),
display_fallback
)]
pub max_diagnostics: u16,
pub max_diagnostics: MaxDiagnostics,

/// Skip over files containing syntax errors instead of emitting an error diagnostic.
#[bpaf(long("skip-errors"), switch)]
Expand Down Expand Up @@ -133,6 +133,12 @@ pub enum CliReporter {
Summary,
}

impl CliReporter {
pub(crate) const fn is_default(&self) -> bool {
matches!(self, Self::Default)
}
}

impl FromStr for CliReporter {
type Err = String;

Expand Down Expand Up @@ -162,3 +168,71 @@ impl Display for CliReporter {
}
}
}

#[derive(Debug, Clone, Copy, Bpaf)]
pub enum MaxDiagnostics {
None,
Limit(u32),
}

impl MaxDiagnostics {
pub fn ok(&self) -> Option<u32> {
match self {
MaxDiagnostics::None => None,
MaxDiagnostics::Limit(value) => Some(*value),
}
}
}

impl Default for MaxDiagnostics {
fn default() -> Self {
Self::Limit(20)
}
}

impl Display for MaxDiagnostics {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
MaxDiagnostics::None => {
write!(f, "none")
}
MaxDiagnostics::Limit(value) => {
write!(f, "{value}")
}
}
}
}

impl FromStr for MaxDiagnostics {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"none" => Ok(MaxDiagnostics::None),
_ => {
if let Ok(value) = s.parse::<u32>() {
Ok(MaxDiagnostics::Limit(value))
} else {
Err(format!("Invalid value provided. Provide 'none' to lift the limit, or a number between 0 and {}.", u32::MAX))
}
}
}
}
}

impl From<MaxDiagnostics> for u64 {
fn from(value: MaxDiagnostics) -> Self {
match value {
MaxDiagnostics::None => u64::MAX,
MaxDiagnostics::Limit(value) => value as u64,
}
}
}

impl From<MaxDiagnostics> for u32 {
fn from(value: MaxDiagnostics) -> Self {
match value {
MaxDiagnostics::None => u32::MAX,
MaxDiagnostics::Limit(value) => value,
}
}
}

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

13 changes: 10 additions & 3 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use biome_service::workspace::{
use std::ffi::OsString;
use std::fmt::{Display, Formatter};
use std::path::{Path, PathBuf};
use tracing::info;

/// Useful information during the traversal of files and virtual content
#[derive(Debug, Clone)]
Expand All @@ -37,7 +38,7 @@ pub struct Execution {
traversal_mode: TraversalMode,

/// The maximum number of diagnostics that can be printed in console
max_diagnostics: u16,
max_diagnostics: u32,
}

impl Execution {
Expand Down Expand Up @@ -281,7 +282,7 @@ impl Execution {
&self.traversal_mode
}

pub(crate) fn get_max_diagnostics(&self) -> u16 {
pub(crate) fn get_max_diagnostics(&self) -> u32 {
self.max_diagnostics
}

Expand Down Expand Up @@ -395,7 +396,13 @@ pub fn execute_mode(
cli_options: &CliOptions,
paths: Vec<OsString>,
) -> Result<(), CliDiagnostic> {
execution.max_diagnostics = cli_options.max_diagnostics;
// If a custom reporter was provided, let's lift the limit so users can see all of them
execution.max_diagnostics = if cli_options.reporter.is_default() {
cli_options.max_diagnostics.into()
} else {
info!("Removing the limit of --max-diagnostics, because of a reporter different from the default one: {}", cli_options.reporter);
u32::MAX
};

// don't do any traversal if there's some content coming from stdin
if let Some(stdin) = execution.as_stdin_file() {
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/process_file/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) fn format_with_guard<'ctx>(
.guard()
.pull_diagnostics(
RuleCategoriesBuilder::default().with_syntax().build(),
max_diagnostics.into(),
max_diagnostics,
Vec::new(),
Vec::new(),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/process_file/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn lint_with_guard<'ctx>(
.with_syntax()
.with_lint()
.build(),
max_diagnostics.into(),
max_diagnostics,
only,
skip,
)
Expand Down
10 changes: 5 additions & 5 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
panic::catch_unwind,
path::{Path, PathBuf},
sync::{
atomic::{AtomicU16, AtomicUsize, Ordering},
atomic::{AtomicUsize, Ordering},
Once,
},
thread,
Expand Down Expand Up @@ -74,7 +74,7 @@ pub(crate) fn traverse(
let workspace = &*session.app.workspace;

let max_diagnostics = execution.get_max_diagnostics();
let remaining_diagnostics = AtomicU16::new(max_diagnostics);
let remaining_diagnostics = AtomicU32::new(max_diagnostics);

let printer = DiagnosticsPrinter::new(execution)
.with_verbose(cli_options.verbose)
Expand Down Expand Up @@ -212,8 +212,8 @@ impl<'ctx> DiagnosticsPrinter<'ctx> {
self
}

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

Expand Down Expand Up @@ -482,7 +482,7 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
pub(crate) messages: Sender<Message>,
/// The approximate number of diagnostics the console will print before
/// folding the rest into the "skipped diagnostics" counter
pub(crate) remaining_diagnostics: &'ctx AtomicU16,
pub(crate) remaining_diagnostics: &'ctx AtomicU32,
}

impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
Expand Down
51 changes: 51 additions & 0 deletions crates/biome_cli/tests/cases/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,54 @@ import { FC, memo, useCallback } from "react";
result,
));
}

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

for i in 0..u8::MAX {
let file_path = PathBuf::from(format!("src/file_{i}.js"));
fs.insert(file_path, UNFORMATTED.as_bytes());
}

let file_path = PathBuf::from("file.js".to_string());
fs.insert(
file_path.clone(),
"debugger;".repeat(u8::MAX as usize * 2).as_bytes(),
);

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(
[
("ci"),
("--max-diagnostics"),
("none"),
file_path.as_os_str().to_str().unwrap(),
]
.as_slice(),
),
);

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

for i in 0..u8::MAX {
let file_path = PathBuf::from(format!("src/file_{i}.js"));
fs.remove(&file_path);
}

let messages = &console.out_buffer;

let errors = format!("{}", u8::MAX as usize * 2 + 1);

assert!(messages
.iter()
.filter(|m| m.level == LogLevel::Log)
.any(|m| {
let content = format!("{:?}", m.content);

content.contains(&errors)
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ Global options applied to all commands
--config-path=PATH Set the file path to the configuration file, or the directory path to find
`biome.json` or `biome.jsonc`. If used, it disables the default configuration
file resolution.
--max-diagnostics=NUMBER Cap the amount of diagnostics displayed.
--max-diagnostics=<none|<NUMBER>> Cap the amount of diagnostics displayed. When `none` is provided,
the limit is lifted.
[default: 20]
--skip-errors Skip over files containing syntax errors instead of emitting an error diagnostic.
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ Global options applied to all commands
--config-path=PATH Set the file path to the configuration file, or the directory path to find
`biome.json` or `biome.jsonc`. If used, it disables the default configuration
file resolution.
--max-diagnostics=NUMBER Cap the amount of diagnostics displayed.
--max-diagnostics=<none|<NUMBER>> Cap the amount of diagnostics displayed. When `none` is provided,
the limit is lifted.
[default: 20]
--skip-errors Skip over files containing syntax errors instead of emitting an error diagnostic.
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Global options applied to all commands
--config-path=PATH Set the file path to the configuration file, or the directory path to find
`biome.json` or `biome.jsonc`. If used, it disables the default configuration
file resolution.
--max-diagnostics=NUMBER Cap the amount of diagnostics displayed.
--max-diagnostics=<none|<NUMBER>> Cap the amount of diagnostics displayed. When `none` is provided,
the limit is lifted.
[default: 20]
--skip-errors Skip over files containing syntax errors instead of emitting an error diagnostic.
--no-errors-on-unmatched Silence errors that would be emitted in case no files were processed
Expand Down
Loading

0 comments on commit 8aeebc5

Please sign in to comment.