tslint-microsoft-contrib
Version:
TSLint Rules for Microsoft
57 lines • 2.24 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var ts = require("typescript");
var Lint = require("tslint");
var tsutils = require("tsutils");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
Rule.metadata = {
ruleName: 'no-regex-spaces',
type: 'maintainability',
description: 'Do not use multiple spaces in a regular expression literal. Similar to the ESLint no-regex-spaces rule',
options: null,
optionsDescription: '',
typescriptOnly: true,
issueClass: 'Non-SDL',
issueType: 'Error',
severity: 'Critical',
level: 'Opportunity for Excellence',
group: 'Correctness'
};
Rule.FAILURE_STRING = 'Spaces in regular expressions are hard to count. Use ';
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
function cb(node) {
if (tsutils.isRegularExpressionLiteral(node)) {
var match = /( {2,})+?/.exec(node.getText());
if (match !== null) {
var replacement = '{' + match[0].length + '}';
ctx.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + replacement);
}
}
return ts.forEachChild(node, cb);
}
return ts.forEachChild(ctx.sourceFile, cb);
}
//# sourceMappingURL=noRegexSpacesRule.js.map