1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var ts = require("typescript");
|
17 | var Lint = require("tslint");
|
18 | var tsutils = require("tsutils");
|
19 | var JsxAttribute_1 = require("./utils/JsxAttribute");
|
20 | function getFailureString() {
|
21 | return 'The value of tabindex attribute is invalid or undefined. It must be either -1 or 0.';
|
22 | }
|
23 | exports.getFailureString = getFailureString;
|
24 | var Rule = (function (_super) {
|
25 | __extends(Rule, _super);
|
26 | function Rule() {
|
27 | return _super !== null && _super.apply(this, arguments) || this;
|
28 | }
|
29 | Rule.prototype.apply = function (sourceFile) {
|
30 | return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithFunction(sourceFile, walk) : [];
|
31 | };
|
32 | Rule.metadata = {
|
33 | ruleName: 'react-a11y-tabindex-no-positive',
|
34 | type: 'maintainability',
|
35 | description: 'Enforce tabindex value is **not greater than zero**.',
|
36 | rationale: "References:\n <ul>\n <li><a href=\"https://www.w3.org/TR/2008/REC-WCAG20-20081211/#navigation-mechanisms-focus-order\">WCAG 2.4.3 - Focus Order</a></li>\n <li><a href=\"https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#tabindex-usage\">Audit Rules - tabindex-usage</a></li>\n <li><a href=\"https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_focus_03\">Avoid positive integer values for tabIndex</a></li>\n </ul>",
|
37 | options: null,
|
38 | optionsDescription: '',
|
39 | typescriptOnly: true,
|
40 | issueClass: 'Non-SDL',
|
41 | issueType: 'Warning',
|
42 | severity: 'Important',
|
43 | level: 'Opportunity for Excellence',
|
44 | group: 'Accessibility'
|
45 | };
|
46 | return Rule;
|
47 | }(Lint.Rules.AbstractRule));
|
48 | exports.Rule = Rule;
|
49 | function walk(ctx) {
|
50 | function cb(node) {
|
51 | if (tsutils.isJsxAttribute(node)) {
|
52 | var name_1 = JsxAttribute_1.getPropName(node);
|
53 | if (!name_1 || name_1.toLowerCase() !== 'tabindex') {
|
54 | return;
|
55 | }
|
56 | var literalString = JsxAttribute_1.getNumericLiteral(node) || JsxAttribute_1.getStringLiteral(node);
|
57 | if (literalString === '') {
|
58 | ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
|
59 | }
|
60 | else if (literalString && literalString !== '-1' && literalString !== '0') {
|
61 | ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
|
62 | }
|
63 | else if (JsxAttribute_1.isEmpty(node)) {
|
64 | ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
|
65 | }
|
66 | }
|
67 | return ts.forEachChild(node, cb);
|
68 | }
|
69 | return ts.forEachChild(ctx.sourceFile, cb);
|
70 | }
|
71 |
|
\ | No newline at end of file |