diff --git a/crates/oxc_cli/fixtures/typescript_eslint/test.js b/crates/oxc_cli/fixtures/typescript_eslint/test.ts similarity index 70% rename from crates/oxc_cli/fixtures/typescript_eslint/test.js rename to crates/oxc_cli/fixtures/typescript_eslint/test.ts index ddf89a754..4fcb68949 100644 --- a/crates/oxc_cli/fixtures/typescript_eslint/test.js +++ b/crates/oxc_cli/fixtures/typescript_eslint/test.ts @@ -1 +1,4 @@ +namespace X { +} + 9007199254740993 // no-loss-of-precision diff --git a/crates/oxc_cli/src/command/lint.rs b/crates/oxc_cli/src/command/lint.rs index 86eeca652..f01af98ab 100644 --- a/crates/oxc_cli/src/command/lint.rs +++ b/crates/oxc_cli/src/command/lint.rs @@ -169,6 +169,18 @@ impl FromStr for OutputFormat { #[allow(clippy::struct_field_names)] #[derive(Debug, Clone, Bpaf)] pub struct EnablePlugins { + /// Disable react plugin, which is turned on by default + #[bpaf(long("disable-react-plugin"), flag(false, true), hide_usage)] + pub react_plugin: bool, + + /// Disable unicorn plugin, which is turned on by default + #[bpaf(long("disable-unicorn-plugin"), flag(false, true), hide_usage)] + pub unicorn_plugin: bool, + + /// Disable TypeScript plugin, which is turned on by default + #[bpaf(long("disable-typescript-plugin"), flag(false, true), hide_usage)] + pub typescript_plugin: bool, + /// Enable the experimental import plugin and detect ESM problems. /// It is recommended to use along side with the `--tsconfig` option. #[bpaf(switch, hide_usage)] diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index e8d8cd39c..e93b03ccc 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -94,6 +94,9 @@ impl Runner for LintRunner { .with_filter(filter) .with_config_path(config) .with_fix(fix_options.fix) + .with_react_plugin(enable_plugins.react_plugin) + .with_unicorn_plugin(enable_plugins.unicorn_plugin) + .with_typescript_plugin(enable_plugins.typescript_plugin) .with_import_plugin(enable_plugins.import_plugin) .with_jsdoc_plugin(enable_plugins.jsdoc_plugin) .with_jest_plugin(enable_plugins.jest_plugin) @@ -395,7 +398,21 @@ mod test { let args = &[ "-c", "fixtures/typescript_eslint/eslintrc.json", - "fixtures/typescript_eslint/test.js", + "fixtures/typescript_eslint/test.ts", + ]; + let result = test(args); + assert_eq!(result.number_of_files, 1); + assert_eq!(result.number_of_warnings, 2); + assert_eq!(result.number_of_errors, 0); + } + + #[test] + fn typescript_eslint_off() { + let args = &[ + "-c", + "fixtures/typescript_eslint/eslintrc.json", + "--disable-typescript-plugin", + "fixtures/typescript_eslint/test.ts", ]; let result = test(args); assert_eq!(result.number_of_files, 1); diff --git a/crates/oxc_linter/src/options.rs b/crates/oxc_linter/src/options.rs index 0d65c3ba4..df78b4a70 100644 --- a/crates/oxc_linter/src/options.rs +++ b/crates/oxc_linter/src/options.rs @@ -14,6 +14,10 @@ pub struct LintOptions { pub filter: Vec<(AllowWarnDeny, String)>, pub config_path: Option, pub fix: bool, + + pub react_plugin: bool, + pub unicorn_plugin: bool, + pub typescript_plugin: bool, pub import_plugin: bool, pub jsdoc_plugin: bool, pub jest_plugin: bool, @@ -28,6 +32,9 @@ impl Default for LintOptions { filter: vec![(AllowWarnDeny::Deny, String::from("correctness"))], config_path: None, fix: false, + react_plugin: true, + unicorn_plugin: true, + typescript_plugin: true, import_plugin: false, jsdoc_plugin: false, jest_plugin: false, @@ -59,6 +66,24 @@ impl LintOptions { self } + #[must_use] + pub fn with_react_plugin(mut self, yes: bool) -> Self { + self.react_plugin = yes; + self + } + + #[must_use] + pub fn with_unicorn_plugin(mut self, yes: bool) -> Self { + self.unicorn_plugin = yes; + self + } + + #[must_use] + pub fn with_typescript_plugin(mut self, yes: bool) -> Self { + self.typescript_plugin = yes; + self + } + #[must_use] pub fn with_import_plugin(mut self, yes: bool) -> Self { self.import_plugin = yes; @@ -157,13 +182,6 @@ impl TryFrom<&Number> for AllowWarnDeny { } } -const IMPORT_PLUGIN_NAME: &str = "import"; -const JSDOC_PLUGIN_NAME: &str = "jsdoc"; -const JEST_PLUGIN_NAME: &str = "jest"; -const JSX_A11Y_PLUGIN_NAME: &str = "jsx_a11y"; -const NEXTJS_PLUGIN_NAME: &str = "nextjs"; -const REACT_PERF_PLUGIN_NAME: &str = "react_perf"; - impl LintOptions { /// # Errors /// @@ -234,13 +252,17 @@ impl LintOptions { RULES .iter() .filter(|rule| match rule.plugin_name() { - IMPORT_PLUGIN_NAME if !self.import_plugin => false, - JSDOC_PLUGIN_NAME if !self.jsdoc_plugin => false, - JEST_PLUGIN_NAME if !self.jest_plugin => false, - JSX_A11Y_PLUGIN_NAME if !self.jsx_a11y_plugin => false, - NEXTJS_PLUGIN_NAME if !self.nextjs_plugin => false, - REACT_PERF_PLUGIN_NAME if !self.react_perf_plugin => false, - _ => true, + "react" => self.react_plugin, + "unicorn" => self.unicorn_plugin, + "typescript" => self.typescript_plugin, + "import" => self.import_plugin, + "jsdoc" => self.jsdoc_plugin, + "jest" => self.jest_plugin, + "jsx_a11y" => self.jsx_a11y_plugin, + "nextjs" => self.nextjs_plugin, + "react_perf" => self.react_perf_plugin, + "eslint" | "oxc" | "deepscan" | "tree_shaking" => true, + name => panic!("Unhandled plugin: {name}"), }) .cloned() .collect::>()