Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .changeset/huge-walls-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
"@biomejs/biome": minor
---

Added a new linter configuration called `preset`. With the new option, users can enable different kinds of rules at once.

The following presets are available:
- `"recommended"`: it enables all Biome-recommended rules, or recommended rules of a group;
- `"all"`: it enables all Biome rules, or enables all rules of a group;
- `"none"`: it disables all Biome rules, or disable all rules of a group.
Comment thread
coderabbitai[bot] marked this conversation as resolved.

You can enable recommended rules:

```json
{
"linter": {
"rules": {
"preset": "recommended"
}
}
}
```

You can enable **all rules** at once:

```json5
{
"linter": {
"rules": {
"preset": "all" // enables all rules
}
}
}
```

Or enable all rules for a group:
```json5
{
"linter": {
"rules": {
"style": {
"preset": "all" // enables all rules in the style group
},
}
}
}
```

This new option, however, doesn't affect how nursery rules work. Nursery rules must be enabled singularly, due to their nature.

This new option is meant to replace `recommended`, so make sure to run the `migrate` command.


1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub use crate::registry::{
};
pub use crate::rule::{
CategoryLanguage, FixKind, GroupCategory, GroupLanguage, Rule, RuleAction, RuleDiagnostic,
RuleDomain, RuleGroup, RuleMeta, RuleMetadata, RuleSource, RuleSourceKind, RuleSourceWithKind,
SuppressAction,
RuleDomain, RuleGroup, RuleMeta, RuleMetadata, RulePreset, RuleSource, RuleSourceKind,
RuleSourceWithKind, SuppressAction,
};
pub use crate::services::{
ExtendedConfigurationProvider, FromServices, ServiceBag, ServicesDiagnostic,
Expand Down
38 changes: 38 additions & 0 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct RuleMetadata {
/// Use this field to tag the rule as being worked, which means the rule is still far from being completed.
/// Possible bugs should be reported in that issue.
pub issue_number: Option<&'static str>,
/// A preset this rule belongs to.
pub rule_presets: &'static [RulePreset],
Comment thread
ematipico marked this conversation as resolved.
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
Expand Down Expand Up @@ -814,6 +816,7 @@ impl RuleMetadata {
severity: Severity::Information,
domains: &[],
issue_number: None,
rule_presets: &[],
}
}

Expand Down Expand Up @@ -857,6 +860,11 @@ impl RuleMetadata {
self
}

pub const fn rule_presets(mut self, rule_presets: &'static [RulePreset]) -> Self {
self.rule_presets = rule_presets;
self
}

pub fn applicability(&self) -> Applicability {
self.fix_kind
.try_into()
Expand Down Expand Up @@ -1760,3 +1768,33 @@ pub struct SuppressAction<L: Language> {
pub message: MarkupBuf,
pub mutation: BatchMutation<L>,
}

// NOTE: you must update the JSON schema representation of [biome_configuration::PresetConfig] every time you add a new variant
/// A preset configuration for enabling a set of rules.
#[cfg_attr(
feature = "serde",
derive(
serde::Serialize,
serde::Deserialize,
biome_deserialize_macros::Deserializable,
biome_deserialize_macros::Merge
)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum RulePreset {
/// A set of rules that are enabled by default.
Recommended,
}

impl FromStr for RulePreset {
type Err = &'static str;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"recommended" => Ok(Self::Recommended),
_ => Err("Invalid rule preset."),
}
}
}
20 changes: 17 additions & 3 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use biome_console::{
markup,
};
use biome_diagnostics::termcolor::{ColorChoice, WriteColor};
use biome_diagnostics::{PrintDescription, termcolor};
use biome_diagnostics::{PrintDescription, Severity, termcolor};
use biome_flags::biome_env;
use biome_fs::OsFileSystem;
use biome_resolver::FsWithResolverProxy;
Expand Down Expand Up @@ -230,6 +230,12 @@ impl Display for RageConfiguration<'_> {
.unwrap();

let status = if !diagnostics.is_empty() {
let max_severity = diagnostics
.iter()
.map(|d| d.severity())
.max()
.unwrap_or_default();

for diagnostic in diagnostics {
(markup! {
{KeyValuePair::new("Error", markup!{
Expand All @@ -238,9 +244,17 @@ impl Display for RageConfiguration<'_> {
})
.fmt(fmt)?;
}
markup!(<Dim>"Loaded with errors"</Dim>)
match max_severity {
Severity::Hint | Severity::Information => {
markup!(<Dim>"Loaded successfully."</Dim>)
}
Severity::Warning => markup!(<Dim>"Loaded with warnings."</Dim>),
Severity::Fatal | Severity::Error => {
markup!(<Dim>"Loaded with errors."</Dim>)
}
}
} else {
markup!(<Dim>"Loaded successfully"</Dim>)
markup!(<Dim>"Loaded successfully."</Dim>)
};

let config_path = file_path.as_ref().map_or_else(
Expand Down
5 changes: 3 additions & 2 deletions crates/biome_cli/src/execute/migrate/eslint_to_biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{
};
use biome_analyze::RuleSource;
use biome_configuration::analyzer::SeverityOrGroup;
use biome_configuration::analyzer::presets::PresetConfig;
use biome_configuration::{self as biome_config};
use biome_console::fmt::Display;
use biome_console::markup;
Expand Down Expand Up @@ -552,7 +553,7 @@ impl eslint_eslint::FlatConfigData {
};
biome_config.javascript = Some(js_config)
}
rules.recommended = Some(false);
rules.preset = Some(PresetConfig::None);
linter.rules = Some(rules);
let includes =
to_biome_includes(&global_config_object.files, &global_config_object.ignores);
Expand All @@ -579,7 +580,7 @@ impl eslint_eslint::LegacyConfigData {
}
let mut linter = biome_config::LinterConfiguration::default();
let mut rules = self.rules.into_biome_rules(options, &mut results);
rules.recommended = Some(false);
rules.preset = Some(PresetConfig::None);
linter.rules = Some(rules);
let includes = to_biome_includes(&[] as &[&str], self.ignore_patterns.as_slice());
linter.includes = (!includes.is_empty()).then_some(includes);
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod overrides_formatter;
mod overrides_linter;
mod overrides_max_file_size;
mod overrides_organize_imports;
mod preset;
mod protected_files;
mod regression_tests;
mod reporter_checkstyle;
Expand Down
Loading
Loading