mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(linter): move LintSettings to its own file (#2052)
This commit is contained in:
parent
ae4e714713
commit
f514410427
3 changed files with 52 additions and 33 deletions
|
|
@ -168,8 +168,7 @@ fn parse_settings_from_root(root_json: &Value) -> LintSettings {
|
||||||
pub fn parse_settings(setting_value: &Value) -> LintSettings {
|
pub fn parse_settings(setting_value: &Value) -> LintSettings {
|
||||||
if let Value::Object(settings_object) = setting_value {
|
if let Value::Object(settings_object) = setting_value {
|
||||||
if let Some(Value::Object(jsx_a11y)) = settings_object.get("jsx-a11y") {
|
if let Some(Value::Object(jsx_a11y)) = settings_object.get("jsx-a11y") {
|
||||||
let mut jsx_a11y_setting =
|
let mut jsx_a11y_setting = JsxA11y::new(None, FxHashMap::default());
|
||||||
JsxA11y { polymorphic_prop_name: None, components: FxHashMap::default() };
|
|
||||||
|
|
||||||
if let Some(Value::Object(components)) = jsx_a11y.get("components") {
|
if let Some(Value::Object(components)) = jsx_a11y.get("components") {
|
||||||
let components_map: FxHashMap<String, String> = components
|
let components_map: FxHashMap<String, String> = components
|
||||||
|
|
@ -186,7 +185,7 @@ pub fn parse_settings(setting_value: &Value) -> LintSettings {
|
||||||
.set_polymorphic_prop_name(Some(String::from(polymorphic_prop_name)));
|
.set_polymorphic_prop_name(Some(String::from(polymorphic_prop_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return LintSettings { jsx_a11y: jsx_a11y_setting };
|
return LintSettings::new(jsx_a11y_setting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ pub mod partial_loader;
|
||||||
pub mod rule;
|
pub mod rule;
|
||||||
mod rules;
|
mod rules;
|
||||||
mod service;
|
mod service;
|
||||||
|
mod settings;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
use std::{io::Write, rc::Rc, sync::Arc};
|
use std::{io::Write, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
use oxc_diagnostics::Report;
|
use oxc_diagnostics::Report;
|
||||||
pub(crate) use oxc_semantic::AstNode;
|
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
context::LintContext,
|
context::LintContext,
|
||||||
|
|
@ -30,8 +30,13 @@ pub use crate::{
|
||||||
options::{AllowWarnDeny, LintOptions},
|
options::{AllowWarnDeny, LintOptions},
|
||||||
rule::RuleCategory,
|
rule::RuleCategory,
|
||||||
service::LintService,
|
service::LintService,
|
||||||
|
settings::LintSettings,
|
||||||
};
|
};
|
||||||
pub(crate) use rules::{RuleEnum, RULES};
|
pub(crate) use crate::{
|
||||||
|
rules::{RuleEnum, RULES},
|
||||||
|
settings::JsxA11y,
|
||||||
|
};
|
||||||
|
pub(crate) use oxc_semantic::AstNode;
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -44,33 +49,6 @@ fn size_asserts() {
|
||||||
assert_eq_size!(RuleEnum, [u8; 16]);
|
assert_eq_size!(RuleEnum, [u8; 16]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct LintSettings {
|
|
||||||
jsx_a11y: JsxA11y,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for LintSettings {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self { jsx_a11y: JsxA11y { polymorphic_prop_name: None, components: FxHashMap::default() } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct JsxA11y {
|
|
||||||
polymorphic_prop_name: Option<String>,
|
|
||||||
components: FxHashMap<String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JsxA11y {
|
|
||||||
pub fn set_components(&mut self, components: FxHashMap<String, String>) {
|
|
||||||
self.components = components;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_polymorphic_prop_name(&mut self, name: Option<String>) {
|
|
||||||
self.polymorphic_prop_name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Linter {
|
pub struct Linter {
|
||||||
rules: Vec<(/* rule name */ &'static str, RuleEnum)>,
|
rules: Vec<(/* rule name */ &'static str, RuleEnum)>,
|
||||||
|
|
|
||||||
42
crates/oxc_linter/src/settings.rs
Normal file
42
crates/oxc_linter/src/settings.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
|
/// The `settings` field from ESLint config
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct LintSettings {
|
||||||
|
pub jsx_a11y: JsxA11y,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for LintSettings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { jsx_a11y: JsxA11y { polymorphic_prop_name: None, components: FxHashMap::default() } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LintSettings {
|
||||||
|
pub fn new(jsx_a11y: JsxA11y) -> Self {
|
||||||
|
Self { jsx_a11y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct JsxA11y {
|
||||||
|
pub polymorphic_prop_name: Option<String>,
|
||||||
|
pub components: FxHashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JsxA11y {
|
||||||
|
pub fn new(
|
||||||
|
polymorphic_prop_name: Option<String>,
|
||||||
|
components: FxHashMap<String, String>,
|
||||||
|
) -> Self {
|
||||||
|
Self { polymorphic_prop_name, components }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_components(&mut self, components: FxHashMap<String, String>) {
|
||||||
|
self.components = components;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_polymorphic_prop_name(&mut self, name: Option<String>) {
|
||||||
|
self.polymorphic_prop_name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue