UNPKG

3.93 kBJavaScriptView Raw
1"use strict";
2var __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})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var ts = require("typescript");
14var Lint = require("tslint");
15var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
16var FAILURE_STRING = 'Do not use http-equiv="refresh"';
17var Rule = (function (_super) {
18 __extends(Rule, _super);
19 function Rule() {
20 return _super !== null && _super.apply(this, arguments) || this;
21 }
22 Rule.prototype.apply = function (sourceFile) {
23 if (sourceFile.languageVariant === ts.LanguageVariant.JSX) {
24 return this.applyWithWalker(new ReactA11yMetaRuleWalker(sourceFile, this.getOptions()));
25 }
26 else {
27 return [];
28 }
29 };
30 Rule.metadata = {
31 ruleName: 'react-a11y-meta',
32 type: 'functionality',
33 description: 'For accessibility of your website, HTML meta elements must not have http-equiv="refresh".',
34 options: null,
35 optionsDescription: '',
36 typescriptOnly: true,
37 issueClass: 'Ignored',
38 issueType: 'Warning',
39 severity: 'Low',
40 level: 'Opportunity for Excellence',
41 group: 'Accessibility'
42 };
43 return Rule;
44}(Lint.Rules.AbstractRule));
45exports.Rule = Rule;
46var ReactA11yMetaRuleWalker = (function (_super) {
47 __extends(ReactA11yMetaRuleWalker, _super);
48 function ReactA11yMetaRuleWalker() {
49 return _super !== null && _super.apply(this, arguments) || this;
50 }
51 ReactA11yMetaRuleWalker.prototype.visitJsxElement = function (node) {
52 this.validateOpeningElement(node, node.openingElement);
53 _super.prototype.visitJsxElement.call(this, node);
54 };
55 ReactA11yMetaRuleWalker.prototype.visitJsxSelfClosingElement = function (node) {
56 this.validateOpeningElement(node, node);
57 };
58 ReactA11yMetaRuleWalker.prototype.validateOpeningElement = function (parent, openElement) {
59 var _this = this;
60 if (openElement.tagName.getText() === 'meta') {
61 var attributes = openElement.attributes;
62 attributes.properties.forEach(function (parameter) {
63 if (parameter.kind === ts.SyntaxKind.JsxAttribute) {
64 var attribute = parameter;
65 if (attribute.name.getText() === 'http-equiv') {
66 if (_this.isStringLiteral(attribute.initializer, 'refresh')) {
67 _this.addFailureAt(parent.getStart(), openElement.getWidth(), FAILURE_STRING);
68 }
69 }
70 }
71 });
72 }
73 };
74 ReactA11yMetaRuleWalker.prototype.isStringLiteral = function (expression, literal) {
75 if (expression != null) {
76 if (expression.kind === ts.SyntaxKind.StringLiteral) {
77 var value = expression.text;
78 return value === literal;
79 }
80 else if (expression.kind === ts.SyntaxKind.JsxExpression) {
81 var exp = expression;
82 if (exp.expression.kind === ts.SyntaxKind.StringLiteral) {
83 var value = exp.expression.text;
84 return value === literal;
85 }
86 }
87 }
88 return null;
89 };
90 return ReactA11yMetaRuleWalker;
91}(ErrorTolerantWalker_1.ErrorTolerantWalker));
92//# sourceMappingURL=reactA11yMetaRule.js.map
\No newline at end of file