Skip to content

Commit

Permalink
feat: enable CSS linter and CSS formatter (#2790)
Browse files Browse the repository at this point in the history
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
  • Loading branch information
ematipico and Conaclos authored May 17, 2024
1 parent 96e5ab9 commit 2fb7d63
Show file tree
Hide file tree
Showing 43 changed files with 1,099 additions and 249 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- Add new command `biome clean`. Use this command to purge all the logs emitted by the Biome daemon. This command is really useful, because the Biome daemon tends
log many files and contents during its lifecycle. This means that if your editor is open for hours (or even days), the `biome-logs` folder could become quite heavy. Contributed by @ematipico

- Add support for formatting and linting CSS files from the CLI. These operations are **opt-in** for the time being.

If you don't have a configuration file, you can enable these features with `--css-formatter-enabled` and `--css-linter-enabled`:
```shell
biome check --css-formatter-enabled=true --css-linter-enabled=true ./
```
Contributed by @ematipico
- Add new CLI options to control the CSS formatting. Check the [CLI reference page](https://biomejs.dev/reference/cli/) for more details. Contributed by @ematipico
#### Enhancements
- Biome now executes commands (lint, format, check and ci) on the working directory by default. [#2266](https://github.com/biomejs/biome/issues/2266) Contributed by @unvalley
Expand Down Expand Up @@ -127,6 +141,11 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
Contributed by @Conaclos
- Add option `javascript.linter.enabled` to control the linter for JavaScript (and its super languages) files. Contributed by @ematipico
- Add option `json.linter.enabled` to control the linter for JSON (and its super languages) files. Contributed by @ematipico
- Add option `css.linter.enabled` to control the linter for CSS (and its super languages) files. Contributed by @ematipico
- Add option `css.formatter`, to control the formatter options for CSS (and its super languages) files. Contributed by @ematipico
#### Enhancements
- The `javascript.formatter.trailingComma` option is deprecated and renamed to `javascript.formatter.trailingCommas`. The corresponding CLI option `--trailing-comma` is also deprecated and renamed to `--trailing-commas`. Details can be checked in [#2492](https://github.com/biomejs/biome/pull/2492). Contributed by @Sec-ant
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ regex = { workspace = true }
tokio = { workspace = true, features = ["io-util"] }

[features]
docgen = ["bpaf/docgen"]
format_css = ["biome_css_formatter/format_css"]
docgen = ["bpaf/docgen"]

[lints]
workspace = true
29 changes: 8 additions & 21 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn format(
files_configuration,
write,
mut json_formatter,
mut css_formatter,
css_formatter,
since,
staged,
changed,
Expand Down Expand Up @@ -130,27 +130,8 @@ pub(crate) fn format(
}
}
}
// TODO: remove in biome 2.0
if let Some(css_formatter) = css_formatter.as_mut() {
if let Some(indent_size) = css_formatter.indent_size {
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--css-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--css-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
});

if css_formatter.indent_width.is_none() {
css_formatter.indent_width = Some(indent_size);
}
}
}

if css_formatter.is_some() {
let css = configuration.css.get_or_insert_with(Default::default);
css.formatter.merge_with(css_formatter);
}
configuration.files.merge_with(files_configuration);
// merge formatter options
if !configuration
.formatter
.as_ref()
Expand All @@ -163,6 +144,10 @@ pub(crate) fn format(

formatter.enabled = Some(true);
}
if css_formatter.is_some() {
let css = configuration.css.get_or_insert_with(Default::default);
css.formatter.merge_with(css_formatter);
}
if javascript_formatter.is_some() {
let javascript = configuration
.javascript
Expand All @@ -173,6 +158,8 @@ pub(crate) fn format(
let json = configuration.json.get_or_insert_with(Default::default);
json.formatter.merge_with(json_formatter);
}

configuration.files.merge_with(files_configuration);
configuration.vcs.merge_with(vcs_configuration);

// check if support of git ignore files is enabled
Expand Down
24 changes: 24 additions & 0 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use crate::commands::{
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_configuration::css::PartialCssLinter;
use biome_configuration::javascript::PartialJavascriptLinter;
use biome_configuration::json::PartialJsonLinter;
use biome_configuration::linter::RuleSelector;
use biome_configuration::vcs::PartialVcsConfiguration;
use biome_configuration::{
Expand All @@ -30,6 +33,9 @@ pub(crate) struct LintCommandPayload {
pub(crate) staged: bool,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
pub(crate) javascript_linter: Option<PartialJavascriptLinter>,
pub(crate) json_linter: Option<PartialJsonLinter>,
pub(crate) css_linter: Option<PartialCssLinter>,
}

/// Handler for the "lint" command of the Biome CLI
Expand All @@ -47,6 +53,9 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
staged,
changed,
since,
javascript_linter,
css_linter,
json_linter,
} = payload;
setup_cli_subscriber(cli_options.log_level, cli_options.log_kind);

Expand Down Expand Up @@ -96,6 +105,21 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
..Default::default()
});

if css_linter.is_some() {
let css = fs_configuration.css.get_or_insert_with(Default::default);
css.linter.merge_with(css_linter);
}
if javascript_linter.is_some() {
let javascript = fs_configuration
.javascript
.get_or_insert_with(Default::default);
javascript.linter.merge_with(javascript_linter);
}
if json_linter.is_some() {
let json = fs_configuration.json.get_or_insert_with(Default::default);
json.linter.merge_with(json_linter);
}

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
let (vcs_base_path, gitignore_matches) =
Expand Down
24 changes: 18 additions & 6 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ use crate::diagnostics::DeprecatedConfigurationFile;
use crate::execute::Stdin;
use crate::logging::LoggingKind;
use crate::{CliDiagnostic, CliSession, LoggingLevel, VERSION};
use biome_configuration::css::PartialCssLinter;
use biome_configuration::javascript::PartialJavascriptLinter;
use biome_configuration::json::PartialJsonLinter;
use biome_configuration::linter::RuleSelector;
use biome_configuration::{
css::partial_css_formatter, javascript::partial_javascript_formatter,
json::partial_json_formatter, partial_configuration, partial_files_configuration,
partial_formatter_configuration, partial_linter_configuration, vcs::partial_vcs_configuration,
vcs::PartialVcsConfiguration, PartialCssFormatter, PartialFilesConfiguration,
PartialFormatterConfiguration, PartialJavascriptFormatter, PartialJsonFormatter,
PartialLinterConfiguration,
css::partial_css_formatter, css::partial_css_linter, javascript::partial_javascript_formatter,
javascript::partial_javascript_linter, json::partial_json_formatter, json::partial_json_linter,
partial_configuration, partial_files_configuration, partial_formatter_configuration,
partial_linter_configuration, vcs::partial_vcs_configuration, vcs::PartialVcsConfiguration,
PartialCssFormatter, PartialFilesConfiguration, PartialFormatterConfiguration,
PartialJavascriptFormatter, PartialJsonFormatter, PartialLinterConfiguration,
};
use biome_configuration::{ConfigurationDiagnostic, PartialConfiguration};
use biome_console::{markup, Console, ConsoleExt};
Expand Down Expand Up @@ -150,6 +153,15 @@ pub enum BiomeCommand {
#[bpaf(external(partial_files_configuration), optional, hide_usage)]
files_configuration: Option<PartialFilesConfiguration>,

#[bpaf(external(partial_javascript_linter), optional, hide_usage)]
javascript_linter: Option<PartialJavascriptLinter>,

#[bpaf(external(partial_json_linter), optional, hide_usage)]
json_linter: Option<PartialJsonLinter>,

#[bpaf(external(partial_css_linter), optional, hide_usage, hide)]
css_linter: Option<PartialCssLinter>,

#[bpaf(external, hide_usage)]
cli_options: CliOptions,

Expand Down
16 changes: 14 additions & 2 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,27 @@ impl Display for RageConfiguration<'_, '_> {
{KeyValuePair("Line width", markup!({DebugDisplayOption(json_formatter_configuration.line_width.map(|lw| lw.get()))}))}
{KeyValuePair("Trailing Commas", markup!({DebugDisplayOption(json_formatter_configuration.trailing_commas)}))}
).fmt(fmt)?;

let css_formatter_configuration =
configuration.get_css_formatter_configuration();
markup! (
{Section("CSS Formatter")}
{KeyValuePair("Enabled", markup!({DebugDisplay(css_formatter_configuration.enabled)}))}
{KeyValuePair("Indent style", markup!({DebugDisplay(css_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplay(css_formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplay(css_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplay(css_formatter_configuration.line_width)}))}
{KeyValuePair("Quote style", markup!({DebugDisplay(css_formatter_configuration.quote_style)}))}
).fmt(fmt)?;
}

// Print linter configuration if --linter option is true
if self.linter {
let linter_configuration = configuration.get_linter_rules();
markup! (
{Section("Linter")}
{KeyValuePair("Recommended", markup!({DebugDisplay(linter_configuration.recommended.unwrap_or(false))}))}
{KeyValuePair("All", markup!({DebugDisplay(linter_configuration.all.unwrap_or(false))}))}
{KeyValuePair("Recommended", markup!({DebugDisplay(linter_configuration.recommended.unwrap_or_default())}))}
{KeyValuePair("All", markup!({DebugDisplay(linter_configuration.all.unwrap_or_default())}))}
{RageConfigurationLintRules("Rules",linter_configuration)}
).fmt(fmt)?;
}
Expand Down
6 changes: 6 additions & 0 deletions crates/biome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ impl<'app> CliSession<'app> {
staged,
changed,
since,
css_linter,
javascript_linter,
json_linter,
} => commands::lint::lint(
self,
LintCommandPayload {
Expand All @@ -137,6 +140,9 @@ impl<'app> CliSession<'app> {
staged,
changed,
since,
css_linter,
javascript_linter,
json_linter,
},
),
BiomeCommand::Ci {
Expand Down
Loading

0 comments on commit 2fb7d63

Please sign in to comment.