Skip to content

Commit bd74d33

Browse files
authored
Feature/1.1.0 (#16)
* version 1.1.0 Error handling if an invalid rule name is included in `.npmpackagejsonlintrc.json`. fix typo in README fix issue resolving file path of `.npmpackagejsonlintrc.json` when running the cli from a nested directory under `node_modules` * Update to throw error - use throw error - add new unit test to validate exception - bump version
1 parent be98471 commit bd74d33

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Removed
1313

14+
## [1.1.0] - 2016-07-17
15+
### Added
16+
- Error handling if an invalid rule name is included in `.npmpackagejsonlintrc.json`.
17+
18+
### Fixed
19+
- Issue resolving file path of `.npmpackagejsonlintrc.json` when running the cli from a nested directory under `node_modules`
20+
1421
## [1.0.0] - 2016-05-22
1522
### Added
1623
- New rule: [require-bin](https://github.com/tclindner/npm-package-json-lint/wiki/require-bin)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![devDependency Status](https://david-dm.org/tclindner/npm-package-json-lint/dev-status.svg?style=flat-square)](https://david-dm.org/tclindner/npm-package-json-lint#info=devDependencies)
1111

1212

13-
## What is package json lint?
13+
## What is npm-package-json-lint?
1414

1515
npm-package-json-lint helps enforce standards for your package.json file.
1616
Currently it can check for:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-package-json-lint",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "CLI app for linting package.json files.",
55
"keywords": [
66
"lint",

src/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Config {
6363
let configFile = passedConfig;
6464

6565
if (!path.isAbsolute(passedConfig)) {
66-
configFile = path.join(__dirname, passedConfig);
66+
configFile = path.join(process.cwd(), passedConfig);
6767
}
6868

6969
const rcFileObj = parser.parse(configFile);

src/Rules.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const chalk = require('chalk');
34
const fs = require('fs');
45
const path = require('path');
56

@@ -43,6 +44,14 @@ class Rules {
4344
* @return {Object} Rule
4445
*/
4546
get(ruleId) {
47+
const rule = this.rules[ruleId];
48+
49+
if (typeof rule === 'undefined') {
50+
const errorMsg = `Rule, ${ruleId}, is invalid. Please ensure it matches a valid option.`;
51+
52+
throw new Error(chalk.bold.red(errorMsg));
53+
}
54+
4655
return require(this.rules[ruleId]);
4756
}
4857

tests/unit/RulesTest.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ describe('Rules Unit Tests', function() {
2424
});
2525
});
2626

27+
describe('get method', function() {
28+
context('when get is called for an invalid ruleId', function() {
29+
before(function() {
30+
const fsStub = sinon.stub(fs, 'readdirSync');
31+
const pathStub = sinon.stub(path, 'join');
32+
33+
fsStub.onFirstCall().returns(['version-type.js', 'require-version.js']);
34+
pathStub.onFirstCall().returns('c/git/rules');
35+
pathStub.onSecondCall().returns('c/git/rules/version-type.js');
36+
pathStub.onThirdCall().returns('c/git/rules/require-version.js');
37+
});
38+
39+
after(function() {
40+
fs.readdirSync.restore();
41+
path.join.restore();
42+
});
43+
44+
it('an error should be thrown', function() {
45+
const rules = new Rules();
46+
47+
rules.load();
48+
49+
(function() {
50+
rules.get('required-version');
51+
}).should.throw(chalk.bold.red('Rule, required-version, is invalid. Please ensure it matches a valid option.'));
52+
});
53+
});
54+
});
55+
2756
describe('load method', function() {
2857
context('when load is called', function() {
2958
before(function() {

0 commit comments

Comments
 (0)