Skip to content

Commit

Permalink
feat(config-angular): update to latest convention (#123)
Browse files Browse the repository at this point in the history
* refactor(config-angular): break out config-angular-type-enum
* feat(config-angular-type-enum): remove chore type
* feat(config-angular): disallow subject with uppercase first character
* fix(core): interprete array values for subject-case correctly
* test: adapt to new angular rules

BREAKING CHANGE

TL;DR
* chore is no longer a valid commit type
* subject with leading capitalized letter are forbidden now

Angular has removed the chore type from their
conventions as of January 2017

See angular/angular@dff6ee3#diff-6a3371457528722a734f3c51d9238c13L204
for reference

This removes the previous chore type from the list
of allowed types.

Projects using the Angular commit convention will identify commits with chore type as faulty.

Also, formerly working commit messages are now considered problems:

*  type: SOME MESSAGE
*  type: SomeMessage
*  type: Some Message
  • Loading branch information
marionebl authored Nov 18, 2017
1 parent 5540abb commit d4bdcf6
Show file tree
Hide file tree
Showing 37 changed files with 242 additions and 211 deletions.
4 changes: 2 additions & 2 deletions @commitlint/cli/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test('should work with husky commitmsg hook and git commit', async () => {

await execa('npm', ['install'], {cwd});
await execa('git', ['add', 'package.json'], {cwd});
await execa('git', ['commit', '-m', '"chore: this should work"'], {cwd});
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
});

test('should work with husky commitmsg hook in sub packages', async () => {
Expand All @@ -98,7 +98,7 @@ test('should work with husky commitmsg hook in sub packages', async () => {

await execa('npm', ['install'], {cwd});
await execa('git', ['add', 'package.json'], {cwd});
await execa('git', ['commit', '-m', '"chore: this should work"'], {cwd});
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
});

test('should pick up parser preset and fail accordingly', async t => {
Expand Down
41 changes: 41 additions & 0 deletions @commitlint/config-angular-type-enum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# @commitlint/config-angular-type-enum

Shareable `commitlint` config enforcing the angular commit convention types.
Use with [@commitlint/cli](../cli) and [@commitlint/prompt-cli](../prompt-cli).

See [@commitlint/config-angular](../config-angular) for full angular conventions.

## Getting started

```sh
npm install --save-dev @commitlint/config-angular-types @commitlint/cli
echo "module.exports = {extends: ['@commitlint/config-angular-type-enum']};" > commitlint.config.js
```

## Usage

```sh
echo "foo: bar" | commitlint # fails
echo "build: bar" | commitlint # passes
```

## Examples

```js
// commitlint.config.js
const types = require("@commitlint/config-angular-type-enum");

// Use as rule creating errors for non-allowed types
module.exports = {
rules: {
...types.rules
}
};

// Warn for non-allowed types
module.exports = {
rules: {
'type-enum': [1, 'always', types.values()]
}
};
```
18 changes: 18 additions & 0 deletions @commitlint/config-angular-type-enum/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const types = [
'build',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test'
];

module.exports.rules = {
'type-enum': [2, 'always', types]
};

module.exports.value = () => types;
31 changes: 31 additions & 0 deletions @commitlint/config-angular-type-enum/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@commitlint/config-angular-type-enum",
"version": "4.3.0",
"description": "Shareable commitlint config enforcing the angular commit convention types",
"scripts": {
"clean": "exit 0",
"pretest": "dep-check",
"start": "exit 0",
"test": "exit 0"
},
"xo": false,
"repository": {
"type": "git",
"url": "git+https://github.com/marionebl/commitlint.git"
},
"keywords": [
"conventional-changelog",
"commitlint",
"commitlint-config",
"angular"
],
"author": "Mario Nebl <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/marionebl/commitlint/issues"
},
"homepage": "https://github.com/marionebl/commitlint#readme",
"devDependencies": {
"@commitlint/utils": "^4.2.1"
}
}
58 changes: 49 additions & 9 deletions @commitlint/config-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Consult [docs/rules](http://marionebl.github.io/commitlint/#/reference-rules) fo
```js
[
'build',
'chore',
'ci',
'docs',
'feat',
Expand All @@ -40,6 +39,11 @@ Consult [docs/rules](http://marionebl.github.io/commitlint/#/reference-rules) fo
]
```

```sh
echo "foo: some message" # fails
echo "fix: some message" # passes
```

#### type-case
* **description**: `type` is in case `value`
* **rule**: `always`
Expand All @@ -48,21 +52,54 @@ Consult [docs/rules](http://marionebl.github.io/commitlint/#/reference-rules) fo
'lowerCase'
```

```sh
echo "FIX: some message" # fails
echo "fix: some message" # passes
```

#### type-empty
* **condition**: `type` is empty
* **rule**: `never`

```sh
echo ": some message" # fails
echo "fix: some message" # passes
```

#### scope-case
* **condition**: `scope` is in case `value`
* **rule**: `always`
```js
'lowerCase'
```

```sh
echo "fix(SCOPE): some message" # fails
echo "fix(scope): some message" # passes
```

#### subject-case
* **condition**: `subject` is in one of the cases `['sentence-case', 'start-case', 'pascal-case', 'upper-case']`
* **rule**: `never`

```sh
echo "fix(SCOPE): Some message" # fails
echo "fix(SCOPE): Some Message" # fails
echo "fix(SCOPE): SomeMessage" # fails
echo "fix(SCOPE): SOMEMESSAGE" # fails
echo "fix(scope): some message" # passes
echo "fix(scope): some Message" # passes
```

#### subject-empty
* **condition**: `subject` is empty
* **rule**: `never`

```sh
echo "fix:" # fails
echo "fix: some message" # passes
```

#### subject-full-stop
* **condition**: `subject` ends with `value`
* **rule**: `never`
Expand All @@ -71,6 +108,12 @@ Consult [docs/rules](http://marionebl.github.io/commitlint/#/reference-rules) fo
'.'
```

```sh
echo "fix: some message." # fails
echo "fix: some message" # passes
```


#### header-max-length
* **condition**: `header` has `value` or less characters
* **rule**: `always`
Expand All @@ -79,17 +122,14 @@ Consult [docs/rules](http://marionebl.github.io/commitlint/#/reference-rules) fo
72
```

```sh
echo "fix: some message that is way too long and breaks the line max-length by several characters" # fails
echo "fix: some message" # passes
```

### Warnings
The following rules are considered warnings for `@commitlint/config-angular` and will print warning messages when not met.

#### body-leading-blank
* **condition**: Body begins with blank line
* **rule**: `always`

#### lang
* **condition**: `subject` is of language `value`
* **rule**: `always`
* **value**
```js
eng
```
29 changes: 10 additions & 19 deletions @commitlint/config-angular/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
const typeEnum = require('@commitlint/config-angular-type-enum');

module.exports = {
rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lowerCase'],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [
2,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case']
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lowerCase'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test'
]
]
'type-enum': typeEnum.rules['type-enum']
}
};
3 changes: 3 additions & 0 deletions @commitlint/config-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"homepage": "https://github.com/marionebl/commitlint#readme",
"devDependencies": {
"@commitlint/utils": "^4.2.1"
},
"dependencies": {
"@commitlint/config-angular-type-enum": "^4.3.0"
}
}
12 changes: 6 additions & 6 deletions @commitlint/config-lerna-scopes/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ packages
├── app
└── web
❯ echo "chore(api): fix something in api's build" | commitlint
⧗ input: chore(api): fix something in api's build
❯ echo "buid(api): change something in api's build" | commitlint
⧗ input: build(api): change something in api's build
✔ found 0 problems, 0 warnings
❯ echo "chore(foo): this won't pass" | commitlint
⧗ input: chore(foo): this won't pass
❯ echo "test(foo): this won't pass" | commitlint
⧗ input: test(foo): this won't pass
✖ scope must be one of [api, app, web] [scope-enum]
✖ found 1 problems, 0 warnings
❯ echo "chore: do some general maintenance" | commitlint
⧗ input: chore: do some general maintenance
❯ echo "ci: do some general maintenance" | commitlint
⧗ input: ci: do some general maintenance
✔ found 0 problems, 0 warnings
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
Expand Down
8 changes: 4 additions & 4 deletions @commitlint/core/src/rules/body-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import parse from '../library/parse';
import bodyCase from './body-case';

const messages = {
empty: 'chore: subject',
lowercase: 'chore: subject\nbody',
mixedcase: 'chore: subject\nBody',
uppercase: 'chore: subject\nBODY'
empty: 'test: subject',
lowercase: 'test: subject\nbody',
mixedcase: 'test: subject\nBody',
uppercase: 'test: subject\nBODY'
};

const parsed = {
Expand Down
4 changes: 2 additions & 2 deletions @commitlint/core/src/rules/body-empty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import parse from '../library/parse';
import bodyEmpty from './body-empty';

const messages = {
empty: 'chore: subject',
filled: 'chore: subject\nbody'
empty: 'test: subject',
filled: 'test: subject\nbody'
};

const parsed = {
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/core/src/rules/body-leading-blank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import parse from '../library/parse';
import bodyLeadingBlank from './body-leading-blank';

const messages = {
simple: 'chore: subject',
without: 'chore: subject\nbody',
with: 'chore: subject\n\nbody'
simple: 'test: subject',
without: 'test: subject\nbody',
with: 'test: subject\n\nbody'
};

const parsed = {
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/core/src/rules/body-max-length.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const long = 'ab';
const value = short.length;

const messages = {
empty: 'chore: subject',
short: `chore: subject\n${short}`,
long: `chore: subject\n${long}`
empty: 'test: subject',
short: `test: subject\n${short}`,
long: `test: subject\n${long}`
};

const parsed = {
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/core/src/rules/body-min-length.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const long = 'ab';
const value = long.length;

const messages = {
simple: 'chore: subject',
short: `chore: subject\n${short}`,
long: `chore: subject\n${long}`
simple: 'test: subject',
short: `test: subject\n${short}`,
long: `test: subject\n${long}`
};

const parsed = {
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/core/src/rules/body-tense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import parse from '../library/parse';
import bodyTense from './body-tense';

test('returns deprecation warning', async t => {
const actual = bodyTense(await parse('chore: \n'), 'always', [
const actual = bodyTense(await parse('test: \n'), 'always', [
'present-imperative'
]);
t.deepEqual(actual, [
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/core/src/rules/footer-empty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import parse from '../library/parse';
import footerEmpty from './footer-empty';

const messages = {
simple: 'chore: subject',
empty: 'chore: subject\nbody',
filled: 'chore: subject\nBREAKING CHANGE: something important'
simple: 'test: subject',
empty: 'test: subject\nbody',
filled: 'test: subject\nBREAKING CHANGE: something important'
};

const parsed = {
Expand Down
Loading

0 comments on commit d4bdcf6

Please sign in to comment.