Skip to content

Commit 651e8d0

Browse files
committed
refactor(rules): clean up rules for pull request
1 parent 382c6d3 commit 651e8d0

21 files changed

+57
-71
lines changed

@commitlint/rules/src/body-case.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ const bodyCase: Rule<ensure.TargetCaseType> = (
77
when = 'always',
88
value = undefined
99
) => {
10-
const {body} = parsed;
11-
12-
if (!body) {
10+
if (!parsed.body) {
1311
return [true];
1412
}
1513

1614
const negated = when === 'never';
17-
const result = ensure.case(body, value);
15+
const result = ensure.case(parsed.body, value);
1816

1917
return [
2018
negated ? !result : result,

@commitlint/rules/src/body-max-length.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import {maxLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const bodyMaxLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.body;
6-
7-
if (!input) {
4+
const bodyMaxLength: Rule<number> = (parsed, when = undefined, value = 0) => {
5+
if (!parsed.body) {
86
return [true];
97
}
108

119
return [
12-
maxLength(input, value),
10+
maxLength(parsed.body, value),
1311
`body must not be longer than ${value} characters`
1412
];
1513
};

@commitlint/rules/src/body-max-line-length.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ import {Rule} from './types';
33

44
const bodyMaxLineLength: Rule<number> = (
55
parsed,
6-
when = 'always',
6+
when = undefined,
77
value = 0
88
) => {
9-
const input = parsed.body;
10-
11-
if (!input) {
9+
if (!parsed.body) {
1210
return [true];
1311
}
1412

1513
return [
16-
maxLineLength(input, value),
14+
maxLineLength(parsed.body, value),
1715
`body's lines must not be longer than ${value} characters`
1816
];
1917
};

@commitlint/rules/src/body-min-length.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {minLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const bodyMinLength: Rule<number> = (parsed, when = 'always', value = 0) => {
4+
const bodyMinLength: Rule<number> = (parsed, when = undefined, value = 0) => {
55
if (!parsed.body) {
66
return [true];
77
}

@commitlint/rules/src/footer-max-length.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import {maxLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const footerMaxLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.footer;
6-
7-
if (!input) {
4+
const footerMaxLength: Rule<number> = (parsed, when = undefined, value = 0) => {
5+
if (!parsed.footer) {
86
return [true];
97
}
108

119
return [
12-
maxLength(input, value),
10+
maxLength(parsed.footer, value),
1311
`footer must not be longer than ${value} characters`
1412
];
1513
};

@commitlint/rules/src/footer-max-line-length.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ import {Rule} from './types';
33

44
const footerMaxLineLength: Rule<number> = (
55
parsed,
6-
when = 'always',
6+
when = undefined,
77
value = 0
88
) => {
9-
const input = parsed.footer;
10-
11-
if (!input) {
9+
if (!parsed.footer) {
1210
return [true];
1311
}
1412

1513
return [
16-
maxLineLength(input, value),
14+
maxLineLength(parsed.footer, value),
1715
`footer's lines must not be longer than ${value} characters`
1816
];
1917
};

@commitlint/rules/src/footer-min-length.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {minLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const footerMinLength: Rule<number> = (parsed, when = 'always', value = 0) => {
4+
const footerMinLength: Rule<number> = (parsed, when = undefined, value = 0) => {
55
if (!parsed.footer) {
66
return [true];
77
}

@commitlint/rules/src/header-max-length.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {maxLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const headerMaxLength: Rule<number> = (parsed, when = 'always', value = 0) => {
4+
const headerMaxLength: Rule<number> = (parsed, when = undefined, value = 0) => {
55
return [
66
maxLength(parsed.header, value),
77
`header must not be longer than ${value} characters, current length is ${

@commitlint/rules/src/header-min-length.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {minLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const headerMinLength: Rule<number> = (parsed, when = 'always', value = 0) => {
4+
const headerMinLength: Rule<number> = (parsed, when = undefined, value = 0) => {
55
return [
66
minLength(parsed.header, value),
77
`header must not be shorter than ${value} characters, current length is ${

@commitlint/rules/src/references-empty.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Rule} from './types';
44
const referencesEmpty: Rule = (parsed, when = 'never') => {
55
const negated = when === 'always';
66
const notEmpty = parsed.references.length > 0;
7+
78
return [
89
negated ? !notEmpty : notEmpty,
910
message(['references', negated ? 'must' : 'may not', 'be empty'])

@commitlint/rules/src/scope-case.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const scopeCase: Rule<ensure.TargetCaseType | ensure.TargetCaseType[]> = (
99
when = 'always',
1010
value = []
1111
) => {
12-
const {scope} = parsed;
13-
14-
if (!scope) {
12+
if (!parsed.scope) {
1513
return [true];
1614
}
1715

@@ -28,7 +26,7 @@ const scopeCase: Rule<ensure.TargetCaseType | ensure.TargetCaseType[]> = (
2826
// Scopes may contain slash-delimiters to separate them and mark them as individual segments.
2927
// This means that each of these segments should be tested separately with `ensure`.
3028
const delimiters = /(\/|\\)/g;
31-
const scopeSegments = scope.split(delimiters);
29+
const scopeSegments = parsed.scope.split(delimiters);
3230

3331
const result = checks.some(check => {
3432
const r = scopeSegments.every(

@commitlint/rules/src/scope-max-length.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import {maxLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const scopeMaxLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.scope;
6-
7-
if (!input) {
4+
const scopeMaxLength: Rule<number> = (parsed, when = undefined, value = 0) => {
5+
if (!parsed.scope) {
86
return [true];
97
}
108

119
return [
12-
maxLength(input, value),
10+
maxLength(parsed.scope, value),
1311
`scope must not be longer than ${value} characters`
1412
];
1513
};

@commitlint/rules/src/scope-min-length.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {minLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const scopeMinLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.scope;
6-
if (!input) {
4+
const scopeMinLength: Rule<number> = (parsed, when = undefined, value = 0) => {
5+
if (!parsed.scope) {
76
return [true];
87
}
8+
99
return [
10-
minLength(input, value),
10+
minLength(parsed.scope, value),
1111
`scope must not be shorter than ${value} characters`
1212
];
1313
};

@commitlint/rules/src/subject-full-stop.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ const subjectFullStop: Rule<string> = (
66
when = 'always',
77
value = '.'
88
) => {
9-
const input = parsed.subject;
10-
11-
if (!input) {
9+
if (!parsed.subject) {
1210
return [true];
1311
}
1412

1513
const negated = when === 'never';
16-
const hasStop = input[input.length - 1] === value;
14+
const hasStop = parsed.subject[parsed.subject.length - 1] === value;
1715

1816
return [
1917
negated ? !hasStop : hasStop,

@commitlint/rules/src/subject-max-length.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import {maxLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const subjectMaxLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.subject;
6-
7-
if (!input) {
4+
const subjectMaxLength: Rule<number> = (
5+
parsed,
6+
when = undefined,
7+
value = 0
8+
) => {
9+
if (!parsed.subject) {
810
return [true];
911
}
1012

1113
return [
12-
maxLength(input, value),
14+
maxLength(parsed.subject, value),
1315
`subject must not be longer than ${value} characters`
1416
];
1517
};

@commitlint/rules/src/subject-min-length.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import {minLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const subjectMinLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.subject;
6-
if (!input) {
4+
const subjectMinLength: Rule<number> = (
5+
parsed,
6+
when = undefined,
7+
value = 0
8+
) => {
9+
if (!parsed.subject) {
710
return [true];
811
}
12+
913
return [
10-
minLength(input, value),
14+
minLength(parsed.subject, value),
1115
`subject must not be shorter than ${value} characters`
1216
];
1317
};

@commitlint/rules/src/type-case.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const typeCase: Rule<ensure.TargetCaseType | ensure.TargetCaseType[]> = (
99
when = 'always',
1010
value = []
1111
) => {
12-
const {type} = parsed;
13-
14-
if (!type) {
12+
if (!parsed.type) {
1513
return [true];
1614
}
1715

@@ -26,7 +24,7 @@ const typeCase: Rule<ensure.TargetCaseType | ensure.TargetCaseType[]> = (
2624
});
2725

2826
const result = checks.some(check => {
29-
const r = ensure.case(type, check.case);
27+
const r = ensure.case(parsed.type!, check.case);
3028
return negated(check.when) ? !r : r;
3129
});
3230

@commitlint/rules/src/type-empty.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Rule} from './types';
55
const typeEmpty: Rule = (parsed, when = 'always') => {
66
const negated = when === 'never';
77
const notEmpty = ensure.notEmpty(parsed.type || '');
8+
89
return [
910
negated ? notEmpty : !notEmpty,
1011
message(['type', negated ? 'may not' : 'must', 'be empty'])

@commitlint/rules/src/type-enum.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import message from '@commitlint/message';
33
import {Rule} from './types';
44

55
const typeEnum: Rule<string[]> = (parsed, when = 'always', value = []) => {
6-
const {type: input} = parsed;
7-
8-
if (!input) {
6+
if (!parsed.type) {
97
return [true];
108
}
119

1210
const negated = when === 'never';
13-
const result = ensure.enum(input, value);
11+
const result = ensure.enum(parsed.type, value);
1412

1513
return [
1614
negated ? !result : result,

@commitlint/rules/src/type-max-length.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import {maxLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const typeMaxLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.type;
6-
7-
if (!input) {
4+
const typeMaxLength: Rule<number> = (parsed, when = undefined, value = 0) => {
5+
if (!parsed.type) {
86
return [true];
97
}
108

119
return [
12-
maxLength(input, value),
10+
maxLength(parsed.type, value),
1311
`type must not be longer than ${value} characters`
1412
];
1513
};

@commitlint/rules/src/type-min-length.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {minLength} from '@commitlint/ensure';
22
import {Rule} from './types';
33

4-
const typeMinLength: Rule<number> = (parsed, when = 'always', value = 0) => {
5-
const input = parsed.type;
6-
if (!input) {
4+
const typeMinLength: Rule<number> = (parsed, when = undefined, value = 0) => {
5+
if (!parsed.type) {
76
return [true];
87
}
8+
99
return [
10-
minLength(input, value),
10+
minLength(parsed.type, value),
1111
`type must not be shorter than ${value} characters`
1212
];
1313
};

0 commit comments

Comments
 (0)