Skip to content

Commit 3ee7f50

Browse files
authored
Feature/move to shared config (#17)
* 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 * Move to shared config - Extend eslint-config-tc - Bump grunt-eslint to 19.0.0 - Resolve lint errors related to new rules * Bump version * Add v1.2.0 release notes
1 parent bd74d33 commit 3ee7f50

File tree

6 files changed

+27
-223
lines changed

6 files changed

+27
-223
lines changed

.eslintrc.json

+1-209
Original file line numberDiff line numberDiff line change
@@ -1,211 +1,3 @@
11
{
2-
"parserOptions": {
3-
"ecmaVersion": 6,
4-
"sourceType": "module"
5-
},
6-
"env": {
7-
"node": true,
8-
"es6": true,
9-
"mocha": true,
10-
"jquery": true
11-
},
12-
"rules": {
13-
"comma-dangle": ["error", "never"],
14-
"no-cond-assign": ["error", "always"],
15-
"no-constant-condition": "error",
16-
"no-dupe-args": "error",
17-
"no-dupe-keys": "error",
18-
"no-duplicate-case": "error",
19-
"no-empty": "error",
20-
"no-empty-character-class": "error",
21-
"no-ex-assign": "error",
22-
"no-extra-boolean-cast": "error",
23-
"no-extra-parens": ["error", "all", {"conditionalAssign": false}],
24-
"no-extra-semi": "error",
25-
"no-func-assign": "error",
26-
"no-invalid-regexp": ["error", {"allowConstructorFlags": ["u", "y"]}],
27-
"no-irregular-whitespace": "error",
28-
"no-negated-in-lhs": "error",
29-
"no-obj-calls": "error",
30-
"no-regex-spaces": "error",
31-
"no-sparse-arrays": "error",
32-
"no-unreachable": "error",
33-
"use-isnan": "error",
34-
"valid-jsdoc": "error",
35-
"no-unexpected-multiline": "error",
36-
"valid-typeof": "error",
37-
"accessor-pairs": "error",
38-
"array-callback-return": "error",
39-
"block-scoped-var": "error",
40-
"complexity": "error",
41-
"consistent-return": "error",
42-
"curly": "error",
43-
"default-case": "error",
44-
"dot-location": ["error", "property"],
45-
"dot-notation": "error",
46-
"eqeqeq": "error",
47-
"no-caller": "error",
48-
"no-case-declarations": "error",
49-
"no-div-regex": "error",
50-
"no-empty-function": "error",
51-
"no-empty-pattern": "error",
52-
"no-eq-null": "error",
53-
"no-eval": "error",
54-
"no-extend-native": "error",
55-
"no-extra-bind": "error",
56-
"no-extra-label": "error",
57-
"no-fallthrough": "error",
58-
"no-floating-decimal": "error",
59-
"no-implicit-coercion": "error",
60-
"no-implicit-globals": "error",
61-
"no-implied-eval": "error",
62-
"no-invalid-this": "error",
63-
"no-iterator": "error",
64-
"no-labels": "error",
65-
"no-lone-blocks": "error",
66-
"no-loop-func": "error",
67-
"no-magic-numbers": "error",
68-
"no-multi-spaces": "error",
69-
"no-multi-str": "error",
70-
"no-native-reassign": "error",
71-
"no-new": "error",
72-
"no-new-func": "error",
73-
"no-new-wrappers": "error",
74-
"no-octal": "error",
75-
"no-octal-escape": "error",
76-
"no-param-reassign": "error",
77-
"no-proto": "error",
78-
"no-redeclare": "error",
79-
"no-return-assign": "error",
80-
"no-script-url": "error",
81-
"no-self-assign": "error",
82-
"no-self-compare": "error",
83-
"no-sequences": "error",
84-
"no-throw-literal": "error",
85-
"no-unmodified-loop-condition": "error",
86-
"no-unused-expressions": "error",
87-
"no-unused-labels": "error",
88-
"no-useless-call": "error",
89-
"no-useless-concat": "error",
90-
"no-useless-escape": "error",
91-
"no-void": "error",
92-
"no-warning-comments": "error",
93-
"no-with": "error",
94-
"radix": "error",
95-
"vars-on-top": "error",
96-
"wrap-iife": ["error", "outside"],
97-
"yoda": "error",
98-
"no-catch-shadow": "error",
99-
"no-delete-var": "error",
100-
"no-label-var": "error",
101-
"no-shadow": "error",
102-
"no-shadow-restricted-names": "error",
103-
"no-undef": "error",
104-
"no-undefined": "error",
105-
"no-use-before-define": "error",
106-
"callback-return": "error",
107-
"handle-callback-err": "error",
108-
"no-mixed-requires": "error",
109-
"no-new-require": "error",
110-
"no-path-concat": "error",
111-
"no-process-env": "error",
112-
"no-process-exit": "error",
113-
"array-bracket-spacing": ["error", "never"],
114-
"brace-style": "error",
115-
"camelcase": "error",
116-
"comma-spacing": ["error", {"before": false, "after": true}],
117-
"comma-style": ["error", "last"],
118-
"computed-property-spacing": ["error", "never"],
119-
"eol-last": "error",
120-
"func-style": ["error", "expression"],
121-
"id-length": ["error", {"min": 2, "max": 20}],
122-
"indent": ["error", 2],
123-
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
124-
"keyword-spacing": "error",
125-
"linebreak-style": ["error", "unix"],
126-
"max-depth": ["error", 4],
127-
"max-nested-callbacks": ["error", 3],
128-
"max-params": ["error", 4],
129-
"max-statements": ["error", 12],
130-
"max-statements-per-line": ["error", {"max": 1}],
131-
"new-cap": "error",
132-
"new-parens": "error",
133-
"newline-after-var": "error",
134-
"newline-before-return": "error",
135-
"newline-per-chained-call": ["error", {"ignoreChainWithDepth": 3}],
136-
"no-array-constructor": "error",
137-
"no-bitwise": "error",
138-
"no-continue": "error",
139-
"no-inline-comments": "error",
140-
"no-lonely-if": "error",
141-
"no-mixed-spaces-and-tabs": "error",
142-
"no-multiple-empty-lines": ["error", {"max": 2}],
143-
"no-negated-condition": "error",
144-
"no-nested-ternary": "error",
145-
"no-new-object": "error",
146-
"no-plusplus": "error",
147-
"no-trailing-spaces": "error",
148-
"no-unneeded-ternary": "error",
149-
"no-whitespace-before-property": "error",
150-
"object-curly-spacing": ["error", "never"],
151-
"one-var": ["error", "never"],
152-
"operator-assignment": ["error", "always"],
153-
"padded-blocks": ["error", {"classes": "always"}],
154-
"quote-props": ["error", "consistent"],
155-
"quotes": ["error", "single"],
156-
"require-jsdoc": ["error", {
157-
"require": {
158-
"FunctionDeclaration": true,
159-
"MethodDefinition": true,
160-
"ClassDeclaration": false
161-
}
162-
}],
163-
"semi": ["error", "always"],
164-
"semi-spacing": ["error", {"before": false, "after": false}],
165-
"sort-imports": "error",
166-
"sort-vars": "error",
167-
"space-before-blocks": ["error", {
168-
"functions": "always",
169-
"keywords": "always",
170-
"classes": "always"
171-
}],
172-
"space-before-function-paren": ["error", "never"],
173-
"space-in-parens": ["error", "never"],
174-
"space-unary-ops": [2, {
175-
"words": true,
176-
"nonwords": false
177-
}],
178-
"spaced-comment": ["error", "always"],
179-
"wrap-regex": "error",
180-
"lines-around-comment": ["error", {
181-
"allowArrayStart": false,
182-
"allowArrayEnd": false,
183-
"allowBlockStart": true,
184-
"allowBlockEnd": false,
185-
"allowObjectStart": false,
186-
"allowObjectEnd": false,
187-
"afterBlockComment": false,
188-
"afterLineComment": false,
189-
"beforeBlockComment": true,
190-
"beforeLineComment": true
191-
}],
192-
"arrow-body-style": ["error", "always"],
193-
"arrow-parens": ["error", "always"],
194-
"arrow-spacing": ["error", {"before": true, "after": true}],
195-
"constructor-super": "error",
196-
"no-class-assign": "error",
197-
"no-confusing-arrow": ["error", {"allowParens": true}],
198-
"no-const-assign": "error",
199-
"no-dupe-class-members": "error",
200-
"no-duplicate-imports": "error",
201-
"no-new-symbol": "error",
202-
"no-this-before-super": "error",
203-
"no-useless-constructor": "error",
204-
"no-var": "error",
205-
"object-shorthand": "error",
206-
"prefer-const": "error",
207-
"prefer-rest-params": "error",
208-
"prefer-template": "error",
209-
"template-curly-spacing": "error"
210-
}
2+
"extends": "eslint-config-tc"
2113
}

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Removed
1313

14+
## [1.2.0] - 2016-07-26
15+
### Changed
16+
- Bump grunt-eslint to version 19.0.0
17+
- Move to shared eslint-config-tc module
18+
1419
## [1.1.0] - 2016-07-17
1520
### Added
1621
- Error handling if an invalid rule name is included in `.npmpackagejsonlintrc.json`.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-package-json-lint",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "CLI app for linting package.json files.",
55
"keywords": [
66
"lint",
@@ -33,14 +33,16 @@
3333
"validator": "^5.1.0"
3434
},
3535
"devDependencies": {
36+
"eslint": "^3.1.1",
37+
"eslint-config-tc": "^1.1.0",
3638
"eslint-formatter-pretty": "^0.2.1",
3739
"grunt": "^1.0.1",
3840
"grunt-bump": "^0.8.0",
3941
"grunt-contrib-clean": "^1.0.0",
4042
"grunt-contrib-copy": "^1.0.0",
4143
"grunt-contrib-watch": "^1.0.0",
4244
"grunt-env": "^0.4.4",
43-
"grunt-eslint": "^18.1.0",
45+
"grunt-eslint": "^19.0.0",
4446
"grunt-istanbul": "^0.7.0",
4547
"grunt-istanbul-coverage": "^0.1.4",
4648
"grunt-jscs": "^2.8.0",

src/Config.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class Config {
2020
'no-restricted-pre-release-dependencies',
2121
'no-restricted-pre-release-devDependencies'
2222
];
23-
this.firstKey = 0;
24-
this.secondKey = 1;
2523

2624
if (this._isConfigPassed(passedConfigParam)) {
2725
const passedConfig = this._getPassedConfig(passedConfigParam);
@@ -86,21 +84,30 @@ class Config {
8684
const ruleConfig = rcFileObj[rule];
8785

8886
if (Array.isArray(ruleConfig) && inArray(this.arrayRules, rule)) {
89-
if (typeof ruleConfig[this.firstKey] !== 'string' || typeof ruleConfig[this.firstKey] === 'string' && ruleConfig[this.firstKey] !== 'error' && ruleConfig[this.firstKey] !== 'warning') {
90-
throw new Error(`${rule} - first key must be set to "error" or "warning". Currently set to ${ruleConfig[this.firstKey]}`);
87+
if (typeof ruleConfig[0] !== 'string' || this._isRuleValid(ruleConfig[0])) {
88+
throw new Error(`${rule} - first key must be set to "error" or "warning". Currently set to ${ruleConfig[0]}`);
9189
}
9290

93-
if (!Array.isArray(ruleConfig[this.secondKey])) {
94-
throw new Error(`${rule} - second key must be set an array. Currently set to ${ruleConfig[this.secondKey]}`);
91+
if (!Array.isArray(ruleConfig[1])) {
92+
throw new Error(`${rule} - second key must be set an array. Currently set to ${ruleConfig[1]}`);
9593
}
96-
} else if (typeof ruleConfig !== 'string' || typeof ruleConfig === 'string' && ruleConfig !== 'error' && ruleConfig !== 'warning') {
94+
} else if (typeof ruleConfig !== 'string' || this._isRuleValid(ruleConfig)) {
9795
throw new Error(`${rule} - must be set to "error" or "warning". Currently set to ${ruleConfig}`);
9896
}
9997
}
10098

10199
return true;
102100
}
103101

102+
/**
103+
* Validates the first key of an array type rule
104+
* @param {String} key Error type of the rule
105+
* @return {Boolean} True if the rule is valid. False if the rule is invalid.
106+
*/
107+
_isRuleValid(key) {
108+
return typeof key === 'string' && key !== 'error' && key !== 'warning';
109+
}
110+
104111
}
105112

106113
module.exports = Config;

src/NpmPackageJsonLint.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class NpmPackageJsonLint {
1818
this.packageJsonData = packageJsonData;
1919
this.ignoreWarnings = options.ignoreWarnings;
2020
this.arrayRuleTypes = ['valid-values', 'no-restricted-dependencies', 'no-restricted-pre-release-dependencies'];
21-
this.firstKey = 0;
22-
this.secondKey = 1;
2321
this.errors = [];
2422
this.warnings = [];
2523

@@ -38,8 +36,8 @@ class NpmPackageJsonLint {
3836
const ruleModule = this.rules.get(rule);
3937

4038
if (inArray(this.arrayRuleTypes, ruleModule.ruleType)) {
41-
const errorWarningSetting = this.config[rule][this.firstKey];
42-
const ruleConfigArray = this.config[rule][this.secondKey];
39+
const errorWarningSetting = this.config[rule][0];
40+
const ruleConfigArray = this.config[rule][1];
4341
const lintResult = ruleModule.lint(this.packageJsonData, errorWarningSetting, ruleConfigArray);
4442

4543
this._processResult(lintResult, errorWarningSetting);

tests/unit/validators/dependency-auditTest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
/* eslint max-nested-callbacks: "off" */
3+
/* eslint max-nested-callbacks: "off", max-lines: "off" */
44

55
const should = require('should');
66
const requireHelper = require('../../require_helper');

0 commit comments

Comments
 (0)