Skip to content

Commit

Permalink
docs: add missing rules to documentation (#2428)
Browse files Browse the repository at this point in the history
* docs: correct documentation for rules

- missing docs for rules:
 - body-case
 - footer-empty
 - body-empty
- add simple unit test for docs validation
- update lowerCase to lower-case

* test: improve unit test for rules
  • Loading branch information
armano2 committed Jan 28, 2021
1 parent c548a32 commit a1ddfcf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
14 changes: 14 additions & 0 deletions @commitlint/rules/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import fs from 'fs';
import globby from 'globby';
import rules from '.';

Expand All @@ -13,6 +14,19 @@ test('rules export functions', () => {
expect(actual.every((rule) => typeof rule === 'function')).toBe(true);
});

test('all rules are present in documentation', () => {
const file = fs.readFileSync(
path.join(__dirname, '../../../docs/reference-rules.md'),
'utf-8'
);
const results = file
.split(/(\n|\r)/)
.filter((s) => s.startsWith('####') && !s.includes('`deprecated`'))
.map((s) => s.replace('#### ', ''));

expect(Object.keys(rules)).toEqual(expect.arrayContaining(results));
});

async function glob(pattern: string | string[]) {
const files = await globby(pattern, {
ignore: ['**/index.ts', '**/*.test.ts'],
Expand Down
41 changes: 38 additions & 3 deletions docs/reference-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Rule configurations are either of type `array` residing on a key with the rule's
- **condition**: `body` begins with blank line
- **rule**: `always`

#### body-empty

- **condition**: `body` is empty
- **rule**: `never`

#### body-max-length

- **condition**: `body` has `value` or less characters
Expand Down Expand Up @@ -87,11 +92,41 @@ Infinity
0
```

#### body-case

- **condition**: `header` is in case `value`
- **rule**: `always`
- **value**

```
'lower-case'
```

- **possible values**

```
[
'lower-case', // default
'upper-case', // UPPERCASE
'camel-case', // camelCase
'kebab-case', // kebab-case
'pascal-case', // PascalCase
'sentence-case', // Sentence case
'snake-case', // snake_case
'start-case' // Start Case
]
```

#### footer-leading-blank

- **condition**: `footer` begins with blank line
- **rule**: `always`

#### footer-empty

- **condition**: `footer` is empty
- **rule**: `never`

#### footer-max-length

- **condition**: `footer` has `value` or less characters
Expand Down Expand Up @@ -129,7 +164,7 @@ Infinity
- **value**

```
'lowerCase'
'lower-case'
```

- **possible values**
Expand Down Expand Up @@ -198,7 +233,7 @@ Infinity
- **value**

```
'lowerCase'
'lower-case'
```

- **possible values**
Expand Down Expand Up @@ -248,7 +283,7 @@ Infinity
- **value**

```
'lowerCase'
'lower-case'
```

- **possible values**
Expand Down

0 comments on commit a1ddfcf

Please sign in to comment.