mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat: introduce --react-perf-plugin CLI flag, update rules to correctness (#2119)
https://github.com/oxc-project/oxc/issues/2041#issuecomment-1903316240 Closes #2041
This commit is contained in:
parent
69fecac733
commit
20a34b5294
9 changed files with 43 additions and 10 deletions
|
|
@ -93,6 +93,10 @@ pub struct EnablePlugins {
|
|||
/// Enable the Next.js plugin and detect Next.js problems
|
||||
#[bpaf(switch, hide_usage)]
|
||||
pub nextjs_plugin: bool,
|
||||
|
||||
/// Enable the React performance plugin and detect rendering performance problems
|
||||
#[bpaf(switch, hide_usage)]
|
||||
pub react_perf_plugin: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Bpaf)]
|
||||
|
|
|
|||
|
|
@ -100,7 +100,8 @@ impl Runner for LintRunner {
|
|||
.with_import_plugin(enable_plugins.import_plugin)
|
||||
.with_jest_plugin(enable_plugins.jest_plugin)
|
||||
.with_jsx_a11y_plugin(enable_plugins.jsx_a11y_plugin)
|
||||
.with_nextjs_plugin(enable_plugins.nextjs_plugin);
|
||||
.with_nextjs_plugin(enable_plugins.nextjs_plugin)
|
||||
.with_react_perf_plugin(enable_plugins.react_perf_plugin);
|
||||
|
||||
let linter = match Linter::from_options(lint_options) {
|
||||
Ok(lint_service) => lint_service,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ pub struct LintOptions {
|
|||
pub jest_plugin: bool,
|
||||
pub jsx_a11y_plugin: bool,
|
||||
pub nextjs_plugin: bool,
|
||||
pub react_perf_plugin: bool,
|
||||
}
|
||||
|
||||
impl Default for LintOptions {
|
||||
|
|
@ -40,6 +41,7 @@ impl Default for LintOptions {
|
|||
jest_plugin: false,
|
||||
jsx_a11y_plugin: false,
|
||||
nextjs_plugin: false,
|
||||
react_perf_plugin: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,6 +96,12 @@ impl LintOptions {
|
|||
self.nextjs_plugin = yes;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_react_perf_plugin(mut self, yes: bool) -> Self {
|
||||
self.react_perf_plugin = yes;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
|
|
@ -154,6 +162,7 @@ impl TryFrom<&Number> for AllowWarnDeny {
|
|||
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
|
||||
|
|
@ -209,6 +218,7 @@ impl LintOptions {
|
|||
let mut rules = rules.into_iter().collect::<Vec<_>>();
|
||||
// for stable diagnostics output ordering
|
||||
rules.sort_unstable_by_key(RuleEnum::name);
|
||||
|
||||
Ok((rules, config.map(ESLintConfig::settings).unwrap_or_default()))
|
||||
}
|
||||
|
||||
|
|
@ -225,6 +235,7 @@ impl LintOptions {
|
|||
may_exclude_plugin_rules(self.jest_plugin, JEST_PLUGIN_NAME);
|
||||
may_exclude_plugin_rules(self.jsx_a11y_plugin, JSX_A11Y_PLUGIN_NAME);
|
||||
may_exclude_plugin_rules(self.nextjs_plugin, NEXTJS_PLUGIN_NAME);
|
||||
may_exclude_plugin_rules(self.react_perf_plugin, REACT_PERF_PLUGIN_NAME);
|
||||
|
||||
rules
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ declare_oxc_lint!(
|
|||
/// <Item callback={this.props.jsx} />
|
||||
/// ```
|
||||
NoJsxAsProp,
|
||||
restriction
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoJsxAsProp {
|
||||
|
|
@ -91,5 +91,5 @@ fn test() {
|
|||
r"<Item jsx={this.props.jsx || (this.props.component ? this.props.component : <SubItem />)} />",
|
||||
];
|
||||
|
||||
Tester::new(NoJsxAsProp::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new(NoJsxAsProp::NAME, pass, fail).with_react_perf_plugin(true).test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ declare_oxc_lint!(
|
|||
/// <Item list={this.props.list} />
|
||||
/// ```
|
||||
NoNewArrayAsProp,
|
||||
restriction
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoNewArrayAsProp {
|
||||
|
|
@ -113,5 +113,7 @@ fn test() {
|
|||
r"<Item list={this.props.list || (this.props.arr ? this.props.arr : [])} />",
|
||||
];
|
||||
|
||||
Tester::new(NoNewArrayAsProp::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new(NoNewArrayAsProp::NAME, pass, fail)
|
||||
.with_react_perf_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ declare_oxc_lint!(
|
|||
/// <Item callback={this.props.callback} />
|
||||
/// ```
|
||||
NoNewFunctionAsProps,
|
||||
restriction
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoNewFunctionAsProps {
|
||||
|
|
@ -139,5 +139,7 @@ fn test() {
|
|||
r"<Item prop={this.props.callback || (this.props.cb ? this.props.cb : function(){})} />",
|
||||
];
|
||||
|
||||
Tester::new(NoNewFunctionAsProps::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new(NoNewFunctionAsProps::NAME, pass, fail)
|
||||
.with_react_perf_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ declare_oxc_lint!(
|
|||
/// <Item config={staticConfig} />
|
||||
/// ```
|
||||
NoNewObjectAsProp,
|
||||
restriction
|
||||
correctness
|
||||
);
|
||||
|
||||
impl Rule for NoNewObjectAsProp {
|
||||
|
|
@ -113,5 +113,7 @@ fn test() {
|
|||
r"<Item config={this.props.config || (this.props.default ? this.props.default : {})} />",
|
||||
];
|
||||
|
||||
Tester::new(NoNewObjectAsProp::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new(NoNewObjectAsProp::NAME, pass, fail)
|
||||
.with_react_perf_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ pub struct Tester {
|
|||
jest_plugin: bool,
|
||||
jsx_a11y_plugin: bool,
|
||||
nextjs_plugin: bool,
|
||||
react_perf_plugin: bool,
|
||||
}
|
||||
|
||||
impl Tester {
|
||||
|
|
@ -91,6 +92,7 @@ impl Tester {
|
|||
jest_plugin: false,
|
||||
jsx_a11y_plugin: false,
|
||||
nextjs_plugin: false,
|
||||
react_perf_plugin: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,6 +122,11 @@ impl Tester {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_react_perf_plugin(mut self, yes: bool) -> Self {
|
||||
self.react_perf_plugin = yes;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn expect_fix<S: Into<String>>(mut self, expect_fix: Vec<(S, S, Option<Value>)>) -> Self {
|
||||
self.expect_fix =
|
||||
expect_fix.into_iter().map(|(s1, s2, r)| (s1.into(), s2.into(), r)).collect::<Vec<_>>();
|
||||
|
|
@ -188,7 +195,8 @@ impl Tester {
|
|||
.with_import_plugin(self.import_plugin)
|
||||
.with_jest_plugin(self.jest_plugin)
|
||||
.with_jsx_a11y_plugin(self.jsx_a11y_plugin)
|
||||
.with_nextjs_plugin(self.nextjs_plugin);
|
||||
.with_nextjs_plugin(self.nextjs_plugin)
|
||||
.with_react_perf_plugin(self.react_perf_plugin);
|
||||
let linter = Linter::from_options(options)
|
||||
.unwrap()
|
||||
.with_rules(vec![rule])
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ Enable Plugins
|
|||
--import-plugin Enable the experimental import plugin and detect ESM problems
|
||||
--jest-plugin Enable the Jest plugin and detect test problems
|
||||
--jsx-a11y-plugin Enable the JSX-a11y plugin and detect accessibility problems
|
||||
--nextjs-plugin Enable the Next.js plugin and detect Next.js problems
|
||||
--react-perf-plugin Enable the React performance plugin and detect rendering performance problems
|
||||
|
||||
|
||||
Fix Problems
|
||||
--fix Fix as many issues as possible. Only unfixed issues are reported in the
|
||||
|
|
|
|||
Loading…
Reference in a new issue