Skip to content

Commit

Permalink
feat(linter): eslint-plugin-next/no-html-link-for-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed May 7, 2024
1 parent 219e1ab commit bb3617c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ mod nextjs {
pub mod no_duplicate_head;
pub mod no_head_element;
pub mod no_head_import_in_document;
pub mod no_html_link_for_pages;
pub mod no_img_element;
pub mod no_page_custom_font;
pub mod no_script_component_in_head;
Expand Down Expand Up @@ -705,6 +706,7 @@ oxc_macros::declare_all_lint_rules! {
nextjs::no_before_interactive_script_outside_document,
nextjs::no_page_custom_font,
nextjs::no_styled_jsx_in_document,
nextjs::no_html_link_for_pages,
jsdoc::check_access,
jsdoc::check_property_names,
jsdoc::check_tag_names,
Expand Down
46 changes: 46 additions & 0 deletions crates/oxc_linter/src/rules/nextjs/no_html_link_for_pages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use oxc_diagnostics::{
miette::{self, Diagnostic},
thiserror::{self, Error},
};
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{context::LintContext, rule::Rule, AstNode};

#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-next(no-html-link-for-pages):")]
#[diagnostic(severity(warning), help(""))]
struct NoHtmlLinkForPagesDiagnostic(#[label] pub Span);

#[derive(Debug, Default, Clone)]
pub struct NoHtmlLinkForPages;

declare_oxc_lint!(
/// ### What it does
///
///
/// ### Why is this bad?
///
///
/// ### Example
/// ```javascript
/// ```
NoHtmlLinkForPages,
nursery, // TODO: change category to `correctness`, `suspicious`, `pedantic`, `perf`, `restriction`, or `style`
// See <https://oxc-project.github.io/docs/contribute/linter.html#rule-category> for details
);

impl Rule for NoHtmlLinkForPages {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {}
}

#[test]
fn test() {
use crate::tester::Tester;

let pass = vec![];

let fail = vec![];

Tester::new(NoHtmlLinkForPages::NAME, pass, fail).with_nextjs_plugin(true).test_and_snapshot();
}
11 changes: 9 additions & 2 deletions crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ impl Tester {
let rule_path = PathBuf::from(rule_name.replace('-', "_")).with_extension("tsx");
let expect_pass = expect_pass.into_iter().map(Into::into).collect::<Vec<_>>();
let expect_fail = expect_fail.into_iter().map(Into::into).collect::<Vec<_>>();
let current_working_directory =
env::current_dir().unwrap().join("fixtures/import").into_boxed_path();
let current_working_directory = env::current_dir().unwrap().into_boxed_path();
Self {
rule_name,
rule_path,
Expand All @@ -116,6 +115,10 @@ impl Tester {

pub fn with_import_plugin(mut self, yes: bool) -> Self {
self.import_plugin = yes;
if yes {
self.current_working_directory =
self.current_working_directory.join("fixtures/import").into_boxed_path();
}
self
}

Expand All @@ -131,6 +134,10 @@ impl Tester {

pub fn with_nextjs_plugin(mut self, yes: bool) -> Self {
self.nextjs_plugin = yes;
if yes {
self.current_working_directory =
self.current_working_directory.join("fixtures/nextjs").into_boxed_path();
}
self
}

Expand Down

0 comments on commit bb3617c

Please sign in to comment.