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 | var ARIA_SCHEMA = require('./utils/attributes/ariaSchema.json');
|
17 | function getFailureString(name) {
|
18 | return "This attribute name '" + name + "' is an invalid ARIA attribute. A reference to valid ARIA attributes can be found at https://www.w3.org/TR/2014/REC-wai-aria-20140320/states_and_properties#state_prop_def ";
|
19 | }
|
20 | exports.getFailureString = getFailureString;
|
21 | var Rule = (function (_super) {
|
22 | __extends(Rule, _super);
|
23 | function Rule() {
|
24 | return _super !== null && _super.apply(this, arguments) || this;
|
25 | }
|
26 | Rule.prototype.apply = function (sourceFile) {
|
27 | return sourceFile.languageVariant === ts.LanguageVariant.JSX
|
28 | ? this.applyWithWalker(new A11yPropsWalker(sourceFile, this.getOptions()))
|
29 | : [];
|
30 | };
|
31 | Rule.metadata = {
|
32 | ruleName: 'react-a11y-props',
|
33 | type: 'maintainability',
|
34 | description: 'Enforce all `aria-*` attributes are valid. Elements cannot use an invalid `aria-*` attribute.',
|
35 | options: null,
|
36 | optionsDescription: '',
|
37 | typescriptOnly: true,
|
38 | issueClass: 'Non-SDL',
|
39 | issueType: 'Warning',
|
40 | severity: 'Important',
|
41 | level: 'Opportunity for Excellence',
|
42 | group: 'Accessibility'
|
43 | };
|
44 | return Rule;
|
45 | }(Lint.Rules.AbstractRule));
|
46 | exports.Rule = Rule;
|
47 | var A11yPropsWalker = (function (_super) {
|
48 | __extends(A11yPropsWalker, _super);
|
49 | function A11yPropsWalker() {
|
50 | return _super !== null && _super.apply(this, arguments) || this;
|
51 | }
|
52 | A11yPropsWalker.prototype.visitJsxAttribute = function (node) {
|
53 | var name = JsxAttribute_1.getPropName(node);
|
54 | if (!name || !name.match(/^aria-/i)) {
|
55 | return;
|
56 | }
|
57 | if (!ARIA_SCHEMA[name.toLowerCase()]) {
|
58 | this.addFailureAt(node.getStart(), node.getWidth(), getFailureString(name));
|
59 | }
|
60 | };
|
61 | return A11yPropsWalker;
|
62 | }(Lint.RuleWalker));
|
63 |
|
\ | No newline at end of file |