1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var ts = require("typescript");
|
14 | var Lint = require("tslint");
|
15 | var JsxAttribute_1 = require("./utils/JsxAttribute");
|
16 | function getFailureString() {
|
17 | return 'The value of tabindex attribute is invalid or undefined. It must be either -1 or 0.';
|
18 | }
|
19 | exports.getFailureString = getFailureString;
|
20 | var Rule = (function (_super) {
|
21 | __extends(Rule, _super);
|
22 | function Rule() {
|
23 | return _super !== null && _super.apply(this, arguments) || this;
|
24 | }
|
25 | Rule.prototype.apply = function (sourceFile) {
|
26 | return sourceFile.languageVariant === ts.LanguageVariant.JSX
|
27 | ? this.applyWithWalker(new A11yTabindexNoPositiveWalker(sourceFile, this.getOptions()))
|
28 | : [];
|
29 | };
|
30 | Rule.metadata = {
|
31 | ruleName: 'react-a11y-tabindex-no-positive',
|
32 | type: 'maintainability',
|
33 | description: 'Enforce tabindex value is **not greater than zero**.',
|
34 | options: null,
|
35 | optionsDescription: '',
|
36 | typescriptOnly: true,
|
37 | issueClass: 'Non-SDL',
|
38 | issueType: 'Warning',
|
39 | severity: 'Important',
|
40 | level: 'Opportunity for Excellence',
|
41 | group: 'Accessibility'
|
42 | };
|
43 | return Rule;
|
44 | }(Lint.Rules.AbstractRule));
|
45 | exports.Rule = Rule;
|
46 | var A11yTabindexNoPositiveWalker = (function (_super) {
|
47 | __extends(A11yTabindexNoPositiveWalker, _super);
|
48 | function A11yTabindexNoPositiveWalker() {
|
49 | return _super !== null && _super.apply(this, arguments) || this;
|
50 | }
|
51 | A11yTabindexNoPositiveWalker.prototype.visitJsxAttribute = function (node) {
|
52 | var name = JsxAttribute_1.getPropName(node);
|
53 | if (!name || name.toLowerCase() !== 'tabindex') {
|
54 | return;
|
55 | }
|
56 | var literalString = JsxAttribute_1.getNumericLiteral(node) || JsxAttribute_1.getStringLiteral(node);
|
57 | if (literalString === '') {
|
58 | this.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
|
59 | }
|
60 | else if (literalString && literalString !== '-1' && literalString !== '0') {
|
61 | this.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
|
62 | }
|
63 | else if (JsxAttribute_1.isEmpty(node)) {
|
64 | this.addFailureAt(node.getStart(), node.getWidth(), getFailureString());
|
65 | }
|
66 | };
|
67 | return A11yTabindexNoPositiveWalker;
|
68 | }(Lint.RuleWalker));
|
69 |
|
\ | No newline at end of file |