Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(parse/css): change fields in CssParserSettings to Option #3273

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions crates/biome_css_parser/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_

let settings = settings.languages.css.parser;

if settings.css_modules {
if settings.css_modules.unwrap_or_default() {
options = options.allow_css_modules();
}

if settings.allow_wrong_line_comments {
if settings.allow_wrong_line_comments.unwrap_or_default() {
options = options.allow_wrong_line_comments();
}

Expand Down
8 changes: 4 additions & 4 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl Default for CssLinterSettings {
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CssParserSettings {
pub allow_wrong_line_comments: bool,
pub css_modules: bool,
pub allow_wrong_line_comments: Option<bool>,
pub css_modules: Option<bool>,
}

impl ServiceLanguage for CssLanguage {
Expand Down Expand Up @@ -217,10 +217,10 @@ fn parse(
) -> ParseResult {
let mut options = CssParserOptions {
allow_wrong_line_comments: settings
.map(|s| s.languages.css.parser.allow_wrong_line_comments)
.and_then(|s| s.languages.css.parser.allow_wrong_line_comments)
.unwrap_or_default(),
css_modules: settings
.map(|s| s.languages.css.parser.css_modules)
.and_then(|s| s.languages.css.parser.css_modules)
.unwrap_or_default(),
};
if let Some(settings) = settings {
Expand Down
55 changes: 33 additions & 22 deletions crates/biome_service/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use biome_configuration::diagnostics::InvalidIgnorePattern;
use biome_configuration::javascript::JsxRuntime;
use biome_configuration::organize_imports::OrganizeImports;
use biome_configuration::{
push_to_analyzer_rules, BiomeDiagnostic, CssConfiguration, FilesConfiguration,
FormatterConfiguration, JavascriptConfiguration, LinterConfiguration,
OverrideFormatterConfiguration, OverrideLinterConfiguration,
OverrideOrganizeImportsConfiguration, Overrides, PartialConfiguration, PartialCssConfiguration,
PartialJavascriptConfiguration, PartialJsonConfiguration, PlainIndentStyle, Rules,
push_to_analyzer_rules, BiomeDiagnostic, FilesConfiguration, FormatterConfiguration,
JavascriptConfiguration, LinterConfiguration, OverrideFormatterConfiguration,
OverrideLinterConfiguration, OverrideOrganizeImportsConfiguration, Overrides,
PartialConfiguration, PartialCssConfiguration, PartialJavascriptConfiguration,
PartialJsonConfiguration, PlainIndentStyle, Rules,
};
use biome_css_formatter::context::CssFormatOptions;
use biome_css_parser::CssParserOptions;
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Settings {
}
// css settings
if let Some(css) = configuration.css {
self.languages.css = CssConfiguration::from(css).into();
self.languages.css = css.into();
}

// NOTE: keep this last. Computing the overrides require reading the settings computed by the parent settings.
Expand Down Expand Up @@ -494,20 +494,27 @@ impl From<PartialJsonConfiguration> for LanguageSettings<JsonLanguage> {
}
}

impl From<CssConfiguration> for LanguageSettings<CssLanguage> {
fn from(css: CssConfiguration) -> Self {
impl From<PartialCssConfiguration> for LanguageSettings<CssLanguage> {
fn from(css: PartialCssConfiguration) -> Self {
let mut language_setting: LanguageSettings<CssLanguage> = LanguageSettings::default();

language_setting.parser.allow_wrong_line_comments = css.parser.allow_wrong_line_comments;
language_setting.parser.css_modules = css.parser.css_modules;

language_setting.formatter.enabled = Some(css.formatter.enabled);
language_setting.formatter.indent_width = css.formatter.indent_width;
language_setting.formatter.indent_style = css.formatter.indent_style.map(Into::into);
language_setting.formatter.line_width = css.formatter.line_width;
language_setting.formatter.line_ending = css.formatter.line_ending;
language_setting.formatter.quote_style = Some(css.formatter.quote_style);
language_setting.linter.enabled = Some(css.linter.enabled);
if let Some(parser) = css.parser {
language_setting.parser.allow_wrong_line_comments = parser.allow_wrong_line_comments;
language_setting.parser.css_modules = parser.css_modules;
}
if let Some(formatter) = css.formatter {
// TODO: remove this when css formatting is enabled by defualt
dyc3 marked this conversation as resolved.
Show resolved Hide resolved
language_setting.formatter.enabled = Some(formatter.enabled.unwrap_or_default());
dyc3 marked this conversation as resolved.
Show resolved Hide resolved
language_setting.formatter.indent_width = formatter.indent_width;
language_setting.formatter.indent_style = formatter.indent_style.map(Into::into);
language_setting.formatter.line_width = formatter.line_width;
language_setting.formatter.line_ending = formatter.line_ending;
language_setting.formatter.quote_style = formatter.quote_style;
}
if let Some(linter) = css.linter {
// TODO: remove this when css linting is enabled by defualt
dyc3 marked this conversation as resolved.
Show resolved Hide resolved
language_setting.linter.enabled = Some(linter.enabled.unwrap_or_default());
dyc3 marked this conversation as resolved.
Show resolved Hide resolved
}

language_setting
}
Expand Down Expand Up @@ -1130,8 +1137,12 @@ impl OverrideSettingPattern {

let css_parser = &self.languages.css.parser;

options.allow_wrong_line_comments = css_parser.allow_wrong_line_comments;
options.css_modules = css_parser.css_modules;
if let Some(allow_wrong_line_comments) = css_parser.allow_wrong_line_comments {
options.allow_wrong_line_comments = allow_wrong_line_comments;
}
if let Some(css_modules) = css_parser.css_modules {
options.css_modules = css_modules;
}

if let Ok(mut writeonly_cache) = self.cached_css_parser_options.write() {
let options = *options;
Expand Down Expand Up @@ -1365,8 +1376,8 @@ fn to_css_language_settings(
let parent_parser = &parent_settings.parser;
language_setting.parser.allow_wrong_line_comments = parser
.allow_wrong_line_comments
.unwrap_or(parent_parser.allow_wrong_line_comments);
language_setting.parser.css_modules = parser.css_modules.unwrap_or(parent_parser.css_modules);
.or(parent_parser.allow_wrong_line_comments);
language_setting.parser.css_modules = parser.css_modules.or(parent_parser.css_modules);

language_setting
}
Expand Down
Loading