Skip to content

Commit

Permalink
build: use XO instead of custom eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 13, 2018
1 parent c2c699e commit 3b365dc
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 407 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion commitlint.config.js

This file was deleted.

21 changes: 4 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,13 @@
"devDependencies": {
"ava": "^0.24.0",
"babel-cli": "^6.26.0",
"babel-eslint": "^8.0.0",
"babel-preset-env": "^1.6.0",
"codecov": "^3.0.0",
"conventional-changelog": "^1.1.4",
"conventional-commits-parser": "^2.0.0",
"emoji-regex": "^6.5.1",
"eslint": "^4.5.0",
"eslint-config-prettier": "^2.3.0",
"eslint-config-pretty": "^2.1.1",
"eslint-plugin-ava": "^4.2.1",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-eslint-comments": "^2.0.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jasmine": "^2.8.4",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-prettier": "^2.2.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-sort-class-members": "^1.2.0",
"eslint-plugin-unicorn": "^3.0.0",
"execa": "^0.9.0",
"fs-extra": "^5.0.0",
"get-stream": "^3.0.0",
Expand All @@ -43,7 +30,8 @@
"rimraf": "^2.6.1",
"semantic-release": "^12.0.0",
"stringz": "^0.4.0",
"tempy": "^0.2.0"
"tempy": "^0.2.0",
"xo": "^0.18.2"
},
"engines": {
"node": ">=4"
Expand Down Expand Up @@ -98,12 +86,11 @@
"url": "https://github.com/vanduynslagerp/conventional-changelog-metahub.git"
},
"scripts": {
"clean": "rimraf coverage && rimraf .nyc_output",
"codecov": "codecov -f coverage/coverage-final.json",
"compile": "rimraf preset.* release-rules.* types.* aliases.* lib && babel src --source-maps --out-dir .",
"lint": "eslint src test package.json",
"lint": "xo",
"prepublishOnly": "npm run compile",
"pretest": "npm run clean && npm run compile && npm run lint",
"pretest": "npm run compile && npm run lint",
"semantic-release": "semantic-release",
"test": "nyc ava -v"
}
Expand Down
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);
});
}
});
30 changes: 21 additions & 9 deletions src/lib/commit-groups-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +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;
};
1 change: 1 addition & 0 deletions src/preset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {merge} from 'lodash';
import conventionalChangelogAngular from 'conventional-changelog-angular';

const commitGroupsSort = require('./lib/commit-groups-compare');
const transform = require('./lib/commit-transform');

Expand Down
26 changes: 10 additions & 16 deletions src/release-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ 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 3b365dc

Please sign in to comment.