Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #134
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
id: prefer-no-dependencies | ||
title: prefer-no-dependencies | ||
--- | ||
|
||
Enabling this rule will result in an error being generated if `dependencies` is present. | ||
|
||
## Example .npmpackagejsonlintrc configuration | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"prefer-no-dependencies": "error" | ||
} | ||
} | ||
``` | ||
|
||
With exceptions | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"prefer-no-dependencies": ["error", { | ||
"exceptions": ["myModule"] | ||
}] | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Rule Details | ||
|
||
### *Incorrect* example(s) | ||
|
||
```json | ||
{ | ||
"dependencies": "dummy-value" | ||
} | ||
``` | ||
|
||
### *Correct* example(s) | ||
|
||
```json | ||
{ | ||
"prefer-no-dependencies": "error" | ||
} | ||
``` | ||
|
||
## History | ||
|
||
* Introduced in version 4.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const {exists} = require('../validators/property'); | ||
const LintIssue = require('../LintIssue'); | ||
|
||
const lintId = 'prefer-no-dependencies'; | ||
const nodeName = 'dependencies'; | ||
const message = 'dependencies should not be defined'; | ||
const ruleType = 'optionalObject'; | ||
|
||
const lint = (packageJsonData, severity) => { | ||
if (exists(packageJsonData, nodeName)) { | ||
return new LintIssue(lintId, severity, nodeName, message); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
module.exports = { | ||
lint, | ||
ruleType | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const ruleModule = require('../../../src/rules/prefer-no-dependencies'); | ||
const property = require('../../../src/validators/property'); | ||
|
||
const {lint, ruleType} = ruleModule; | ||
|
||
jest.mock('../../../src/validators/property'); | ||
|
||
const nodeName = 'dependencies'; | ||
|
||
describe('prefer-no-dependencies Unit Tests', () => { | ||
describe('a rule type value should be exported', () => { | ||
test('it should equal "optionalObject"', () => { | ||
expect(ruleType).toStrictEqual('optionalObject'); | ||
}); | ||
}); | ||
|
||
describe('when package.json has dependencies node', () => { | ||
test('LintIssue object should be returned', () => { | ||
property.exists.mockReturnValue(true); | ||
|
||
const packageJsonData = { | ||
dependencies: 'dummy-value' | ||
}; | ||
const response = lint(packageJsonData, 'error'); | ||
|
||
expect(response.lintId).toStrictEqual('prefer-no-dependencies'); | ||
expect(response.severity).toStrictEqual('error'); | ||
expect(response.node).toStrictEqual(nodeName); | ||
expect(response.lintMessage).toStrictEqual('dependencies should not be defined'); | ||
|
||
expect(property.exists).toHaveBeenCalledTimes(1); | ||
expect(property.exists).toHaveBeenCalledWith(packageJsonData, nodeName); | ||
}); | ||
}); | ||
|
||
describe('when package.json does not have node', () => { | ||
test('true should be returned', () => { | ||
property.exists.mockReturnValue(false); | ||
|
||
const packageJsonData = {}; | ||
const response = lint(packageJsonData, 'error'); | ||
|
||
expect(response).toBe(true); | ||
|
||
expect(property.exists).toHaveBeenCalledTimes(1); | ||
expect(property.exists).toHaveBeenCalledWith(packageJsonData, nodeName); | ||
}); | ||
}); | ||
}); |