feat: added rule tabindex-no-positive
MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -153,6 +153,7 @@ type LintDiagnosticCategory =
| "lint/jsx-a11y/noDistractingElements"
| "lint/jsx-a11y/noTargetBlank"
| "lint/jsx-a11y/scope"
+ | "lint/jsx-a11y/tabindexNoPositive"
| "lint/react/jsxKey"
| "lint/react/jsxNoCommentText"
| "lint/react/noChildrenProp"

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -292,6 +292,10 @@ export const descriptions = createMessages({
},
// @romejs/js-compiler
LINT: {
+ JSX_A11Y_TABINDEX_NO_POSITIVE: {
+ category: "lint/jsx-a11y/tabindexNoPositive",
+ message: "Avoid positive integer values for <emphasis>tabIndex</emphasis>.",
+ },
REACT_NO_WILL_UPDATE_SET_STATE: {
category: "lint/react/noWillUpdateSetState",
message: "Avoid <emphasis>this.setState</emphasis> in <emphasis>componentWillUpdate</emphasis>",

MODIFY
packages/@romejs/js-compiler/lint/rules/index.ts
packages/@romejs/js-compiler/lint/rules/index.ts
@@ -67,6 +67,7 @@ import noAutofocus from "./jsx-a11y/noAutofocus";
import noDistractingElements from "./jsx-a11y/noDistractingElements";
import noTargetBlank from "./jsx-a11y/noTargetBlank";
import scope from "./jsx-a11y/scope";
+import tabindexNoPositive from "./jsx-a11y/tabindexNoPositive";
import jsxKey from "./react/jsxKey";
import jsxNoCommentText from "./react/jsxNoCommentText";
import noChildrenProp from "./react/noChildrenProp";
@@ -142,6 +143,7 @@ export const lintTransforms = [
noDistractingElements,
noTargetBlank,
scope,
+ tabindexNoPositive,
jsxKey,
jsxNoCommentText,
noChildrenProp,

ADD
packages/@romejs/js-compiler/lint/rules/jsx-a11y/tabindexNoPositive.test.ts
+import {test} from "rome";
+import {testLintMultiple} from "../testHelpers";
+
+test(
+ "no tabindex positive",
+ async (t) => {
+ await testLintMultiple(
+ t,
+ [
+ // INVALID
+ "<span tabIndex='5'>foo</span>",
+ "<span tabIndex={5}>foo</span>",
+ // VALID
+ "<span tabIndex={0}>baz</span>",
+ "<span tabIndex={-1}>baz</span>",
+ "<span tabIndex='-1'>baz</span>",
+ "<span tabIndex='0'>baz</span>",
+ ],
+ {category: "lint/jsx-a11y/tabindexNoPositive"},
+ );
+ },
+);

ADD
packages/@romejs/js-compiler/lint/rules/jsx-a11y/tabindexNoPositive.ts
+import {Path, TransformExitResult} from "@romejs/js-compiler";
+import {descriptions} from "@romejs/diagnostics";
+import {
+ getJSXAttribute,
+ hasJSXAttribute,
+ isJSXElement,
+} from "@romejs/js-ast-utils";
+
+export default {
+ name: "tabindexNoPositive",
+ enter(path: Path): TransformExitResult {
+ const {node} = path;
+
+ if (isJSXElement(node) && hasJSXAttribute(node, "tabIndex")) {
+ const attribute = getJSXAttribute(node, "tabIndex");
+ if (
+ attribute &&
+ attribute.value &&
+ attribute.value.type === "JSStringLiteral"
+ ) {
+ const tabIndexValue = attribute.value.value;
+ if (Number(tabIndexValue) > 0) {
+ path.context.addNodeDiagnostic(
+ node,
+ descriptions.LINT.JSX_A11Y_TABINDEX_NO_POSITIVE,
+ );
+ }
+ }
+
+ if (
+ attribute &&
+ attribute.value &&
+ attribute.value.type === "JSXExpressionContainer"
+ ) {
+ const expression = attribute.value.expression;
+ if (expression.type === "JSNumericLiteral") {
+ const tabIndexValue = expression.value;
+ if (Number(tabIndexValue) > 0) {
+ path.context.addNodeDiagnostic(
+ node,
+ descriptions.LINT.JSX_A11Y_TABINDEX_NO_POSITIVE,
+ );
+ }
+ }
+ }
+ }
+ return node;
+ },
+};

feat: added rule tabindex-no-positive