tslint-config-security
Version:
TSLint security rules
43 lines (42 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("tslint");
var ts = require("typescript");
var Rule = (function (_super) {
tslib_1.__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: 'tsr-detect-unsafe-properties-access',
description: 'Warns when potential unsafe access to the object properties is found',
descriptionDetails: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["Any potential unsafe access to the object properties\n will trigger a warning.\n See https://github.com/webschik/tslint-config-security#tsr-detect-unsafe-properties-access"], ["Any potential unsafe access to the object properties\n will trigger a warning.\n See https://github.com/webschik/tslint-config-security#tsr-detect-unsafe-properties-access"]))),
optionsDescription: '',
options: null,
type: 'functionality',
requiresTypeInfo: false,
typescriptOnly: false
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
function visitNode(node) {
if (node.kind === ts.SyntaxKind.CallExpression) {
var _a = node, expression = _a.expression, args = _a.arguments;
if (expression &&
args &&
expression.kind === ts.SyntaxKind.ElementAccessExpression &&
args.find(ts.isIdentifier)) {
ctx.addFailureAtNode(node, 'Found unsafe properties access');
}
}
return ts.forEachChild(node, visitNode);
}
return ts.forEachChild(ctx.sourceFile, visitNode);
}
var templateObject_1;