File tree Expand file tree Collapse file tree 6 files changed +48
-3
lines changed Expand file tree Collapse file tree 6 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
11
11
12
12
### Removed
13
13
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
+
14
21
## [ 1.0.0] - 2016-05-22
15
22
### Added
16
23
- New rule: [ require-bin] ( https://github.com/tclindner/npm-package-json-lint/wiki/require-bin )
Original file line number Diff line number Diff line change 10
10
[ ![ 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 )
11
11
12
12
13
- ## What is package json lint?
13
+ ## What is npm- package- json- lint?
14
14
15
15
npm-package-json-lint helps enforce standards for your package.json file.
16
16
Currently it can check for:
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " npm-package-json-lint" ,
3
- "version" : " 1.0 .0" ,
3
+ "version" : " 1.1 .0" ,
4
4
"description" : " CLI app for linting package.json files." ,
5
5
"keywords" : [
6
6
" lint" ,
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ class Config {
63
63
let configFile = passedConfig ;
64
64
65
65
if ( ! path . isAbsolute ( passedConfig ) ) {
66
- configFile = path . join ( __dirname , passedConfig ) ;
66
+ configFile = path . join ( process . cwd ( ) , passedConfig ) ;
67
67
}
68
68
69
69
const rcFileObj = parser . parse ( configFile ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const chalk = require ( 'chalk' ) ;
3
4
const fs = require ( 'fs' ) ;
4
5
const path = require ( 'path' ) ;
5
6
@@ -43,6 +44,14 @@ class Rules {
43
44
* @return {Object } Rule
44
45
*/
45
46
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
+
46
55
return require ( this . rules [ ruleId ] ) ;
47
56
}
48
57
Original file line number Diff line number Diff line change @@ -24,6 +24,35 @@ describe('Rules Unit Tests', function() {
24
24
} ) ;
25
25
} ) ;
26
26
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
+
27
56
describe ( 'load method' , function ( ) {
28
57
context ( 'when load is called' , function ( ) {
29
58
before ( function ( ) {
You can’t perform that action at this time.
0 commit comments