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 | var ARIA_SCHEMA = require('./utils/attributes/ariaSchema.json');
|
21 | function getFailureString(name) {
|
22 | 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 ";
|
23 | }
|
24 | exports.getFailureString = getFailureString;
|
25 | var Rule = (function (_super) {
|
26 | __extends(Rule, _super);
|
27 | function Rule() {
|
28 | return _super !== null && _super.apply(this, arguments) || this;
|
29 | }
|
30 | Rule.prototype.apply = function (sourceFile) {
|
31 | return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithFunction(sourceFile, walk) : [];
|
32 | };
|
33 | Rule.metadata = {
|
34 | ruleName: 'react-a11y-props',
|
35 | type: 'maintainability',
|
36 | description: 'Enforce all `aria-*` attributes are valid. Elements cannot use an invalid `aria-*` attribute.',
|
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.match(/^aria-/i)) {
|
54 | return;
|
55 | }
|
56 | if (!ARIA_SCHEMA[name_1.toLowerCase()]) {
|
57 | ctx.addFailureAt(node.getStart(), node.getWidth(), getFailureString(name_1));
|
58 | }
|
59 | }
|
60 | else {
|
61 | return ts.forEachChild(node, cb);
|
62 | }
|
63 | }
|
64 | return ts.forEachChild(ctx.sourceFile, cb);
|
65 | }
|
66 |
|
\ | No newline at end of file |