0.5.3 • Published 10 years ago
gulp-limit-complexity v0.5.3
gulp limit complexity
Limit complexity in JavaScript projects by failing build if function exceed limits.
Using Mozilla's JavaScript tree mapper to parse functions, and escomplex to calculate the complexity of every function. This is mainly useful for keeping third-party developers honest and to a certain level of quality. Can also be useful on large teams as a kind of contract for how complex or readable their code must be.
##Install
npm install gulp-limit-complexity
##Example
var limitComplexity = require('gulp-limit-complexity');
gulp.task('complexity', function () {
return gulp.src(path.src.js)
.pipe(limitComplexity({
cyclomatic: 4, //maximum of 4 code paths through any function
halstead: {
vocabulary: 10 //maximum of ten for vocabulary
}
}));
});
##Another example
var limitComplexity = require('gulp-limit-complexity');
gulp.task('complexity', function () {
return gulp.src(path.src.js)
.pipe(limitComplexity({
halstead: {
difficulty: 14 //difficulty represents readability
},
params: 3 //functions can only have a maximum of three parameters
}));
});
##Another example
var limitComplexity = require('gulp-limit-complexity');
gulp.task('complexity', function () {
return gulp.src(path.src.js)
.pipe(limitComplexity({
halstead: {
operands {
distinct: 6 //only six unique operands each function
}
}
}));
});