oxc/tasks/rulegen/template.txt

78 lines
2.2 KiB
Text

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
context::LintContext,
fixer::{RuleFix, RuleFixer},
rule::Rule,
AstNode,
};
fn {{snake_rule_name}}_diagnostic(span: Span) -> OxcDiagnostic {
// See <https://oxc.rs/docs/contribute/linter/adding-rules.html#diagnostics> for details
OxcDiagnostic::warn("Should be an imperative statement about what is wrong")
.with_help("Should be a command-like statement that tells the user how to fix the issue")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct {{pascal_rule_name}};
declare_oxc_lint!(
/// ### What it does
///
///
/// ### Why is this bad?
///
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```{{language}}
/// FIXME: Tests will fail if examples are missing or syntactically incorrect.
/// ```
///
/// Examples of **correct** code for this rule:
/// ```{{language}}
/// FIXME: Tests will fail if examples are missing or syntactically incorrect.
/// ```
{{pascal_rule_name}},
nursery, // TODO: change category to `correctness`, `suspicious`, `pedantic`, `perf`, `restriction`, or `style`
// See <https://oxc.rs/docs/contribute/linter.html#rule-category> for details
pending // TODO: describe fix capabilities. Remove if no fix can be done,
// keep at 'pending' if you think one could be added but don't know how.
// Options are 'fix', 'fix_dangerous', 'suggestion', and 'conditional_fix_suggestion'
);
impl Rule for {{pascal_rule_name}} {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
}
}
#[test]
fn test() {
use crate::tester::Tester;
{{#if has_filename}}
use std::path::PathBuf;
{{/if}}
let pass = vec![
{{pass_cases}}
];
let fail = vec![
{{fail_cases}}
];
{{#if fix_cases}}
let fix = vec![
{{fix_cases}}
];
Tester::new({{pascal_rule_name}}::NAME, {{pascal_rule_name}}::CATEGORY, pass, fail).expect_fix(fix).test_and_snapshot();
{{else}}
Tester::new({{pascal_rule_name}}::NAME, {{pascal_rule_name}}::CATEGORY, pass, fail).test_and_snapshot();
{{/if}}
}