Skip to content

Commit

Permalink
Closes #52 - add new require-module rule (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclindner authored Sep 2, 2017
1 parent 13a568d commit 18b261d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Removed


## [2.11.0] - 2017-09-02
### Added
- New rule: [require-module](https://github.com/tclindner/npm-package-json-lint/wiki/require-module)

## [2.10.0] - 2017-09-02
### Changed
- Addressed issues, from @moshest, [#57](https://github.com/tclindner/npm-package-json-lint/issues/57) and [#58](https://github.com/tclindner/npm-package-json-lint/issues/58). This change gives better recommendations for what change is required by the user to resolve the lint issue. It also no longer throws an error when a property exists in the package.json file that doesn't exist in the preferred property order array. Thanks @moshest.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-package-json-lint",
"version": "2.10.0",
"version": "2.11.0",
"description": "CLI app for linting package.json files.",
"keywords": [
"lint",
Expand Down
18 changes: 18 additions & 0 deletions src/rules/require-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const LintIssue = require('./../LintIssue');
const lintId = 'require-module';
const nodeName = 'module';
const message = 'module is required';
const ruleType = 'standard';

const lint = function(packageJsonData, lintType) {
if (!packageJsonData.hasOwnProperty(nodeName)) {
return new LintIssue(lintId, lintType, nodeName, message);
}

return true;
};

module.exports.lint = lint;
module.exports.ruleType = ruleType;
39 changes: 39 additions & 0 deletions tests/unit/rules/require-module.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const chai = require('chai');
const ruleModule = require('./../../../src/rules/require-module');
const lint = ruleModule.lint;
const ruleType = ruleModule.ruleType;

const should = chai.should();

describe('require-module Unit Tests', function() {
context('a rule type value should be exported', function() {
it('it should equal "standard"', function() {
ruleType.should.equal('standard');
});
});

context('when package.json has node', function() {
it('true should be returned', function() {
const packageJsonData = {
module: 'module'
};
const response = lint(packageJsonData, 'error');

response.should.be.true;
});
});

context('when package.json does not have node', function() {
it('LintIssue object should be returned', function() {
const packageJsonData = {};
const response = lint(packageJsonData, 'error');

response.lintId.should.equal('require-module');
response.lintType.should.equal('error');
response.node.should.equal('module');
response.lintMessage.should.equal('module is required');
});
});
});

0 comments on commit 18b261d

Please sign in to comment.