tslint-clean-code
Version:
TSLint rules for enforcing Clean Code
115 lines • 5.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var TestHelper_1 = require("./TestHelper");
var idLengthRule_1 = require("../idLengthRule");
describe('idLengthRule', function () {
var ruleName = 'id-length';
context('default options', function () {
it('should pass on identifiers with length 2', function () {
var script = "\n let x1;\n const y1;\n function f1() {}\n class c1() {}\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, []);
});
it('should fail on identifiers with length 1', function () {
var script = "\n let x;\n const y;\n function f() {}\n class c() {}\n ";
TestHelper_1.TestHelper.assertViolations(ruleName, script, [
{
failure: idLengthRule_1.FAILURE_MIN_STRING + ': x',
name: 'file.ts',
ruleName: 'id-length',
ruleSeverity: 'ERROR',
startPosition: {
character: 21,
line: 2,
},
},
{
failure: idLengthRule_1.FAILURE_MIN_STRING + ': y',
name: 'file.ts',
ruleName: 'id-length',
ruleSeverity: 'ERROR',
startPosition: {
character: 23,
line: 3,
},
},
{
failure: idLengthRule_1.FAILURE_MIN_STRING + ': f',
name: 'file.ts',
ruleName: 'id-length',
ruleSeverity: 'ERROR',
startPosition: {
character: 26,
line: 4,
},
},
{
failure: idLengthRule_1.FAILURE_MIN_STRING + ': c',
name: 'file.ts',
ruleName: 'id-length',
ruleSeverity: 'ERROR',
startPosition: {
character: 23,
line: 5,
},
},
]);
});
});
context('change options', function () {
var options;
beforeEach(function () {
options = [true];
});
context('object option', function () {
context('exceptions', function () {
beforeEach(function () {
options = [
true,
{
exceptions: ['x', 'y', 'f', 'c'],
},
];
});
it('should pass on identifiers of length 1 and are exceptions', function () {
var script = "\n let x;\n const y;\n function f() {}\n class c() {}\n ";
TestHelper_1.TestHelper.assertViolationsWithOptions(ruleName, options, script, []);
});
});
context('min = 0', function () {
beforeEach(function () {
options = [
true,
{
min: 0,
},
];
});
it('should pass on identifiers of length 1', function () {
var script = "\n let x;\n const y;\n function f() {}\n class c() {}\n ";
TestHelper_1.TestHelper.assertViolationsWithOptions(ruleName, options, script, []);
});
});
});
context('array option (exception)', function () {
beforeEach(function () {
options = [true, ['x', 'y', 'f', 'c']];
});
it('should pass on identifiers of length 1 and are exceptions', function () {
var script = "\n let x;\n const y;\n function f() {}\n class c() {}\n ";
TestHelper_1.TestHelper.assertViolationsWithOptions(ruleName, options, script, []);
});
});
context('number option (minimum)', function () {
context('option = 0', function () {
beforeEach(function () {
options = [true, 0];
});
it('should pass on identifiers of length 1', function () {
var script = "\n let x;\n const y;\n function f() {}\n class c() {}\n ";
TestHelper_1.TestHelper.assertViolationsWithOptions(ruleName, options, script, []);
});
});
});
});
});
//# sourceMappingURL=IdLengthRuleTests.js.map