mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat: nextjs plugin (#1948)
https://github.com/oxc-project/oxc/issues/1929#issuecomment-1880369624
This commit is contained in:
parent
6e0bd52af1
commit
ac3b44bd0c
11 changed files with 46 additions and 9 deletions
|
|
@ -98,6 +98,10 @@ pub struct EnablePlugins {
|
|||
/// Enable the JSX-a11y plugin and detect accessibility problems
|
||||
#[bpaf(switch, hide_usage)]
|
||||
pub jsx_a11y_plugin: bool,
|
||||
|
||||
/// Enable the Next.js plugin and detect Next.js problems
|
||||
#[bpaf(switch, hide_usage)]
|
||||
pub nextjs_plugin: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Bpaf)]
|
||||
|
|
|
|||
|
|
@ -100,7 +100,8 @@ impl Runner for LintRunner {
|
|||
.with_timing(misc_options.timing)
|
||||
.with_import_plugin(enable_plugins.import_plugin)
|
||||
.with_jest_plugin(enable_plugins.jest_plugin)
|
||||
.with_jsx_a11y_plugin(enable_plugins.jsx_a11y_plugin);
|
||||
.with_jsx_a11y_plugin(enable_plugins.jsx_a11y_plugin)
|
||||
.with_nextjs_plugin(enable_plugins.nextjs_plugin);
|
||||
|
||||
let linter = match Linter::from_options(lint_options) {
|
||||
Ok(lint_service) => lint_service,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ pub struct LintOptions {
|
|||
pub import_plugin: bool,
|
||||
pub jest_plugin: bool,
|
||||
pub jsx_a11y_plugin: bool,
|
||||
pub nextjs_plugin: bool,
|
||||
}
|
||||
|
||||
impl Default for LintOptions {
|
||||
|
|
@ -38,6 +39,7 @@ impl Default for LintOptions {
|
|||
import_plugin: false,
|
||||
jest_plugin: false,
|
||||
jsx_a11y_plugin: false,
|
||||
nextjs_plugin: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,6 +88,12 @@ impl LintOptions {
|
|||
self.jsx_a11y_plugin = yes;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_nextjs_plugin(mut self, yes: bool) -> Self {
|
||||
self.nextjs_plugin = yes;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
|
|
@ -141,6 +149,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";
|
||||
|
||||
impl LintOptions {
|
||||
/// # Errors
|
||||
|
|
@ -210,6 +219,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);
|
||||
|
||||
rules
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,5 +211,7 @@ fn test() {
|
|||
"#,
|
||||
];
|
||||
|
||||
Tester::new_without_config(GoogleFontDisplay::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(GoogleFontDisplay::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,5 +105,7 @@ fn test() {
|
|||
"#,
|
||||
];
|
||||
|
||||
Tester::new_without_config(GoogleFontPreconnect::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(GoogleFontPreconnect::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -246,5 +246,7 @@ fn test() {
|
|||
}",
|
||||
];
|
||||
|
||||
Tester::new_without_config(InlineScriptId::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(InlineScriptId::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,5 +310,7 @@ fn test() {
|
|||
}",
|
||||
];
|
||||
|
||||
Tester::new_without_config(NextScriptForGa::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(NextScriptForGa::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,5 +73,7 @@ fn test() {
|
|||
",
|
||||
];
|
||||
|
||||
Tester::new_without_config(NoAssignModuleVariable::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(NoAssignModuleVariable::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,5 +209,7 @@ fn test() {
|
|||
"#,
|
||||
];
|
||||
|
||||
Tester::new_without_config(NoAsyncClientComponent::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(NoAsyncClientComponent::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,5 +153,7 @@ fn test() {
|
|||
</div>"#,
|
||||
];
|
||||
|
||||
Tester::new_without_config(NoCssTags::NAME, pass, fail).test_and_snapshot();
|
||||
Tester::new_without_config(NoCssTags::NAME, pass, fail)
|
||||
.with_nextjs_plugin(true)
|
||||
.test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ pub struct Tester {
|
|||
import_plugin: bool,
|
||||
jest_plugin: bool,
|
||||
jsx_a11y_plugin: bool,
|
||||
nextjs_plugin: bool,
|
||||
}
|
||||
|
||||
impl Tester {
|
||||
|
|
@ -73,6 +74,7 @@ impl Tester {
|
|||
import_plugin: false,
|
||||
jest_plugin: false,
|
||||
jsx_a11y_plugin: false,
|
||||
nextjs_plugin: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +123,11 @@ impl Tester {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_nextjs_plugin(mut self, yes: bool) -> Self {
|
||||
self.nextjs_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<_>>();
|
||||
|
|
@ -187,7 +194,8 @@ impl Tester {
|
|||
.with_fix(is_fix)
|
||||
.with_import_plugin(self.import_plugin)
|
||||
.with_jest_plugin(self.jest_plugin)
|
||||
.with_jsx_a11y_plugin(self.jsx_a11y_plugin);
|
||||
.with_jsx_a11y_plugin(self.jsx_a11y_plugin)
|
||||
.with_nextjs_plugin(self.nextjs_plugin);
|
||||
let linter = Linter::from_options(options)
|
||||
.unwrap()
|
||||
.with_rules(vec![rule])
|
||||
|
|
|
|||
Loading…
Reference in a new issue