From 85e9ed9a81ec816d25ee74062e4aab9d545a736e Mon Sep 17 00:00:00 2001 From: Rich Harris <richard.a.harris@gmail.com> Date: Sun, 3 Sep 2017 18:42:26 -0400 Subject: [PATCH] tabindex-no-positive --- src/validate/html/a11y.ts | 8 ++++++++ .../samples/a11y-tabindex-no-positive/input.html | 4 ++++ .../samples/a11y-tabindex-no-positive/warnings.json | 10 ++++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/validator/samples/a11y-tabindex-no-positive/input.html create mode 100644 test/validator/samples/a11y-tabindex-no-positive/warnings.json diff --git a/src/validate/html/a11y.ts b/src/validate/html/a11y.ts index 0b34c9b451..205a6388f5 100644 --- a/src/validate/html/a11y.ts +++ b/src/validate/html/a11y.ts @@ -78,6 +78,14 @@ export default function a11y( validator.warn(`A11y: The scope attribute should only be used with <th> elements`, attribute.start); } + // tabindex-no-positive + if (name === 'tabindex') { + const value = getStaticAttributeValue(node, 'tabindex'); + if (!isNaN(value) && +value > 0) { + validator.warn(`A11y: avoid tabindex values above zero`, attribute.start); + } + } + attributeMap.set(attribute.name, attribute); }); diff --git a/test/validator/samples/a11y-tabindex-no-positive/input.html b/test/validator/samples/a11y-tabindex-no-positive/input.html new file mode 100644 index 0000000000..fa34d69f2d --- /dev/null +++ b/test/validator/samples/a11y-tabindex-no-positive/input.html @@ -0,0 +1,4 @@ +<div tabindex='-1'/> +<div tabindex='0'/> +<div tabindex='1'/> +<div tabindex='{{foo}}'/> \ No newline at end of file diff --git a/test/validator/samples/a11y-tabindex-no-positive/warnings.json b/test/validator/samples/a11y-tabindex-no-positive/warnings.json new file mode 100644 index 0000000000..6c163a8834 --- /dev/null +++ b/test/validator/samples/a11y-tabindex-no-positive/warnings.json @@ -0,0 +1,10 @@ +[ + { + "message": "A11y: avoid tabindex values above zero", + "loc": { + "line": 3, + "column": 5 + }, + "pos": 46 + } +]