-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule for repository.directory field (#106)
* Add rule for repository.directory field * Ensure that repository exists
- Loading branch information
Showing
2 changed files
with
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const LintIssue = require('./../LintIssue'); | ||
|
||
const lintId = 'require-repository-directory'; | ||
const nodeName = 'repository'; | ||
const parentNodeMessage = 'repository is required'; | ||
const message = 'repository object missing directory property'; | ||
const ruleType = 'standard'; | ||
|
||
const lint = (packageJsonData, severity) => { | ||
if (!packageJsonData.hasOwnProperty(nodeName)) { | ||
return new LintIssue(lintId, severity, nodeName, parentNodeMessage); | ||
} | ||
|
||
if (!packageJsonData[nodeName].hasOwnProperty('directory')) { | ||
return new LintIssue(lintId, severity, nodeName, message); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
module.exports.lint = lint; | ||
module.exports.ruleType = 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,53 @@ | ||
const ruleModule = require('./../../../src/rules/require-repository-directory'); | ||
|
||
const {lint, ruleType} = ruleModule; | ||
|
||
describe('require-repository-directory Unit Tests', () => { | ||
describe('a rule type value should be exported', () => { | ||
test('it should equal "standard"', () => { | ||
expect(ruleType).toStrictEqual('standard'); | ||
}); | ||
}); | ||
|
||
describe('when package.json does not have parent node', () => { | ||
test('false should be returned', () => { | ||
const packageJsonData = {}; | ||
const response = lint(packageJsonData, 'error'); | ||
|
||
expect(response.lintId).toStrictEqual('require-repository-directory'); | ||
expect(response.severity).toStrictEqual('error'); | ||
expect(response.node).toStrictEqual('repository'); | ||
expect(response.lintMessage).toStrictEqual('repository is required'); | ||
}); | ||
}); | ||
|
||
describe('when package.json has node', () => { | ||
test('true should be returned', () => { | ||
const packageJsonData = { | ||
repository: { | ||
url: 'https://github.com/packages/monorepo', | ||
directory: 'packages/somepackage' | ||
} | ||
}; | ||
const response = lint(packageJsonData, 'error'); | ||
|
||
expect(response).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('when package.json does not have node', () => { | ||
test('LintIssue object should be returned', () => { | ||
const packageJsonData = { | ||
repository: { | ||
url: 'https://github.com/packages/monorepo' | ||
} | ||
}; | ||
const response = lint(packageJsonData, 'error'); | ||
|
||
expect(response.lintId).toStrictEqual('require-repository-directory'); | ||
expect(response.severity).toStrictEqual('error'); | ||
expect(response.node).toStrictEqual('repository'); | ||
expect(response.lintMessage).toStrictEqual('repository object missing directory property'); | ||
}); | ||
}); | ||
}); |