Skip to content

Commit f152ace

Browse files
authored
Update array style rules so they can easily be turned off (#29)
Fixes #27 - Allows array style rules, like “valid-values-author”, so they can be turned off by setting “valid-values-author: ‘off’”
1 parent e974665 commit f152ace

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

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

1212
### Removed
1313

14+
## [2.1.2] - 2017-04-10
15+
### Fixed
16+
- Array style rules, like `valid-values-author`, so they can be easily turned off by setting `valid-values-author: 'off'`
17+
1418
## [2.1.1] - 2017-04-10
1519
### Fixed
1620
- CLI so process exit code remains 0 if only warnings are detected

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": "2.1.1",
3+
"version": "2.1.2",
44
"description": "CLI app for linting package.json files.",
55
"keywords": [
66
"lint",

src/NpmPackageJsonLint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class NpmPackageJsonLint {
3737
const ruleModule = this.rules.get(rule);
3838

3939
if (inArray(this.arrayRuleTypes, ruleModule.ruleType)) {
40-
const errorWarningOffSetting = configObj[rule][0];
40+
const errorWarningOffSetting = typeof configObj[rule] === 'string' && configObj[rule] === 'off' ? configObj[rule] : configObj[rule][0];
4141
const ruleConfigArray = configObj[rule][1];
4242

4343
if (errorWarningOffSetting !== 'off') {

tests/unit/NpmPackageJsonLintTest.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ describe('NpmPackageJsonLint Unit Tests', function() {
126126
});
127127
});
128128

129-
context('validate that errors and warnings are set', function() {
130-
it('one error and one warning expected', function() {
129+
context('validate that when array style rules have an array value with off', function() {
130+
it('zero errors and zero warning expected', function() {
131131
const packageJsonData = {
132132
author: 'Caitlin Snow'
133133
};
@@ -149,6 +149,27 @@ describe('NpmPackageJsonLint Unit Tests', function() {
149149
response.hasOwnProperty('warnings').should.be.false();
150150
});
151151
});
152+
153+
context('validate that when array style rules have a value of off', function() {
154+
it('zero errors and zero warnings expected', function() {
155+
const packageJsonData = {
156+
author: 'Caitlin Snow'
157+
};
158+
const config = {
159+
'valid-values-author': 'off'
160+
};
161+
const options = {
162+
ignoreWarnings: true
163+
};
164+
const npmPackageJsonLint = new NpmPackageJsonLint(packageJsonData, config, options);
165+
const configStub = sinon.stub(npmPackageJsonLint, '_getConfig').returns(config);
166+
const response = npmPackageJsonLint.lint();
167+
const expectedErrorCount = 0;
168+
169+
response.errors.length.should.equal(expectedErrorCount);
170+
response.hasOwnProperty('warnings').should.be.false();
171+
});
172+
});
152173
});
153174

154175
describe('_getConfig method', function() {

0 commit comments

Comments
 (0)