Skip to content

Commit

Permalink
add docs to override config
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac authored and Boshen committed Oct 29, 2024
1 parent 8f1460e commit abc9ffd
Show file tree
Hide file tree
Showing 16 changed files with 759 additions and 44 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ futures = "0.3.31"
glob = "0.3.1"
globset = "0.4.15"
handlebars = "6.1.0"
heapless = "0.8.0"
humansize = "2.1.3"
ignore = "0.4.23"
indexmap = "2.6.0"
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct OxcCode {
pub scope: Option<Cow<'static, str>>,
pub number: Option<Cow<'static, str>>,
}

impl OxcCode {
pub fn is_some(&self) -> bool {
self.scope.is_some() || self.number.is_some()
Expand Down
9 changes: 6 additions & 3 deletions crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,30 @@ oxc_cfg = { workspace = true }
oxc_codegen = { workspace = true }
oxc_diagnostics = { workspace = true }
oxc_ecmascript = { workspace = true }
oxc_index = { workspace = true }
oxc_index = { workspace = true, features = ["serialize"] }
oxc_macros = { workspace = true }
oxc_parser = { workspace = true }
oxc_regular_expression = { workspace = true }
oxc_resolver = { workspace = true }
oxc_semantic = { workspace = true }
oxc_span = { workspace = true, features = ["schemars", "serialize"] }
oxc_syntax = { workspace = true }
oxc_syntax = { workspace = true, features = ["serialize"] }

aho-corasick = { workspace = true }
assert-unchecked = { workspace = true }
bitflags = { workspace = true }
convert_case = { workspace = true }
cow-utils = { workspace = true }
dashmap = { workspace = true }
globset = { workspace = true }
globset = { workspace = true, features = ["serde1"] }
heapless = { workspace = true }
itertools = { workspace = true }
json-strip-comments = { workspace = true }
language-tags = { workspace = true }
lazy_static = { workspace = true }
memchr = { workspace = true }
mime_guess = { workspace = true }
nonmax = { workspace = true }
once_cell = { workspace = true }
phf = { workspace = true, features = ["macros"] }
rayon = { workspace = true }
Expand Down
28 changes: 21 additions & 7 deletions crates/oxc_linter/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::CompactStr;
use rustc_hash::FxHashSet;

use crate::{
config::{ESLintRule, LintPlugins, OxlintRules},
config::{ConfigStore, ESLintRule, LintPlugins, OxlintOverrides, OxlintRules},
rules::RULES,
AllowWarnDeny, FixKind, FrameworkFlags, LintConfig, LintFilter, LintFilterKind, LintOptions,
Linter, Oxlintrc, RuleCategory, RuleEnum, RuleWithSeverity,
Expand All @@ -18,6 +18,7 @@ pub struct LinterBuilder {
pub(super) rules: FxHashSet<RuleWithSeverity>,
options: LintOptions,
config: LintConfig,
overrides: OxlintOverrides,
cache: RulesCache,
}

Expand All @@ -36,9 +37,10 @@ impl LinterBuilder {
let options = LintOptions::default();
let config = LintConfig::default();
let rules = FxHashSet::default();
let overrides = OxlintOverrides::default();
let cache = RulesCache::new(config.plugins);

Self { rules, options, config, cache }
Self { rules, options, config, overrides, cache }
}

/// Warn on all rules in all plugins and categories, including those in `nursery`.
Expand All @@ -48,6 +50,7 @@ impl LinterBuilder {
pub fn all() -> Self {
let options = LintOptions::default();
let config = LintConfig { plugins: LintPlugins::all(), ..LintConfig::default() };
let overrides = OxlintOverrides::default();
let cache = RulesCache::new(config.plugins);
Self {
rules: RULES
Expand All @@ -56,6 +59,7 @@ impl LinterBuilder {
.collect(),
options,
config,
overrides,
cache,
}
}
Expand All @@ -76,15 +80,22 @@ impl LinterBuilder {
/// ```
pub fn from_oxlintrc(start_empty: bool, oxlintrc: Oxlintrc) -> Self {
// TODO: monorepo config merging, plugin-based extends, etc.
let Oxlintrc { plugins, settings, env, globals, categories, rules: oxlintrc_rules } =
oxlintrc;
let Oxlintrc {
plugins,
settings,
env,
globals,
categories,
rules: oxlintrc_rules,
overrides,
} = oxlintrc;

let config = LintConfig { plugins, settings, env, globals };
let options = LintOptions::default();
let rules =
if start_empty { FxHashSet::default() } else { Self::warn_correctness(plugins) };
let cache = RulesCache::new(config.plugins);
let mut builder = Self { rules, options, config, cache };
let mut builder = Self { rules, options, config, overrides, cache };

if !categories.is_empty() {
builder = builder.with_filters(categories.filters());
Expand Down Expand Up @@ -222,6 +233,8 @@ impl LinterBuilder {
}
}

/// # Panics
/// If more than 128 overrides are present within the oxlint config.
#[must_use]
pub fn build(self) -> Linter {
// When a plugin gets disabled before build(), rules for that plugin aren't removed until
Expand All @@ -234,7 +247,8 @@ impl LinterBuilder {
self.rules.into_iter().collect::<Vec<_>>()
};
rules.sort_unstable_by_key(|r| r.id());
Linter::new(rules, self.options, self.config)
let config = ConfigStore::new(rules, self.config, self.overrides).unwrap();
Linter::new(self.options, config)
}

/// Warn for all correctness rules in the given set of plugins.
Expand Down Expand Up @@ -532,7 +546,7 @@ mod test {
desired_plugins.set(LintPlugins::TYPESCRIPT, false);

let linter = LinterBuilder::default().with_plugins(desired_plugins).build();
for rule in linter.rules() {
for rule in linter.rules().iter() {
let name = rule.name();
let plugin = rule.plugin_name();
assert_ne!(
Expand Down
Loading

0 comments on commit abc9ffd

Please sign in to comment.