tslint-config-shopify
Version:
Shopify's baseline TSLint config.
56 lines (55 loc) • 2.61 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var 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 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 Lint = require("tslint");
var TrailingCommaInterfaceWalker = (function (_super) {
__extends(TrailingCommaInterfaceWalker, _super);
function TrailingCommaInterfaceWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
TrailingCommaInterfaceWalker.prototype.visitInterfaceDeclaration = function (node) {
var _this = this;
node.members
.filter(function (propertySignature) { return propertySignature.getText().slice(-1) !== ','; })
.forEach(function (propertySignature) {
var lastChar = propertySignature.getText().slice(-1);
var lastCharPosition = propertySignature.getStart() + propertySignature.getWidth() - 1;
var replacementText = (lastChar === ';') ? "," : lastChar + ",";
var fixer = new Lint.Replacement(lastCharPosition, 1, replacementText);
_this.addFailureAt(lastCharPosition, 1, TrailingCommaInterfaceWalker.FAILURE_STRING, fixer);
});
};
TrailingCommaInterfaceWalker.FAILURE_STRING = 'Trailing comma is required in interfaces properties.';
return TrailingCommaInterfaceWalker;
}(Lint.RuleWalker));
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new TrailingCommaInterfaceWalker(sourceFile, this.getOptions()));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
'ruleName': 'trailing-comma-interface',
'description': 'Enforce trailing commas in interface properties.',
'rationale': 'Our team prefers traling commas over trailing semicolons.',
'optionsDescription': 'Not configurable.',
'options': null,
'type': 'typescript',
'typescriptOnly': true,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
;