Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule for repository.directory field #106

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/rules/require-repository-directory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const LintIssue = require('./../LintIssue');

const lintId = 'require-repository-directory';
const nodeName = 'repository';
const message = 'repository object missing directory property';
const ruleType = 'standard';

const lint = (packageJsonData, severity) => {
if (!packageJsonData[nodeName].hasOwnProperty('directory')) {
greatislander marked this conversation as resolved.
Show resolved Hide resolved
return new LintIssue(lintId, severity, nodeName, message);
}

return true;
};

module.exports.lint = lint;
module.exports.ruleType = ruleType;
41 changes: 41 additions & 0 deletions test/unit/rules/require-repository-directory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 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');
});
});
});