Skip to content

Commit

Permalink
Feature/1.1.0 (#16)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tclindner authored Jul 18, 2016
1 parent be98471 commit bd74d33
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Removed

## [1.1.0] - 2016-07-17
### Added
- Error handling if an invalid rule name is included in `.npmpackagejsonlintrc.json`.

### Fixed
- Issue resolving file path of `.npmpackagejsonlintrc.json` when running the cli from a nested directory under `node_modules`

## [1.0.0] - 2016-05-22
### Added
- New rule: [require-bin](https://github.com/tclindner/npm-package-json-lint/wiki/require-bin)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![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)


## What is package json lint?
## What is npm-package-json-lint?

npm-package-json-lint helps enforce standards for your package.json file.
Currently it can check for:
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": "1.0.0",
"version": "1.1.0",
"description": "CLI app for linting package.json files.",
"keywords": [
"lint",
Expand Down
2 changes: 1 addition & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Config {
let configFile = passedConfig;

if (!path.isAbsolute(passedConfig)) {
configFile = path.join(__dirname, passedConfig);
configFile = path.join(process.cwd(), passedConfig);
}

const rcFileObj = parser.parse(configFile);
Expand Down
9 changes: 9 additions & 0 deletions src/Rules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const chalk = require('chalk');
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -43,6 +44,14 @@ class Rules {
* @return {Object} Rule
*/
get(ruleId) {
const rule = this.rules[ruleId];

if (typeof rule === 'undefined') {
const errorMsg = `Rule, ${ruleId}, is invalid. Please ensure it matches a valid option.`;

throw new Error(chalk.bold.red(errorMsg));
}

return require(this.rules[ruleId]);
}

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/RulesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@ describe('Rules Unit Tests', function() {
});
});

describe('get method', function() {
context('when get is called for an invalid ruleId', function() {
before(function() {
const fsStub = sinon.stub(fs, 'readdirSync');
const pathStub = sinon.stub(path, 'join');

fsStub.onFirstCall().returns(['version-type.js', 'require-version.js']);
pathStub.onFirstCall().returns('c/git/rules');
pathStub.onSecondCall().returns('c/git/rules/version-type.js');
pathStub.onThirdCall().returns('c/git/rules/require-version.js');
});

after(function() {
fs.readdirSync.restore();
path.join.restore();
});

it('an error should be thrown', function() {
const rules = new Rules();

rules.load();

(function() {
rules.get('required-version');
}).should.throw(chalk.bold.red('Rule, required-version, is invalid. Please ensure it matches a valid option.'));
});
});
});

describe('load method', function() {
context('when load is called', function() {
before(function() {
Expand Down

0 comments on commit bd74d33

Please sign in to comment.