Skip to content

Commit

Permalink
Name format (#118)
Browse files Browse the repository at this point in the history
* Remove validator and add ajv-errors

* Add new property exist module

* Add the ability to add exceptions

Closes #93

* Update format.test.js

* Update format.js

* Update format.js

* Enhance name format rule

Closes #115
  • Loading branch information
tclindner committed Jun 29, 2019
1 parent 973c603 commit 1dd158f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
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

0 comments on commit 1dd158f

Please sign in to comment.