tslint-ionic-rules
Version:
Common TypeScript lint rules/preferences for Ionic.
68 lines (67 loc) • 2.88 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 __());
};
})();
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
Object.defineProperty(exports, "__esModule", { value: true });
var ts = require("typescript");
var Lint = require("tslint");
// tslint:disable object-literal-sort-keys
var Rule = /** @class */ (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.applyWithProgram = function (sourceFile, program) {
var options = {};
return this.applyWithFunction(sourceFile, walk, options, program.getTypeChecker());
};
Rule.metadata = {
ruleName: "strict-boolean-conditions",
description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n "], ["\n "]))),
options: {},
optionExamples: [],
type: "functionality",
typescriptOnly: true,
requiresTypeInfo: false,
};
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
function walk(ctx, checker) {
var sourceFile = ctx.sourceFile;
// sourceFile.statements.forEach(node => {
// if (isExportDeclaration(node)) {
// ts.forEachChild(node, child => {
// if (child.kind === ts.SyntaxKind.EnumDeclaration) {
// console.log(node);
// }
// });
// }
// });
ts.forEachChild(sourceFile, function cb(node) {
if (node.kind === ts.SyntaxKind.EnumDeclaration && node.modifiers) {
var isConst = node.modifiers.some(function (a) { return a.kind === ts.SyntaxKind.ConstKeyword; });
var isExport = node.modifiers.some(function (a) { return a.kind === ts.SyntaxKind.ExportKeyword; });
if (isConst && isExport) {
ctx.addFailureAtNode(node, 'exported const enums are not allowed');
}
}
return ts.forEachChild(node, cb);
});
}
var templateObject_1, templateObject_2;