Skip to content

Commit 039a4ac

Browse files
committed
Fix check for root node in the event it does not exist
Fixes #79
1 parent 6e1c80d commit 039a4ac

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

CHANGELOG.md

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

1212
### Removed
1313

14+
15+
## [3.0.1] - 2018-05-14
16+
### Fixed
17+
- Addressed issue, from @ntwb, [#79](https://github.com/tclindner/npm-package-json-lint/issues/79).
18+
19+
1420
## [3.0.0] - 2018-05-09
1521
### Added
1622
- Added support for glob based package.json file detection. Addresses [#74](https://github.com/tclindner/npm-package-json-lint/issues/74) from @dnepro.

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": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Configurable linter for package.json files.",
55
"keywords": [
66
"lint",

src/Config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ class Config {
128128
config = ConfigFile.load(javaScriptConfigFilePath, this);
129129
}
130130

131-
if (config.hasOwnProperty('root') && !config.root) {
132-
const parentDir = path.resolve(directory, '../');
133-
const parentConfig = this.getProjectHierarchyConfig(parentDir);
131+
if (!config.hasOwnProperty('root') || !config.root) {
132+
const parentPackageJsonFile = path.resolve(directory, '../', 'package.json');
133+
const parentConfig = this.getProjectHierarchyConfig(parentPackageJsonFile);
134134

135135
// Merge base object
136136
const mergedConfig = Object.assign({}, parentConfig, config);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "npm-package-json-lint",
3+
"version": "0.1.0",
4+
"description": "CLI app for linting package.json files.",
5+
"keywords": [
6+
"lint"
7+
],
8+
"homepage": "https://github.com/tclindner/npm-package-json-lint",
9+
"author": "Thomas Lindner",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/tclindner/npm-package-json-lint"
13+
},
14+
"devDependencies": {
15+
"mocha": "^2.4.5"
16+
},
17+
"npmPackageJsonLintConfig": {
18+
"root": "true",
19+
"rules": {
20+
"require-author": "off",
21+
"version-format": "error"
22+
}
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "npm-package-json-lint",
3+
"version": "0.1.0",
4+
"description": "CLI app for linting package.json files.",
5+
"keywords": [
6+
"lint"
7+
],
8+
"homepage": "https://github.com/tclindner/npm-package-json-lint",
9+
"author": "Thomas Lindner",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/tclindner/npm-package-json-lint"
13+
},
14+
"devDependencies": {
15+
"mocha": "^2.4.5"
16+
},
17+
"npmPackageJsonLintConfig": {
18+
"rules": {
19+
"require-author": "error"
20+
}
21+
}
22+
}

tests/unit/Config.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,28 @@ describe('Config Unit Tests', function() {
752752
ConfigFile.load.restore();
753753
});
754754

755+
it('and package.json prop exists and root is not set, the config object should returned', function() {
756+
const options = {
757+
configFile: '',
758+
cwd: process.cwd(),
759+
useConfigFiles: false,
760+
rules: {}
761+
};
762+
const config = new Config(options, linterContext);
763+
764+
const expectedConfigObj = {
765+
root: true,
766+
rules: {
767+
'require-author': 'error',
768+
'version-format': 'error'
769+
}
770+
};
771+
const filePath = './tests/fixtures/hierarchyWithoutRoot/subdirectory/package.json';
772+
const result = config.getProjectHierarchyConfig(filePath);
773+
774+
result.should.deep.equal(expectedConfigObj);
775+
});
776+
755777
it('and package.json prop exists and has no prop, the config object should returned', function() {
756778
const options = {
757779
configFile: '',

0 commit comments

Comments
 (0)