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

Name format #118

Merged
merged 8 commits into from Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/rules/name-format.js
Expand Up @@ -3,16 +3,32 @@ const LintIssue = require('./../LintIssue');

const lintId = 'name-format';
const nodeName = 'name';
const message = 'Format should be all lowercase';
const ruleType = 'standard';
const maxLength = 214;

const lint = (packageJsonData, severity) => {
if (!isLowercase(packageJsonData, nodeName)) {
return new LintIssue(lintId, severity, nodeName, message);
if (!packageJsonData.hasOwnProperty(nodeName)) {
return true;
}

const name = packageJsonData[nodeName];

if (!isLowercase(name)) {
return new LintIssue(lintId, severity, nodeName, 'Format should be all lowercase');
}

if (name.length > maxLength) {
return new LintIssue(lintId, severity, nodeName, `name should be less than or equal to ${maxLength} characters.`);
}

if (name.startsWith('.') || name.startsWith('_')) {
return new LintIssue(lintId, severity, nodeName, 'name should not start with . or _');
}

return true;
};

module.exports.lint = lint;
module.exports.ruleType = ruleType;
module.exports = {
lint,
ruleType
};
4 changes: 0 additions & 4 deletions src/validators/format.js
Expand Up @@ -6,10 +6,6 @@ const semver = require('semver');
* @return {boolean} True if the string is lowercase or is missing. False if it is not.
*/
const isLowercase = name => {
if (typeof name !== 'string') {
return true;
}

return name === name.toLowerCase();
};

Expand Down
2 changes: 1 addition & 1 deletion test/unit/rules/name-format.test.js
Expand Up @@ -10,7 +10,7 @@ describe('name-format Unit Tests', () => {
});

describe('when package.json has node with incorrect format', () => {
test('LintIssue object should be returned', () => {
test('not lowercase - LintIssue object should be returned', () => {
const packageJsonData = {
name: 'ImNotLowercase'
};
Expand Down