Skip to content

Commit

Permalink
refactor(parse/css): change fields in CssParserOptions and `CssPars…
Browse files Browse the repository at this point in the history
…erSettings` to `Option`
  • Loading branch information
dyc3 committed Jun 24, 2024
1 parent fc9b1eb commit 17cf082
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/biome_css_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ impl<'src> CssLexer<'src> {
COMMENT
}
}
Some(b'/') if self.options.allow_wrong_line_comments => {
Some(b'/') if self.options.allow_wrong_line_comments.unwrap_or_default() => {
self.advance(2);

while let Some(chr) = self.current_byte() {
Expand Down
10 changes: 5 additions & 5 deletions crates/biome_css_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ pub struct CssParserOptions {
/// use `//` as a comment because it's javascript file.
///
/// Defaults to `false`.
pub allow_wrong_line_comments: bool,
pub allow_wrong_line_comments: Option<bool>,

/// Enables parsing of CSS Modules specific features.
/// Defaults to `false`.
pub css_modules: bool,
pub css_modules: Option<bool>,
}

impl CssParserOptions {
/// Allows the parser to parse wrong line comments.
pub fn allow_wrong_line_comments(mut self) -> Self {
self.allow_wrong_line_comments = true;
self.allow_wrong_line_comments = Some(true);
self
}

/// Enables parsing of css modules selectors.
pub fn allow_css_modules(mut self) -> Self {
self.css_modules = true;
self.css_modules = Some(true);
self
}

/// Checks if parsing of CSS Modules features is disabled.
pub fn is_css_modules_disabled(&self) -> bool {
!self.css_modules
!self.css_modules.unwrap_or_default()
}
}

Expand Down
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
4 changes: 2 additions & 2 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
12 changes: 8 additions & 4 deletions crates/biome_service/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,12 @@ impl From<CssConfiguration> for LanguageSettings<CssLanguage> {
fn from(css: CssConfiguration) -> 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;
if css.parser.allow_wrong_line_comments {
language_setting.parser.allow_wrong_line_comments = Some(true);
}
if css.parser.css_modules {
language_setting.parser.css_modules = Some(true);
}

language_setting.formatter.enabled = Some(css.formatter.enabled);
language_setting.formatter.indent_width = css.formatter.indent_width;
Expand Down Expand Up @@ -1357,8 +1361,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
4 changes: 2 additions & 2 deletions crates/biome_unicode_table/src/tables.rs

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

0 comments on commit 17cf082

Please sign in to comment.