Skip to content

Commit

Permalink
chore(deps): replace xo with eslint & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed May 26, 2023
1 parent 37cf116 commit feffd9f
Show file tree
Hide file tree
Showing 23 changed files with 6,745 additions and 10,336 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 'latest',
},
env: {
node: true,
es6: true,
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
ignorePatterns: ['.eslintrc.js'],
overrides: [
{
files: ['test/**/*.js'],
parserOptions: {
sourceType: 'module',
},
plugins: ['ava'],
},
],
};
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CHANGELOG.md

.nyc_output
coverage
9 changes: 8 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{ "printWidth": 120, "trailingComma": "es5" }
{
"tabWidth": 2,
"printWidth": 80,
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"endOfLine": "lf"
}
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
Also provides [release rules](https://github.com/semantic-release/commit-analyzer#releaserules) configuration for [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer#releaserules).

Commit types originally from:

- [Angular Git Commit Message Conventions](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#type)
- [commitizen/cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog)
- [conventional-commit-types](https://github.com/commitizen/conventional-commit-types)

## Install

```bash
npm install --save-dev @insurgentlab/conventional-changelog-preset
```
Expand All @@ -27,10 +29,13 @@ npm install --save-dev @semantic-release/commit-analyzer
```json
{
"plugins": [
["@semantic-release/commit-analyzer", {
"config": "@insurgentlab/conventional-changelog-preset",
"releaseRules": "@insurgentlab/conventional-changelog-preset/release-rules"
}]
[
"@semantic-release/commit-analyzer",
{
"config": "@insurgentlab/conventional-changelog-preset",
"releaseRules": "@insurgentlab/conventional-changelog-preset/release-rules"
}
]
]
}
```
Expand All @@ -44,9 +49,12 @@ npm install --save-dev @semantic-release/release-notes-generator
```json
{
"plugins": [
["@semantic-release/release-notes-generator", {
"config": "@insurgentlab/conventional-changelog-preset"
}]
[
"@semantic-release/release-notes-generator",
{
"config": "@insurgentlab/conventional-changelog-preset"
}
]
]
}
```
Expand All @@ -61,39 +69,40 @@ npm install --save-dev conventional-changelog
import conventionalChangelog from 'conventional-changelog';

const config = require('@insurgentlab/conventional-changelog-preset');
conventionalChangelog({config}).pipe(process.stdout);
conventionalChangelog({ config }).pipe(process.stdout);
```

## Commit types

| Commit Type | Title | Description | Emoji | Release | Include in changelog |
|:-----------:|--------------------------|-------------------------------------------------------------------------------------------------------------|:-----:|--------------------------------|:--------------------:|
| `feat` | Features | A new feature | | `minor` | `true` |
| :---------: | ------------------------ | ----------------------------------------------------------------------------------------------------------- | :---: | ------------------------------ | :------------------: |
| `feat` | Features | A new feature || `minor` | `true` |
| `fix` | Bug Fixes | A bug Fix | 🐛 | `patch` | `true` |
| `docs` | Documentation | Documentation only changes | 📚 | `patch` if `scope` is `readme` | `true` |
| `style` | Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) | 💎 | - | `true` |
| `refactor` | Code Refactoring | A code change that neither fixes a bug nor adds a feature | 📦 | - | `true` |
| `perf` | Performance Improvements | A code change that improves performance | 🚀 | `patch` | `true` |
| `test` | Tests | Adding missing tests or correcting existing tests | 🚨 | - | `true` |
| `build` | Builds | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) | 🛠 | `patch` | `true` |
| `build` | Builds | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) | 🛠 | `patch` | `true` |
| `ci` | Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) | ⚙️ | - | `true` |
| `chore` | Chores | Other changes that don't modify src or test files | ♻️ | - | `true` |
| `revert` | Reverts | Reverts a previous commit | 🗑 | - | `true` |
| `revert` | Reverts | Reverts a previous commit | 🗑 | - | `true` |

## Commit aliases

Aliases allow to have additional commit types (in a tool like [commitizen](https://github.com/commitizen/cz-cli) for example) that can be formatted to follow [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit).

For example the [commitizen](https://github.com/commitizen/cz-cli) CLI can present the choice `initial` and the final commit message will be 'feat: Initial commit 🎉'

| Commit Type | Maps to | Title | Description | Emoji |
|:------------------:| ------- | ----------------- | ------------------------------ |:------:|
| `initial` | `feat` | Initial | Initial commit | 🎉 |
| `dependencies` | `fix` | Dependencies | Update dependencies | ⬆️ |
| `peerDependencies` | `fix` | Peer dependencies | Update peer dependencies | ⬆️ |
| `devDependencies` | `chore` | Dev dependencies | Update development dependencies | ⬆️ |
| `metadata` | `fix` | Metadata | Update metadata (package.json) | 📦 |
| Commit Type | Maps to | Title | Description | Emoji |
| :----------------: | ------- | ----------------- | ------------------------------- | :---: |
| `initial` | `feat` | Initial | Initial commit | 🎉 |
| `dependencies` | `fix` | Dependencies | Update dependencies | ⬆️ |
| `peerDependencies` | `fix` | Peer dependencies | Update peer dependencies | ⬆️ |
| `devDependencies` | `chore` | Dev dependencies | Update development dependencies | ⬆️ |
| `metadata` | `fix` | Metadata | Update metadata (package.json) | 📦 |

## Related

- [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog)
- [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
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);
});
}
});
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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'}})
module.exports = conventionalChangelogAngular.then((preset) =>
_.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,32 +10,32 @@ 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 === -1 && idx2 !== -1) {
return 1;
}
if (idx1 === -1 && idx2 !== -1) {
return 1;
}

if (idx1 < idx2) {
return -1;
}
if (idx1 < idx2) {
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;
}

if (group1.title > group2.title) {
return 1;
}
if (group1.title > group2.title) {
return 1;
}

return 0;
return 0;
};
97 changes: 53 additions & 44 deletions lib/commit-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,67 @@ 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.shortHash = commit.hash.slice(0, COMMIT_HASH_LENGTH);
}
if (typeof commit.hash === 'string') {
commit.shortHash = commit.hash.slice(0, COMMIT_HASH_LENGTH);
}

const references = [];
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(/#(\d+)/g, (_, issue) => {
references.push(issue);
return `[#${issue}](${url}${issue})`;
});
}
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 (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.includes(reference.issue)) {
return true;
}
if (commit.references) {
// Remove references that already appear in the subject
commit.references = commit.references.filter((reference) => {
if (!references.includes(reference.issue)) {
return true;
}

return false;
});
}
return false;
});
}

return commit;
return commit;
};
Loading

0 comments on commit feffd9f

Please sign in to comment.