Permalink
Browse files

Add absolute version (dev)dependencies rule (#36)

* Feature add absolute dep rule

* Feature add absolute devDep rule
  • Loading branch information...
chr1shaefn3r authored and tclindner committed May 24, 2017
1 parent 2a85ec9 commit e5c03814dc91e7be857ade3fe9fcc795fcad28af
@@ -0,0 +1,21 @@
'use strict';
const areVersRangesValid = require('./../validators/dependency-audit').areVersRangesValid;
const LintIssue = require('./../LintIssue');
const lintId = 'prefer-absolute-version-dependencies';
const nodeName = 'dependencies';
const message = 'You are using an invalid version range. Please use absolute versions.';
const ruleType = 'dependencies-version-range';
const lint = function(packageJsonData, lintType) {
const rangeSpecifier = '=';
if (!areVersRangesValid(packageJsonData, nodeName, rangeSpecifier)) {
return new LintIssue(lintId, lintType, nodeName, message);
}
return true;
};
module.exports.lint = lint;
module.exports.ruleType = ruleType;
@@ -0,0 +1,21 @@
'use strict';
const areVersRangesValid = require('./../validators/dependency-audit').areVersRangesValid;
const LintIssue = require('./../LintIssue');
const lintId = 'prefer-absolute-version-devDependencies';
const nodeName = 'devDependencies';
const message = 'You are using an invalid version range. Please use absolute versions.';
const ruleType = 'devDependencies-version-range';
const lint = function(packageJsonData, lintType) {
const rangeSpecifier = '=';
if (!areVersRangesValid(packageJsonData, nodeName, rangeSpecifier)) {
return new LintIssue(lintId, lintType, nodeName, message);
}
return true;
};
module.exports.lint = lint;
module.exports.ruleType = ruleType;
@@ -0,0 +1,45 @@
'use strict';
const should = require('should');
const requireHelper = require('../../require_helper');
const lint = requireHelper('rules/prefer-absolute-version-dependencies').lint;
describe('prefer-absolute-version-dependencies Unit Tests', function() {
context('when package.json has node with an invalid value', function() {
it('LintIssue object should be returned', function() {
const packageJsonData = {
dependencies: {
'npm-package-json-lint': '~1.0.0'
}
};
const response = lint(packageJsonData, 'error');
response.lintId.should.equal('prefer-absolute-version-dependencies');
response.lintType.should.equal('error');
response.node.should.equal('dependencies');
response.lintMessage.should.equal('You are using an invalid version range. Please use absolute versions.');
});
});
context('when package.json has node with a valid value (= prefixed)', function() {
it('LintIssue object should be returned', function() {
const packageJsonData = {
dependencies: {
'gulp-npm-package-json-lint': '=1.0.0'
}
};
const response = lint(packageJsonData, 'error');
response.should.be.true();
});
});
context('when package.json does not have node', function() {
it('true should be returned', function() {
const packageJsonData = {};
const response = lint(packageJsonData, 'error');
response.should.be.true();
});
});
});
@@ -0,0 +1,45 @@
'use strict';
const should = require('should');
const requireHelper = require('../../require_helper');
const lint = requireHelper('rules/prefer-absolute-version-devDependencies').lint;
describe('prefer-absolute-version-devDependencies Unit Tests', function() {
context('when package.json has node with an invalid value', function() {
it('LintIssue object should be returned', function() {
const packageJsonData = {
devDependencies: {
'npm-package-json-lint': '~1.0.0'
}
};
const response = lint(packageJsonData, 'error');
response.lintId.should.equal('prefer-absolute-version-devDependencies');
response.lintType.should.equal('error');
response.node.should.equal('devDependencies');
response.lintMessage.should.equal('You are using an invalid version range. Please use absolute versions.');
});
});
context('when package.json has node with a valid value (= prefixed)', function() {
it('LintIssue object should be returned', function() {
const packageJsonData = {
devDependencies: {
'gulp-npm-package-json-lint': '=1.0.0'
}
};
const response = lint(packageJsonData, 'error');
response.should.be.true();
});
});
context('when package.json does not have node', function() {
it('true should be returned', function() {
const packageJsonData = {};
const response = lint(packageJsonData, 'error');
response.should.be.true();
});
});
});

0 comments on commit e5c0381

Please sign in to comment.