Skip to content

Commit

Permalink
Merge branch 'main' into 10-28-feat_ast_label_ast_fields_with_ts_
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed Oct 30, 2024
2 parents ebbe9ef + 55637c2 commit e581685
Show file tree
Hide file tree
Showing 40 changed files with 926 additions and 384 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ labels: C-bug
<!--
!!IMPORTANT!! If you are reporting a bug for Oxlint or the Oxc VSCode extension,
please use the "Linter bug report" template instead. You can find it here:
https://github.com/oxc-project/oxc/issues/new?assignees=DonIsaac&labels=C-bug,A-linter&projects=&template=linter_bug_report.yaml&title=linter:+
https://github.com/oxc-project/oxc/issues/new?labels=C-bug,A-linter&projects=&template=linter_bug_report.yaml&title=linter:+
-->
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/linter_bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Linter bug report
description: Report a bug in Oxlint
title: "linter: "
labels: ["C-bug", "A-linter"]
assignees:
- DonIsaac

body:
- type: markdown
Expand Down
19 changes: 0 additions & 19 deletions bacon.toml

This file was deleted.

31 changes: 17 additions & 14 deletions crates/oxc_linter/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use oxc_span::CompactStr;
use rustc_hash::FxHashSet;

use crate::{
config::{ESLintRule, OxlintRules},
options::LintPlugins,
config::{ESLintRule, LintPlugins, OxlintRules},
rules::RULES,
AllowWarnDeny, FixKind, FrameworkFlags, LintConfig, LintFilter, LintFilterKind, LintOptions,
Linter, Oxlintrc, RuleCategory, RuleEnum, RuleWithSeverity,
Expand All @@ -35,24 +34,28 @@ impl LinterBuilder {
/// You can think of this as `oxlint -A all`.
pub fn empty() -> Self {
let options = LintOptions::default();
let cache = RulesCache::new(options.plugins);
Self { rules: FxHashSet::default(), options, config: LintConfig::default(), cache }
let config = LintConfig::default();
let rules = FxHashSet::default();
let cache = RulesCache::new(config.plugins);

Self { rules, options, config, cache }
}

/// Warn on all rules in all plugins and categories, including those in `nursery`.
/// This is the kitchen sink.
///
/// You can think of this as `oxlint -W all -W nursery`.
pub fn all() -> Self {
let options = LintOptions { plugins: LintPlugins::all(), ..LintOptions::default() };
let cache = RulesCache::new(options.plugins);
let options = LintOptions::default();
let config = LintConfig { plugins: LintPlugins::all(), ..LintConfig::default() };
let cache = RulesCache::new(config.plugins);
Self {
rules: RULES
.iter()
.map(|rule| RuleWithSeverity { rule: rule.clone(), severity: AllowWarnDeny::Warn })
.collect(),
options,
config: LintConfig::default(),
config,
cache,
}
}
Expand All @@ -76,11 +79,11 @@ impl LinterBuilder {
let Oxlintrc { plugins, settings, env, globals, categories, rules: oxlintrc_rules } =
oxlintrc;

let config = LintConfig { settings, env, globals };
let options = LintOptions { plugins, ..Default::default() };
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(options.plugins);
let cache = RulesCache::new(config.plugins);
let mut builder = Self { rules, options, config, cache };

if !categories.is_empty() {
Expand Down Expand Up @@ -128,7 +131,7 @@ impl LinterBuilder {
/// [`and_plugins`]: LinterBuilder::and_plugins
#[inline]
pub fn with_plugins(mut self, plugins: LintPlugins) -> Self {
self.options.plugins = plugins;
self.config.plugins = plugins;
self.cache.set_plugins(plugins);
self
}
Expand All @@ -139,14 +142,14 @@ impl LinterBuilder {
/// rules.
#[inline]
pub fn and_plugins(mut self, plugins: LintPlugins, enabled: bool) -> Self {
self.options.plugins.set(plugins, enabled);
self.cache.set_plugins(self.options.plugins);
self.config.plugins.set(plugins, enabled);
self.cache.set_plugins(self.config.plugins);
self
}

#[inline]
pub fn plugins(&self) -> LintPlugins {
self.options.plugins
self.config.plugins
}

#[cfg(test)]
Expand Down
10 changes: 9 additions & 1 deletion crates/oxc_linter/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ mod categories;
mod env;
mod globals;
mod oxlintrc;
mod plugins;
mod rules;
mod settings;

pub use self::{
env::OxlintEnv,
globals::OxlintGlobals,
oxlintrc::Oxlintrc,
plugins::LintPlugins,
rules::ESLintRule,
rules::OxlintRules,
settings::{jsdoc::JSDocPluginSettings, OxlintSettings},
};

#[derive(Debug, Default)]
pub(crate) struct LintConfig {
pub(crate) plugins: LintPlugins,
pub(crate) settings: OxlintSettings,
/// Environments enable and disable collections of global variables.
pub(crate) env: OxlintEnv,
Expand All @@ -25,7 +28,12 @@ pub(crate) struct LintConfig {

impl From<Oxlintrc> for LintConfig {
fn from(config: Oxlintrc) -> Self {
Self { settings: config.settings, env: config.env, globals: config.globals }
Self {
plugins: config.plugins,
settings: config.settings,
env: config.env,
globals: config.globals,
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::{
categories::OxlintCategories, env::OxlintEnv, globals::OxlintGlobals, rules::OxlintRules,
settings::OxlintSettings,
categories::OxlintCategories, env::OxlintEnv, globals::OxlintGlobals, plugins::LintPlugins,
rules::OxlintRules, settings::OxlintSettings,
};

use crate::{options::LintPlugins, utils::read_to_string};
use crate::utils::read_to_string;

/// Oxlint Configuration File
///
Expand Down
File renamed without changes.
18 changes: 14 additions & 4 deletions crates/oxc_linter/src/context/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use oxc_span::SourceType;
use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc};

use crate::{
config::LintConfig,
config::{LintConfig, LintPlugins},
disable_directives::{DisableDirectives, DisableDirectivesBuilder},
fixer::{FixKind, Message},
frameworks,
options::{LintOptions, LintPlugins},
options::LintOptions,
utils, FrameworkFlags, RuleWithSeverity,
};

Expand Down Expand Up @@ -68,6 +68,7 @@ impl<'a> ContextHost<'a> {
file_path: P,
semantic: Rc<Semantic<'a>>,
options: LintOptions,
config: Arc<LintConfig>,
) -> Self {
const DIAGNOSTICS_INITIAL_CAPACITY: usize = 512;

Expand All @@ -82,24 +83,33 @@ impl<'a> ContextHost<'a> {
DisableDirectivesBuilder::new().build(semantic.source_text(), semantic.comments());

let file_path = file_path.as_ref().to_path_buf().into_boxed_path();
let plugins = config.plugins;

Self {
semantic,
disable_directives,
diagnostics: RefCell::new(Vec::with_capacity(DIAGNOSTICS_INITIAL_CAPACITY)),
fix: options.fix,
file_path,
config: Arc::new(LintConfig::default()),
config,
frameworks: options.framework_hints,
plugins: options.plugins,
plugins,
}
.sniff_for_frameworks()
}

/// Set the linter configuration for this context.
#[inline]
#[allow(dead_code)] // will be used in up-stack PR
pub fn with_config(mut self, config: &Arc<LintConfig>) -> Self {
let plugins = config.plugins;
self.config = Arc::clone(config);

if self.plugins != plugins {
self.plugins = plugins;
return self.sniff_for_frameworks();
}

self
}

Expand Down
Loading

0 comments on commit e581685

Please sign in to comment.