Skip to content

Commit

Permalink
fix(linter): use correct rule name (#2169)
Browse files Browse the repository at this point in the history
Found by accident but it should be.

- [x] react/jsx-no-comment-text-nodes
  - `jsx-no-comment-textnodes` is correct
-
https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-no-comment-textnodes.js
- [x] react/no-dangerously-set-inner-html
  - `no-danger` is correct
-
https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/no-danger.js
- [x] react-perf/no-jsx-as-prop
  - Correct name has `jsx-` prefix
-
https://github.com/cvazac/eslint-plugin-react-perf/tree/master/lib/rules
- [x] react-perf/no-new-array-as-prop
  - The same as above
- [x] react-perf/no-new-function-as-props
  - The same as above
- [x] react-perf/no-new-object-as-prop
  - The same as above
- [x] jsx-a11y/tab-index-no-positive
  - `tabindex-no-positive` is correct
-
https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/tabindex-no-positive.js
- [x] jsx-a11y/role-support-aria-props
  - `role-suports-aria-props` is correct
-
https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/role-supports-aria-props.js

- - - 

+1, 

- typescript/consistent-type-exports
- Listed in `disable-type-checked` config == This is type checking rule
but implemented
-
https://github.com/typescript-eslint/typescript-eslint/blob/8622286207b3e04ddd260eaa8ac71927d47edd7d/packages/eslint-plugin/src/configs/disable-type-checked.ts#L12
  - Should remove it..?
  • Loading branch information
leaysgur authored Jan 25, 2024
1 parent 83a54e0 commit c18619e
Show file tree
Hide file tree
Showing 17 changed files with 672 additions and 76 deletions.
32 changes: 16 additions & 16 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ mod jest {
mod react {
pub mod button_has_type;
pub mod jsx_key;
pub mod jsx_no_comment_text_nodes;
pub mod jsx_no_comment_textnodes;
pub mod jsx_no_duplicate_props;
pub mod jsx_no_target_blank;
pub mod jsx_no_undef;
pub mod jsx_no_useless_fragment;
pub mod no_children_prop;
pub mod no_dangerously_set_inner_html;
pub mod no_danger;
pub mod no_direct_mutation_state;
pub mod no_find_dom_node;
pub mod no_is_mounted;
Expand All @@ -168,10 +168,10 @@ mod react {
}

mod react_perf {
pub mod no_jsx_as_prop;
pub mod no_new_array_as_prop;
pub mod no_new_function_as_props;
pub mod no_new_object_as_prop;
pub mod jsx_no_jsx_as_prop;
pub mod jsx_no_new_array_as_prop;
pub mod jsx_no_new_function_as_props;
pub mod jsx_no_new_object_as_prop;
}

mod unicorn {
Expand Down Expand Up @@ -277,9 +277,9 @@ mod jsx_a11y {
pub mod no_redundant_roles;
pub mod prefer_tag_over_role;
pub mod role_has_required_aria_props;
pub mod role_support_aria_props;
pub mod role_supports_aria_props;
pub mod scope;
pub mod tab_index_no_positive;
pub mod tabindex_no_positive;
}

mod oxc {
Expand Down Expand Up @@ -507,13 +507,13 @@ oxc_macros::declare_all_lint_rules! {
react::button_has_type,
react::jsx_no_target_blank,
react::jsx_key,
react::jsx_no_comment_text_nodes,
react::jsx_no_comment_textnodes,
react::jsx_no_duplicate_props,
react::jsx_no_useless_fragment,
react::jsx_no_undef,
react::react_in_jsx_scope,
react::no_children_prop,
react::no_dangerously_set_inner_html,
react::no_danger,
react::no_direct_mutation_state,
react::no_find_dom_node,
react::no_render_return_value,
Expand All @@ -522,10 +522,10 @@ oxc_macros::declare_all_lint_rules! {
react::no_is_mounted,
react::no_unknown_property,
react::require_render_return,
react_perf::no_jsx_as_prop,
react_perf::no_new_array_as_prop,
react_perf::no_new_function_as_props,
react_perf::no_new_object_as_prop,
react_perf::jsx_no_jsx_as_prop,
react_perf::jsx_no_new_array_as_prop,
react_perf::jsx_no_new_function_as_props,
react_perf::jsx_no_new_object_as_prop,
import::default,
import::no_named_as_default_member,
import::no_named_as_default,
Expand Down Expand Up @@ -555,10 +555,10 @@ oxc_macros::declare_all_lint_rules! {
jsx_a11y::prefer_tag_over_role,
jsx_a11y::role_has_required_aria_props,
jsx_a11y::scope,
jsx_a11y::tab_index_no_positive,
jsx_a11y::tabindex_no_positive,
jsx_a11y::aria_role,
jsx_a11y::no_distracting_elements,
jsx_a11y::role_support_aria_props,
jsx_a11y::role_supports_aria_props,
jsx_a11y::autocomplete_valid,
oxc::approx_constant,
oxc::const_comparisons,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ declare_oxc_lint!(
/// </ul>
/// ```
///
RoleSupportAriaProps,
RoleSupportsAriaProps,
correctness
);

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

#[derive(Debug, Error, Diagnostic)]
enum RoleSupportAriaPropsDiagnostic {
#[error("eslint-plugin-jsx-a11y(role-support-aria-props): The attribute {1} is not supported by the role {2}.")]
enum RoleSupportsAriaPropsDiagnostic {
#[error("eslint-plugin-jsx-a11y(role-supports-aria-props): The attribute {1} is not supported by the role {2}.")]
#[diagnostic(severity(warning), help("Try to remove invalid attribute {1}."))]
Default(#[label] Span, String, String),

#[error("eslint-plugin-jsx-a11y(role-support-aria-props): The attribute {1} is not supported by the role {2}. This role is implicit on the element {3}.")]
#[error("eslint-plugin-jsx-a11y(role-supports-aria-props): The attribute {1} is not supported by the role {2}. This role is implicit on the element {3}.")]
#[diagnostic(severity(warning), help("Try to remove invalid attribute {1}."))]
IsImplicit(#[label] Span, String, String, String),
}

impl Rule for RoleSupportAriaProps {
impl Rule for RoleSupportsAriaProps {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
if let AstKind::JSXOpeningElement(jsx_el) = node.kind() {
if let Some(el_type) = get_element_type(ctx, jsx_el) {
Expand All @@ -81,14 +81,14 @@ impl Rule for RoleSupportAriaProps {
let name = get_jsx_attribute_name(&attr.name).to_lowercase();
if invalid_props.contains(&&name.as_str()) {
ctx.diagnostic(if is_implicit {
RoleSupportAriaPropsDiagnostic::IsImplicit(
RoleSupportsAriaPropsDiagnostic::IsImplicit(
attr.span,
name,
role_value.to_string(),
el_type.clone(),
)
} else {
RoleSupportAriaPropsDiagnostic::Default(
RoleSupportsAriaPropsDiagnostic::Default(
attr.span,
name,
role_value.to_string(),
Expand Down Expand Up @@ -1597,5 +1597,5 @@ fn test() {
(r#"<Link href="/" aria-checked />"#, None, Some(settings()), None),
];

Tester::new(RoleSupportAriaProps::NAME, pass, fail).test_and_snapshot();
Tester::new(RoleSupportsAriaProps::NAME, pass, fail).test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use crate::{

#[derive(Debug, Error, Diagnostic)]
#[error(
"eslint-plugin-jsx-a11y(tab-index-no-positive): Avoid positive integer values for tabIndex."
"eslint-plugin-jsx-a11y(tabindex-no-positive): Avoid positive integer values for tabIndex."
)]
#[diagnostic(severity(warning), help("Change the tabIndex prop to a non-negative value"))]
struct TabIndexNoPositiveDiagnostic(#[label] pub Span);
struct TabindexNoPositiveDiagnostic(#[label] pub Span);

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

declare_oxc_lint!(
/// ### What it does
Expand All @@ -39,11 +39,11 @@ declare_oxc_lint!(
/// <span tabIndex="0">foo</span>
/// <span tabIndex="-1">bar</span>
/// ```
TabIndexNoPositive,
TabindexNoPositive,
correctness
);

impl Rule for TabIndexNoPositive {
impl Rule for TabindexNoPositive {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::JSXOpeningElement(jsx_el) = node.kind() else { return };
if let Some(tab_index_prop) = has_jsx_prop_lowercase(jsx_el, "tabIndex") {
Expand All @@ -57,7 +57,7 @@ fn check_and_diagnose(attr: &JSXAttributeItem, ctx: &LintContext<'_>) {
JSXAttributeItem::Attribute(attr) => attr.value.as_ref().map_or((), |value| {
if let Ok(parsed_value) = parse_jsx_value(value) {
if parsed_value > 0.0 {
ctx.diagnostic(TabIndexNoPositiveDiagnostic(attr.span));
ctx.diagnostic(TabindexNoPositiveDiagnostic(attr.span));
}
}
}),
Expand Down Expand Up @@ -98,5 +98,5 @@ fn test() {
(r"<div tabIndex={1.589} />", None),
];

Tester::new(TabIndexNoPositive::NAME, pass, fail).test_and_snapshot();
Tester::new(TabindexNoPositive::NAME, pass, fail).test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use regex::Regex;
use crate::{context::LintContext, rule::Rule, AstNode};

#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-react(jsx-no-comment-TextNodes): Comments inside children section of tag should be placed inside braces")]
#[error("eslint-plugin-react(jsx-no-comment-textnodes): Comments inside children section of tag should be placed inside braces")]
#[diagnostic(severity(warning))]
struct JsxNoCommentTextNodesDiagnostic(#[label] pub Span);
struct JsxNoCommentTextnodesDiagnostic(#[label] pub Span);

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

declare_oxc_lint!(
/// ### What it does
Expand Down Expand Up @@ -49,16 +49,16 @@ declare_oxc_lint!(
/// return <div>{/* empty div */}</div>;
/// }
/// ```
JsxNoCommentTextNodes,
JsxNoCommentTextnodes,
suspicious
);

impl Rule for JsxNoCommentTextNodes {
impl Rule for JsxNoCommentTextnodes {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::JSXText(jsx_text) = node.kind() else { return };

if control_patterns(&jsx_text.value) {
ctx.diagnostic(JsxNoCommentTextNodesDiagnostic(jsx_text.span));
ctx.diagnostic(JsxNoCommentTextnodesDiagnostic(jsx_text.span));
}
}
}
Expand Down Expand Up @@ -309,5 +309,5 @@ fn test() {
),
];

Tester::new(JsxNoCommentTextNodes::NAME, pass, fail).test_and_snapshot();
Tester::new(JsxNoCommentTextnodes::NAME, pass, fail).test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::{
#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-react(no-danger): Do not use `dangerouslySetInnerHTML` prop")]
#[diagnostic(severity(warning), help("`dangerouslySetInnerHTML` is a way to inject HTML into your React component. This is dangerous because it can easily lead to XSS vulnerabilities."))]
struct NoDangerouslySetInnerHtmlDiagnostic(#[label] pub Span);
struct NoDangerDiagnostic(#[label] pub Span);

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

declare_oxc_lint!(
/// ### What it does
Expand All @@ -37,18 +37,18 @@ declare_oxc_lint!(
/// ### Example
/// ```javascript
/// ```
NoDangerouslySetInnerHtml,
NoDanger,
restriction
);

impl Rule for NoDangerouslySetInnerHtml {
impl Rule for NoDanger {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
match node.kind() {
AstKind::JSXElement(jsx_elem) => {
if let Some(JSXAttributeItem::Attribute(prop)) =
has_jsx_prop(&jsx_elem.opening_element, "dangerouslySetInnerHTML")
{
ctx.diagnostic(NoDangerouslySetInnerHtmlDiagnostic(prop.name.span()));
ctx.diagnostic(NoDangerDiagnostic(prop.name.span()));
}
}
AstKind::CallExpression(call_expr) => {
Expand All @@ -64,9 +64,7 @@ impl Rule for NoDangerouslySetInnerHtml {
if let ObjectPropertyKind::ObjectProperty(obj_prop) = prop {
if let Some(prop_name) = obj_prop.key.static_name() {
if prop_name.as_str() == "dangerouslySetInnerHTML" {
ctx.diagnostic(NoDangerouslySetInnerHtmlDiagnostic(
obj_prop.key.span(),
));
ctx.diagnostic(NoDangerDiagnostic(obj_prop.key.span()));
}
}
}
Expand Down Expand Up @@ -94,5 +92,5 @@ fn test() {
("React.createElement(\"button\", { dangerouslySetInnerHTML: { __html: \"baz\" } }, \"Foo\");", None),
];

Tester::new(NoDangerouslySetInnerHtml::NAME, pass, fail).test_and_snapshot();
Tester::new(NoDanger::NAME, pass, fail).test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::{context::LintContext, rule::Rule, utils::get_prop_value, AstNode};

#[derive(Debug, Error, Diagnostic)]
#[error(
"eslint-plugin-react-perf(no-jsx-as-prop): JSX attribute values should not contain other JSX."
"eslint-plugin-react-perf(jsx-no-jsx-as-prop): JSX attribute values should not contain other JSX."
)]
#[diagnostic(severity(warning), help(r"simplify props or memoize props in the parent component (https://react.dev/reference/react/memo#my-component-rerenders-when-a-prop-is-an-object-or-array)."))]
struct NoJsxAsPropDiagnostic(#[label] pub Span);
struct JsxNoJsxAsPropDiagnostic(#[label] pub Span);

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

declare_oxc_lint!(
/// ### What it does
Expand All @@ -36,11 +36,11 @@ declare_oxc_lint!(
/// // Good
/// <Item callback={this.props.jsx} />
/// ```
NoJsxAsProp,
JsxNoJsxAsProp,
correctness
);

impl Rule for NoJsxAsProp {
impl Rule for JsxNoJsxAsProp {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
if let AstKind::JSXElement(jsx_elem) = node.kind() {
check_jsx_element(jsx_elem, ctx);
Expand All @@ -57,7 +57,7 @@ fn check_jsx_element<'a>(jsx_elem: &JSXElement<'a>, ctx: &LintContext<'a>) {
..
})) => {
if let Some(span) = check_expression(expr) {
ctx.diagnostic(NoJsxAsPropDiagnostic(span));
ctx.diagnostic(JsxNoJsxAsPropDiagnostic(span));
}
}
_ => {}
Expand Down Expand Up @@ -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).with_react_perf_plugin(true).test_and_snapshot();
Tester::new(JsxNoJsxAsProp::NAME, pass, fail).with_react_perf_plugin(true).test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use crate::{
};

#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-react-perf(no-new-array-as-prop): JSX attribute values should not contain Arrays created in the same scope.")]
#[error("eslint-plugin-react-perf(jsx-no-new-array-as-prop): JSX attribute values should not contain Arrays created in the same scope.")]
#[diagnostic(severity(warning), help(r"simplify props or memoize props in the parent component (https://react.dev/reference/react/memo#my-component-rerenders-when-a-prop-is-an-object-or-array)."))]
struct NoNewArrayAsPropDiagnostic(#[label] pub Span);
struct JsxNoNewArrayAsPropDiagnostic(#[label] pub Span);

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

declare_oxc_lint!(
/// ### What it does
Expand All @@ -42,11 +42,11 @@ declare_oxc_lint!(
/// // Good
/// <Item list={this.props.list} />
/// ```
NoNewArrayAsProp,
JsxNoNewArrayAsProp,
correctness
);

impl Rule for NoNewArrayAsProp {
impl Rule for JsxNoNewArrayAsProp {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
if let AstKind::JSXElement(jsx_elem) = node.kind() {
check_jsx_element(jsx_elem, ctx);
Expand All @@ -63,7 +63,7 @@ fn check_jsx_element<'a>(jsx_elem: &JSXElement<'a>, ctx: &LintContext<'a>) {
..
})) => {
if let Some(span) = check_expression(expr) {
ctx.diagnostic(NoNewArrayAsPropDiagnostic(span));
ctx.diagnostic(JsxNoNewArrayAsPropDiagnostic(span));
}
}
_ => {}
Expand Down Expand Up @@ -113,7 +113,7 @@ fn test() {
r"<Item list={this.props.list || (this.props.arr ? this.props.arr : [])} />",
];

Tester::new(NoNewArrayAsProp::NAME, pass, fail)
Tester::new(JsxNoNewArrayAsProp::NAME, pass, fail)
.with_react_perf_plugin(true)
.test_and_snapshot();
}
Loading

0 comments on commit c18619e

Please sign in to comment.