Skip to content

Commit 606279a

Browse files
authored
Add require-types and require-typings (#112)
1 parent a8e84df commit 606279a

File tree

6 files changed

+121
-12
lines changed

6 files changed

+121
-12
lines changed

CHANGELOG.md

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

1212
### Removed
1313

14+
## [3.7.0] - 2019-06-16
15+
### Added
16+
- New rule: [require-types](https://github.com/tclindner/npm-package-json-lint/wiki/require-types).
17+
- New rule: [require-typings](https://github.com/tclindner/npm-package-json-lint/wiki/require-typings).
18+
19+
Addresses [#109](https://github.com/tclindner/npm-package-json-lint/issues/109) from @ceilfors.
20+
1421
## [3.6.1] - 2019-05-22
1522
### Fixed
1623
- @lddubeau resolved an issue with how require.resolve was implemented. The issue was causing npm-package-json-lint to crash on Node 12.3.0. Please see #110 for more details.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-package-json-lint",
3-
"version": "3.6.1",
3+
"version": "3.7.0",
44
"description": "Configurable linter for package.json files.",
55
"keywords": [
66
"lint",
@@ -34,30 +34,30 @@
3434
"test:ci": "jest --runInBand"
3535
},
3636
"dependencies": {
37-
"ajv": "^6.9.2",
37+
"ajv": "^6.10.0",
3838
"chalk": "^2.4.2",
39-
"glob": "^7.1.3",
40-
"ignore": "^5.0.5",
41-
"is-path-inside": "^2.0.0",
39+
"glob": "^7.1.4",
40+
"ignore": "^5.1.2",
41+
"is-path-inside": "^2.1.0",
4242
"is-plain-obj": "^1.1.0",
4343
"is-resolvable": "^1.1.0",
4444
"log-symbols": "^2.2.0",
4545
"meow": "^5.0.0",
46-
"plur": "^3.0.1",
46+
"plur": "^3.1.1",
4747
"semver": "^5.6.0",
4848
"strip-json-comments": "^2.0.1",
4949
"validator": "^10.11.0"
5050
},
5151
"devDependencies": {
52-
"eslint": "^5.14.1",
53-
"eslint-config-tc": "^6.0.0",
52+
"eslint": "^5.16.0",
53+
"eslint-config-tc": "^6.4.0",
5454
"eslint-formatter-pretty": "^2.1.1",
55-
"eslint-plugin-import": "^2.16.0",
56-
"eslint-plugin-prettier": "^3.0.1",
55+
"eslint-plugin-import": "^2.17.3",
56+
"eslint-plugin-prettier": "^3.1.0",
5757
"figures": "^2.0.0",
58-
"jest": "^24.1.0",
58+
"jest": "^24.8.0",
5959
"npm-package-json-lint-config-default": "^2.0.0",
60-
"prettier": "^1.16.4"
60+
"prettier": "^1.18.2"
6161
},
6262
"engines": {
6363
"node": ">=6.0.0",

src/rules/require-types.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const LintIssue = require('./../LintIssue');
2+
3+
const lintId = 'require-types';
4+
const nodeName = 'types';
5+
const message = 'types is required';
6+
const ruleType = 'standard';
7+
8+
const lint = (packageJsonData, severity) => {
9+
if (!packageJsonData.hasOwnProperty(nodeName)) {
10+
return new LintIssue(lintId, severity, nodeName, message);
11+
}
12+
13+
return true;
14+
};
15+
16+
module.exports.lint = lint;
17+
module.exports.ruleType = ruleType;

src/rules/require-typings.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const LintIssue = require('./../LintIssue');
2+
3+
const lintId = 'require-typings';
4+
const nodeName = 'typings';
5+
const message = 'typings is required';
6+
const ruleType = 'standard';
7+
8+
const lint = (packageJsonData, severity) => {
9+
if (!packageJsonData.hasOwnProperty(nodeName)) {
10+
return new LintIssue(lintId, severity, nodeName, message);
11+
}
12+
13+
return true;
14+
};
15+
16+
module.exports.lint = lint;
17+
module.exports.ruleType = ruleType;

test/unit/rules/require-types.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const ruleModule = require('./../../../src/rules/require-types');
2+
3+
const {lint, ruleType} = ruleModule;
4+
5+
describe('require-types Unit Tests', () => {
6+
describe('a rule type value should be exported', () => {
7+
test('it should equal "standard"', () => {
8+
expect(ruleType).toStrictEqual('standard');
9+
});
10+
});
11+
12+
describe('when package.json has node', () => {
13+
test('true should be returned', () => {
14+
const packageJsonData = {
15+
types: './lib/main.d.ts'
16+
};
17+
const response = lint(packageJsonData, 'error');
18+
19+
expect(response).toBeTruthy();
20+
});
21+
});
22+
23+
describe('when package.json does not have node', () => {
24+
test('LintIssue object should be returned', () => {
25+
const packageJsonData = {};
26+
const response = lint(packageJsonData, 'error');
27+
28+
expect(response.lintId).toStrictEqual('require-types');
29+
expect(response.severity).toStrictEqual('error');
30+
expect(response.node).toStrictEqual('types');
31+
expect(response.lintMessage).toStrictEqual('types is required');
32+
});
33+
});
34+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const ruleModule = require('./../../../src/rules/require-typings');
2+
3+
const {lint, ruleType} = ruleModule;
4+
5+
describe('require-typings Unit Tests', () => {
6+
describe('a rule type value should be exported', () => {
7+
test('it should equal "standard"', () => {
8+
expect(ruleType).toStrictEqual('standard');
9+
});
10+
});
11+
12+
describe('when package.json has node', () => {
13+
test('true should be returned', () => {
14+
const packageJsonData = {
15+
typings: './lib/main.d.ts'
16+
};
17+
const response = lint(packageJsonData, 'error');
18+
19+
expect(response).toBeTruthy();
20+
});
21+
});
22+
23+
describe('when package.json does not have node', () => {
24+
test('LintIssue object should be returned', () => {
25+
const packageJsonData = {};
26+
const response = lint(packageJsonData, 'error');
27+
28+
expect(response.lintId).toStrictEqual('require-typings');
29+
expect(response.severity).toStrictEqual('error');
30+
expect(response.node).toStrictEqual('typings');
31+
expect(response.lintMessage).toStrictEqual('typings is required');
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)