Skip to content

Commit

Permalink
style: add prettier to xo config
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 13, 2018
1 parent 8ef293c commit ae3b8bb
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 391 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@
"pretest": "npm run compile && npm run lint",
"semantic-release": "semantic-release",
"test": "nyc ava -v"
},
"xo": {
"extends": [
"plugin:prettier/recommended"
]
}
}
10 changes: 5 additions & 5 deletions src/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {types} from './types';
* @return {Object} Object with each alias as a key and the alias value merge with it's `type` as value.
*/
export default transform(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);
});
}
});
42 changes: 21 additions & 21 deletions src/lib/commit-groups-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import {typesOrder} from '../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 = typesOrder.indexOf(group1.commits[0].type);
const idx2 = typesOrder.indexOf(group2.commits[0].type);
const idx1 = typesOrder.indexOf(group1.commits[0].type);
const idx2 = 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;
};
78 changes: 39 additions & 39 deletions src/lib/commit-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ 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[commit.type] && (types[commit.type].changelog || (commit.notes && commit.notes.length > 0))) {
commit.groupType = `${types[commit.type].emoji ? `${types[commit.type].emoji} ` : ''}${types[commit.type].title}`;
} else {
return null;
}
if (types[commit.type] && (types[commit.type].changelog || (commit.notes && commit.notes.length > 0))) {
commit.groupType = `${types[commit.type].emoji ? `${types[commit.type].emoji} ` : ''}${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/';
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) {
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) {
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;
commit.references = commit.references.filter(reference => {
if (references.indexOf(reference.issue) === -1) {
return true;
}
return false;
});
}
return commit;
};
26 changes: 16 additions & 10 deletions src/release-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import {types} from './types';
/**
* @type {Array} `releaseRules` configuration for `sr-commit-analyzer`.
*/
module.exports = [{breaking: true, release: 'major'}].concat(transform(types, (releaseRules, value, type) => {
if (value.release) {
if (typeof value.release === 'string') {
releaseRules.push({type, release: value.release});
}
module.exports = [{breaking: true, release: 'major'}].concat(
transform(
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));
}
}
},
[]
)
);
Loading

0 comments on commit ae3b8bb

Please sign in to comment.