mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(cli,linter): add --disable-react/unicorn/typescript-plugin (#3305)
closes #1970
This commit is contained in:
parent
9ee962add8
commit
8ab9856dea
4 changed files with 69 additions and 15 deletions
|
|
@ -1 +1,4 @@
|
||||||
|
namespace X {
|
||||||
|
}
|
||||||
|
|
||||||
9007199254740993 // no-loss-of-precision
|
9007199254740993 // no-loss-of-precision
|
||||||
|
|
@ -169,6 +169,18 @@ impl FromStr for OutputFormat {
|
||||||
#[allow(clippy::struct_field_names)]
|
#[allow(clippy::struct_field_names)]
|
||||||
#[derive(Debug, Clone, Bpaf)]
|
#[derive(Debug, Clone, Bpaf)]
|
||||||
pub struct EnablePlugins {
|
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.
|
/// Enable the experimental import plugin and detect ESM problems.
|
||||||
/// It is recommended to use along side with the `--tsconfig` option.
|
/// It is recommended to use along side with the `--tsconfig` option.
|
||||||
#[bpaf(switch, hide_usage)]
|
#[bpaf(switch, hide_usage)]
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,9 @@ impl Runner for LintRunner {
|
||||||
.with_filter(filter)
|
.with_filter(filter)
|
||||||
.with_config_path(config)
|
.with_config_path(config)
|
||||||
.with_fix(fix_options.fix)
|
.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_import_plugin(enable_plugins.import_plugin)
|
||||||
.with_jsdoc_plugin(enable_plugins.jsdoc_plugin)
|
.with_jsdoc_plugin(enable_plugins.jsdoc_plugin)
|
||||||
.with_jest_plugin(enable_plugins.jest_plugin)
|
.with_jest_plugin(enable_plugins.jest_plugin)
|
||||||
|
|
@ -395,7 +398,21 @@ mod test {
|
||||||
let args = &[
|
let args = &[
|
||||||
"-c",
|
"-c",
|
||||||
"fixtures/typescript_eslint/eslintrc.json",
|
"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);
|
let result = test(args);
|
||||||
assert_eq!(result.number_of_files, 1);
|
assert_eq!(result.number_of_files, 1);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ pub struct LintOptions {
|
||||||
pub filter: Vec<(AllowWarnDeny, String)>,
|
pub filter: Vec<(AllowWarnDeny, String)>,
|
||||||
pub config_path: Option<PathBuf>,
|
pub config_path: Option<PathBuf>,
|
||||||
pub fix: bool,
|
pub fix: bool,
|
||||||
|
|
||||||
|
pub react_plugin: bool,
|
||||||
|
pub unicorn_plugin: bool,
|
||||||
|
pub typescript_plugin: bool,
|
||||||
pub import_plugin: bool,
|
pub import_plugin: bool,
|
||||||
pub jsdoc_plugin: bool,
|
pub jsdoc_plugin: bool,
|
||||||
pub jest_plugin: bool,
|
pub jest_plugin: bool,
|
||||||
|
|
@ -28,6 +32,9 @@ impl Default for LintOptions {
|
||||||
filter: vec![(AllowWarnDeny::Deny, String::from("correctness"))],
|
filter: vec![(AllowWarnDeny::Deny, String::from("correctness"))],
|
||||||
config_path: None,
|
config_path: None,
|
||||||
fix: false,
|
fix: false,
|
||||||
|
react_plugin: true,
|
||||||
|
unicorn_plugin: true,
|
||||||
|
typescript_plugin: true,
|
||||||
import_plugin: false,
|
import_plugin: false,
|
||||||
jsdoc_plugin: false,
|
jsdoc_plugin: false,
|
||||||
jest_plugin: false,
|
jest_plugin: false,
|
||||||
|
|
@ -59,6 +66,24 @@ impl LintOptions {
|
||||||
self
|
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]
|
#[must_use]
|
||||||
pub fn with_import_plugin(mut self, yes: bool) -> Self {
|
pub fn with_import_plugin(mut self, yes: bool) -> Self {
|
||||||
self.import_plugin = yes;
|
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 {
|
impl LintOptions {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
|
@ -234,13 +252,17 @@ impl LintOptions {
|
||||||
RULES
|
RULES
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|rule| match rule.plugin_name() {
|
.filter(|rule| match rule.plugin_name() {
|
||||||
IMPORT_PLUGIN_NAME if !self.import_plugin => false,
|
"react" => self.react_plugin,
|
||||||
JSDOC_PLUGIN_NAME if !self.jsdoc_plugin => false,
|
"unicorn" => self.unicorn_plugin,
|
||||||
JEST_PLUGIN_NAME if !self.jest_plugin => false,
|
"typescript" => self.typescript_plugin,
|
||||||
JSX_A11Y_PLUGIN_NAME if !self.jsx_a11y_plugin => false,
|
"import" => self.import_plugin,
|
||||||
NEXTJS_PLUGIN_NAME if !self.nextjs_plugin => false,
|
"jsdoc" => self.jsdoc_plugin,
|
||||||
REACT_PERF_PLUGIN_NAME if !self.react_perf_plugin => false,
|
"jest" => self.jest_plugin,
|
||||||
_ => true,
|
"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()
|
.cloned()
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue