Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Feb 15, 2018
1 parent f7d2db1 commit 59a02fc
Show file tree
Hide file tree
Showing 16 changed files with 503 additions and 503 deletions.
10 changes: 5 additions & 5 deletions aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const types = require('./types');
* @return {Object} Object with each alias as a key and the alias value merge with it's `type` as value.
*/
module.exports = _.transform(types.types, (aliases, value, type) => {
if (value.aliases) {
_.each(value.aliases, (aliasValue, alias) => {
aliases[alias] = _.merge({type}, aliasValue);
});
}
if (value.aliases) {
_.each(value.aliases, (aliasValue, alias) => {
aliases[alias] = _.merge({type}, aliasValue);
});
}
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ const transform = require('./lib/commit-transform');
* @type {Promise<Object>} preset with `parserOpts` and `writerOpts`.
*/
module.exports = conventionalChangelogAngular.then(preset =>
_.merge(preset, {writerOpts: {transform, commitGroupsSort, groupBy: 'groupType'}})
_.merge(preset, {writerOpts: {transform, commitGroupsSort, groupBy: 'groupType'}})
);
42 changes: 21 additions & 21 deletions lib/commit-groups-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ const types = require('../types');
* @return {integer} -1 if `group1` should be displayed before `group2`, 1 for the opposite and 0 if they are equals.
*/
module.exports = (group1, group2) => {
const idx1 = types.typesOrder.indexOf(group1.commits[0].type);
const idx2 = types.typesOrder.indexOf(group2.commits[0].type);
const idx1 = types.typesOrder.indexOf(group1.commits[0].type);
const idx2 = types.typesOrder.indexOf(group2.commits[0].type);

if (idx1 !== -1 && idx2 === -1) {
return -1;
}
if (idx1 === -1 && idx2 !== -1) {
return 1;
}
if (idx1 < idx2) {
return -1;
}
if (idx1 > idx2) {
return 1;
}
if (group1.title < group2.title) {
return -1;
}
if (group1.title > group2.title) {
return 1;
}
return 0;
if (idx1 !== -1 && idx2 === -1) {
return -1;
}
if (idx1 === -1 && idx2 !== -1) {
return 1;
}
if (idx1 < idx2) {
return -1;
}
if (idx1 > idx2) {
return 1;
}
if (group1.title < group2.title) {
return -1;
}
if (group1.title > group2.title) {
return 1;
}
return 0;
};
88 changes: 44 additions & 44 deletions lib/commit-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@ const COMMIT_HASH_LENGTH = 7;
* @return {Object} the transformed commit.
*/
module.exports = (commit, context) => {
if (commit.notes) {
commit.notes.forEach(note => {
note.title = 'Breaking changes';
});
}
if (commit.notes) {
commit.notes.forEach(note => {
note.title = 'Breaking changes';
});
}

if (types.types[commit.type] && (types.types[commit.type].changelog || (commit.notes && commit.notes.length > 0))) {
commit.groupType = `${types.types[commit.type].emoji ? `${types.types[commit.type].emoji} ` : ''}${
types.types[commit.type].title
}`;
} else {
return null;
}
if (types.types[commit.type] && (types.types[commit.type].changelog || (commit.notes && commit.notes.length > 0))) {
commit.groupType = `${types.types[commit.type].emoji ? `${types.types[commit.type].emoji} ` : ''}${
types.types[commit.type].title
}`;
} else {
return null;
}

if (commit.scope === '*') {
commit.scope = '';
}
if (commit.scope === '*') {
commit.scope = '';
}

if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, COMMIT_HASH_LENGTH);
}
const references = [];
if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, COMMIT_HASH_LENGTH);
}
const references = [];

if (typeof commit.subject === 'string') {
let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl;
if (typeof commit.subject === 'string') {
let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl;

if (url) {
url += '/issues/';
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
references.push(issue);
return `[#${issue}](${url}${issue})`;
});
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9]){0,38})/g, `[@$1](${context.host}/$1)`);
}
}
if (commit.references) {
// Remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (references.indexOf(reference.issue) === -1) {
return true;
}
return false;
});
}
return commit;
if (url) {
url += '/issues/';
// Issue URLs.
commit.subject = commit.subject.replace(/#(\d+)/g, (_, issue) => {
references.push(issue);
return `[#${issue}](${url}${issue})`;
});
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9]){0,38})/g, `[@$1](${context.host}/$1)`);
}
}
if (commit.references) {
// Remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (references.indexOf(reference.issue) === -1) {
return true;
}
return false;
});
}
return commit;
};
28 changes: 14 additions & 14 deletions release-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ const types = require('./types');
* @type {Array} `releaseRules` configuration for `sr-commit-analyzer`.
*/
module.exports = [{breaking: true, release: 'major'}].concat(
_.transform(
types.types,
(releaseRules, value, type) => {
if (value.release) {
if (typeof value.release === 'string') {
releaseRules.push({type, release: value.release});
}
_.transform(
types.types,
(releaseRules, value, type) => {
if (value.release) {
if (typeof value.release === 'string') {
releaseRules.push({type, release: value.release});
}

if (value.release.release) {
releaseRules.push(Object.assign({type}, value.release));
}
}
},
[]
)
if (value.release.release) {
releaseRules.push(Object.assign({type}, value.release));
}
}
},
[]
)
);
42 changes: 21 additions & 21 deletions test/aliases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ import {types, typesOrder} from '../types';
* @param {string} type type to verify
*/
function hasProperty(t, object, prop, type) {
for (const obj in object) {
if (Object.prototype.hasOwnProperty.call(object, obj)) {
t.true(Object.prototype.hasOwnProperty.call(object[obj], prop));
if (type === 'string') {
t.true(typeof object[obj][prop] === type);
} else if (type === 'emoji') {
t.true(emojiRegex({exact: true}).test(object[obj][prop]));
t.is(length(object[obj][prop]), 1);
}
}
}
for (const obj in object) {
if (Object.prototype.hasOwnProperty.call(object, obj)) {
t.true(Object.prototype.hasOwnProperty.call(object[obj], prop));
if (type === 'string') {
t.true(typeof object[obj][prop] === type);
} else if (type === 'emoji') {
t.true(emojiRegex({exact: true}).test(object[obj][prop]));
t.is(length(object[obj][prop]), 1);
}
}
}
}

test('Each alias has the property title', hasProperty, aliases, 'title', 'string');
test('Each type has the property description', hasProperty, aliases, 'description', 'string');
test('Each type has the property emoji', hasProperty, aliases, 'emoji', 'emoji');

test('Each alias`s type property has a value that exists in types', t => {
for (const alias in aliases) {
if (Object.prototype.hasOwnProperty.call(aliases, alias)) {
t.true(Object.prototype.hasOwnProperty.call(types, aliases[alias].type));
}
}
for (const alias in aliases) {
if (Object.prototype.hasOwnProperty.call(aliases, alias)) {
t.true(Object.prototype.hasOwnProperty.call(types, aliases[alias].type));
}
}
});

test('Each alias exists in typesOrder', t => {
for (const type in types) {
if (Object.prototype.hasOwnProperty.call(types, type)) {
t.true(typesOrder.indexOf(type) !== -1);
}
}
for (const type in types) {
if (Object.prototype.hasOwnProperty.call(types, type)) {
t.true(typesOrder.indexOf(type) !== -1);
}
}
});
88 changes: 44 additions & 44 deletions test/commit-groups-compare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@ import test from 'ava';
import commitGroupsCompare from './helpers/commit-groups-compare';

test('Return ordered commit groups', t => {
const commitGroups = [
{title: '📘 Documentation', commits: [{type: 'docs'}]},
{title: '🐞 Bug Fixes', commits: [{type: 'fix'}]},
{title: 'Features', commits: [{type: 'feat'}]},
];
const compare = commitGroupsCompare({
typesOrder: ['feat', 'fix', 'docs', 'initial', 'metadata'],
types: {
feat: {title: 'Features'},
fix: {title: 'Bug Fixes'},
docs: {title: 'Documentation'},
},
});
const commitGroups = [
{title: '📘 Documentation', commits: [{type: 'docs'}]},
{title: '🐞 Bug Fixes', commits: [{type: 'fix'}]},
{title: 'Features', commits: [{type: 'feat'}]},
];
const compare = commitGroupsCompare({
typesOrder: ['feat', 'fix', 'docs', 'initial', 'metadata'],
types: {
feat: {title: 'Features'},
fix: {title: 'Bug Fixes'},
docs: {title: 'Documentation'},
},
});

t.deepEqual(commitGroups.sort(compare), [
{title: 'Features', commits: [{type: 'feat'}]},
{title: '🐞 Bug Fixes', commits: [{type: 'fix'}]},
{title: '📘 Documentation', commits: [{type: 'docs'}]},
]);
t.deepEqual(commitGroups.sort(compare), [
{title: 'Features', commits: [{type: 'feat'}]},
{title: '🐞 Bug Fixes', commits: [{type: 'fix'}]},
{title: '📘 Documentation', commits: [{type: 'docs'}]},
]);
});

test('Return alphabeticaly ordered commit groups not in "typesOrder" at the end of the list', t => {
const commitGroups = [
{title: 'b-Test', commits: [{type: 'btest'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
{title: 'Bug Fixes', commits: [{type: 'fix'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
{title: 'a-Test', commits: [{type: 'atest'}]},
{title: 'Features', commits: [{type: 'feat'}]},
];
const compare = commitGroupsCompare({
typesOrder: ['feat', 'fix'],
types: {
feat: {title: 'Features'},
fix: {title: 'Bug Fixes'},
atest: {title: 'a-Test'},
ztest: {title: 'z-Test'},
btest: {title: 'b-Test'},
},
});
const commitGroups = [
{title: 'b-Test', commits: [{type: 'btest'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
{title: 'Bug Fixes', commits: [{type: 'fix'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
{title: 'a-Test', commits: [{type: 'atest'}]},
{title: 'Features', commits: [{type: 'feat'}]},
];
const compare = commitGroupsCompare({
typesOrder: ['feat', 'fix'],
types: {
feat: {title: 'Features'},
fix: {title: 'Bug Fixes'},
atest: {title: 'a-Test'},
ztest: {title: 'z-Test'},
btest: {title: 'b-Test'},
},
});

t.deepEqual(commitGroups.sort(compare), [
{title: 'Features', commits: [{type: 'feat'}]},
{title: 'Bug Fixes', commits: [{type: 'fix'}]},
{title: 'a-Test', commits: [{type: 'atest'}]},
{title: 'b-Test', commits: [{type: 'btest'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
]);
t.deepEqual(commitGroups.sort(compare), [
{title: 'Features', commits: [{type: 'feat'}]},
{title: 'Bug Fixes', commits: [{type: 'fix'}]},
{title: 'a-Test', commits: [{type: 'atest'}]},
{title: 'b-Test', commits: [{type: 'btest'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
{title: 'z-Test', commits: [{type: 'ztest'}]},
]);
});
Loading

0 comments on commit 59a02fc

Please sign in to comment.