From 8692b563b04816353d68ac0b545fb984f5e59e5f Mon Sep 17 00:00:00 2001 From: Rory Smith Date: Thu, 12 Jan 2023 10:43:04 +0000 Subject: [PATCH 1/9] Add no-static-element-interactions --- .gitignore | 1 + src/index.ts | 2 + .../no-static-element-interactions.test.ts | 80 + src/rules/interactive-supports-focus.ts | 28 +- src/rules/no-static-element-interactions.ts | 47 + src/utils.ts | 3 + src/utils/getInteractiveRoles.ts | 18 + src/utils/interactiveHandlers.ts | 24 + src/utils/isInteractiveRole.ts | 17 + yarn.lock | 5480 +++++++++-------- 10 files changed, 2943 insertions(+), 2757 deletions(-) create mode 100644 src/rules/__tests__/no-static-element-interactions.test.ts create mode 100644 src/rules/no-static-element-interactions.ts create mode 100644 src/utils/getInteractiveRoles.ts create mode 100644 src/utils/interactiveHandlers.ts create mode 100644 src/utils/isInteractiveRole.ts diff --git a/.gitignore b/.gitignore index 0c6b94b0..29efe008 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.eslintcache /.husky/ +/.idea/ /dist/ /node_modules/ diff --git a/src/index.ts b/src/index.ts index 357798fd..32c75c79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import noAutofocus from "./rules/no-autofocus"; import noDistractingElements from "./rules/no-distracting-elements"; import noOnchange from "./rules/no-onchange"; import noRedundantRoles from "./rules/no-redundant-roles"; +import noStaticElementInteractions from "./rules/no-static-element-interactions"; import roleHasRequiredAriaProps from "./rules/role-has-required-aria-props"; import tabindexNoPositive from "./rules/tabindex-no-positive"; @@ -44,6 +45,7 @@ const plugin = { "no-distracting-elements": noDistractingElements, "no-onchange": noOnchange, "no-redundant-roles": noRedundantRoles, + "no-static-element-interactions": noStaticElementInteractions, "role-has-required-aria-props": roleHasRequiredAriaProps, "tabindex-no-positive": tabindexNoPositive } diff --git a/src/rules/__tests__/no-static-element-interactions.test.ts b/src/rules/__tests__/no-static-element-interactions.test.ts new file mode 100644 index 00000000..e911cbc6 --- /dev/null +++ b/src/rules/__tests__/no-static-element-interactions.test.ts @@ -0,0 +1,80 @@ +import rule from "../no-static-element-interactions"; +import makeRuleTester from "./makeRuleTester"; + +makeRuleTester("no-static-element-interactions", rule, { + valid: [ + // Doesn't contain relevant directives + "
", + "
", + "", + "
", + "
", + + // Contains relevant directives + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + + // Elements which don't require `role='button'` + "