UNPKG

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