Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: prefer-no-devDependencies (#133)
* Add: prefer-no-devDependencies * Prettier fix
- Loading branch information
Showing
7 changed files
with
116 additions
and
3 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
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,38 @@ | ||
--- | ||
id: prefer-no-devDependencies | ||
title: prefer-no-devDependencies | ||
--- | ||
|
||
Enabling this rule will result in an error being generated if `devDependencies` is present. | ||
|
||
## Example .npmpackagejsonlintrc configuration | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"prefer-no-devDependencies": "error" | ||
} | ||
} | ||
``` | ||
|
||
## Rule Details | ||
|
||
### *Incorrect* example(s) | ||
|
||
```json | ||
{ | ||
"devDependencies": "dummy-value" | ||
} | ||
``` | ||
|
||
### *Correct* example(s) | ||
|
||
```json | ||
{ | ||
"prefer-no-devDependencies": "error" | ||
} | ||
``` | ||
|
||
## History | ||
|
||
* Introduced in version 4.0.0 |
File renamed without changes.
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-devDependencies'; | ||
const nodeName = 'devDependencies'; | ||
const message = 'devDependencies 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-devDependencies'); | ||
const property = require('../../../src/validators/property'); | ||
|
||
const {lint, ruleType} = ruleModule; | ||
|
||
jest.mock('../../../src/validators/property'); | ||
|
||
const nodeName = 'devDependencies'; | ||
|
||
describe('prefer-no-devDependencies Unit Tests', () => { | ||
describe('a rule type value should be exported', () => { | ||
test('it should equal "optionalObject"', () => { | ||
expect(ruleType).toStrictEqual('optionalObject'); | ||
}); | ||
}); | ||
|
||
describe('when package.json has devDependencies node', () => { | ||
test('LintIssue object should be returned', () => { | ||
property.exists.mockReturnValue(true); | ||
|
||
const packageJsonData = { | ||
devDependencies: 'dummy-value' | ||
}; | ||
const response = lint(packageJsonData, 'error'); | ||
|
||
expect(response.lintId).toStrictEqual('prefer-no-devDependencies'); | ||
expect(response.severity).toStrictEqual('error'); | ||
expect(response.node).toStrictEqual(nodeName); | ||
expect(response.lintMessage).toStrictEqual('devDependencies 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); | ||
}); | ||
}); | ||
}); |
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