Skip to content

Commit

Permalink
here
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Dec 1, 2023
1 parent 2456722 commit 17e67c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
34 changes: 14 additions & 20 deletions crates/oxc_linter/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{ops::Deref, path::PathBuf};

pub mod errors;
use oxc_diagnostics::{Error, FailedToOpenFileError};
Expand All @@ -12,23 +12,24 @@ use crate::{

use self::errors::{FailedToParseConfigError, FailedToParseRuleValueError};

pub struct ESLintConfig<'a> {
rules: Vec<(&'a str, &'a str, AllowWarnDeny, Option<Value>)>,
pub struct ESLintConfig {
// rules: Vec<(&'a str, &'a str, AllowWarnDeny, Option<Value>)>,
rules: std::vec::Vec<RuleEnum>,
}

impl ESLintConfig<'_> {
pub fn new(path: PathBuf) -> Result<Self, Error> {
let file = match std::fs::read_to_string(&path) {
impl ESLintConfig {
pub fn new(path: &PathBuf) -> Result<Self, Error> {
let file = match std::fs::read_to_string(path) {
Ok(file) => file,
Err(e) => {
return Err(Error::new(FailedToOpenFileError(path, e)));
return Err(Error::new(FailedToOpenFileError(path.clone(), e)));
}
};

let file = match serde_json::from_str::<serde_json::Value>(&file) {
Ok(file) => file,
Err(e) => {
return Err(Error::new(FailedToParseConfigError(path, e.to_string())));
return Err(Error::new(FailedToParseConfigError(path.clone(), e.to_string())));
}
};

Expand All @@ -48,7 +49,7 @@ impl ESLintConfig<'_> {

// `extends` provides the defaults
// `rules` provides the overrides
let m = RULES.clone().into_iter().map(|rule| {
let m = RULES.clone().into_iter().filter_map(|rule| {
// Check if the extends set is empty or contains the plugin name
let in_extends = extends_hm.contains(rule.plugin_name());

Expand All @@ -62,27 +63,20 @@ impl ESLintConfig<'_> {
(false, AllowWarnDeny::Allow, &None)
};

todo!();

// The rule is included if it's in the extends set and not explicitly disabled,
// or if it's explicitly enabled
if (in_extends && !is_explicitly_handled) || policy.is_enabled() {
(
rule.plugin_name(),
rule.name(),
if is_explicitly_handled { policy } else { AllowWarnDeny::Deny },
config.cloned(),
)
Some(rule.read_json(config.cloned()))
} else {
(rule.plugin_name(), rule.name(), AllowWarnDeny::Allow, None)
None
}
});

Ok(Self { rules: m.collect::<Vec<_>>() })
}

pub fn filter(&self) -> &Vec<(&str, &str, AllowWarnDeny, Option<Value>)> {
&self.rules
pub fn filter(self) -> Vec<RuleEnum> {
self.rules
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl LintOptions {

if let Some(path) = &self.config_path {
// TODO: report err
// ESLintConfig::new(path)
return ESLintConfig::new(path).unwrap().filter();
}
let all_rules = self.get_filtered_rules();

Expand Down

0 comments on commit 17e67c4

Please sign in to comment.