Skip to content

Commit e943daf

Browse files
authored
chore: consider ts files when formatting (#690)
* chore: consider ts files when formatting * style: format according to prettier
1 parent 7de4185 commit e943daf

File tree

16 files changed

+201
-126
lines changed

16 files changed

+201
-126
lines changed

@commitlint/ensure/src/case.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,4 @@ test('true for numeric on lowercase', () => {
335335
test('throw TypeError for invalid case name', () => {
336336
const actualFn = () => ensure('anything', 'someweirdcase' as any);
337337
expect(actualFn).toThrowError(TypeError);
338-
});
338+
});

@commitlint/ensure/src/case.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@ import * as _ from 'lodash';
22

33
export default ensureCase;
44

5-
type TargetCaseType = 'camel-case' | 'kebab-case' | 'snake-case' | 'pascal-case' | 'start-case' | 'upper-case' | 'uppercase' | 'sentence-case' | 'sentencecase' | 'lower-case' | 'lowercase' | 'lowerCase';
5+
type TargetCaseType =
6+
| 'camel-case'
7+
| 'kebab-case'
8+
| 'snake-case'
9+
| 'pascal-case'
10+
| 'start-case'
11+
| 'upper-case'
12+
| 'uppercase'
13+
| 'sentence-case'
14+
| 'sentencecase'
15+
| 'lower-case'
16+
| 'lowercase'
17+
| 'lowerCase';
618

7-
function ensureCase(raw: string = '', target: TargetCaseType = 'lowercase'): boolean {
19+
function ensureCase(
20+
raw: string = '',
21+
target: TargetCaseType = 'lowercase'
22+
): boolean {
823
// We delete any content together with quotes because he can contains proper names (example `refactor: `Eslint` configuration`).
924
// We need trim string because content with quotes can be at the beginning or end of a line
1025
const input = String(raw)

@commitlint/ensure/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import globby from 'globby';
3-
import { camelCase, values } from 'lodash';
3+
import {camelCase, values} from 'lodash';
44
import * as ensure from '.';
55

66
test('exports all checkers', async () => {

@commitlint/ensure/src/max-length.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export default (value: string, max: number): boolean => typeof value === 'string' && value.length <= max;
1+
export default (value: string, max: number): boolean =>
2+
typeof value === 'string' && value.length <= max;

@commitlint/ensure/src/min-length.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export default (value: string, min: number): boolean => typeof value === 'string' && value.length >= min;
1+
export default (value: string, min: number): boolean =>
2+
typeof value === 'string' && value.length >= min;

@commitlint/ensure/src/not-empty.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export default (value: string): boolean => typeof value === 'string' && value.length > 0;
1+
export default (value: string): boolean =>
2+
typeof value === 'string' && value.length > 0;

@commitlint/execute-rule/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./lib";
1+
export * from './lib';

@commitlint/execute-rule/src/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ type ExecutedRule<T> = readonly [string, T];
66

77
export default execute;
88

9-
export async function execute<T = unknown>(rule: Rule<T>): Promise<ExecutedRule<T> | null> {
9+
export async function execute<T = unknown>(
10+
rule: Rule<T>
11+
): Promise<ExecutedRule<T> | null> {
1012
if (!Array.isArray(rule)) {
1113
return null;
1214
}
1315

1416
const [name, config] = rule;
1517

16-
const fn = executable(config)
17-
? config
18-
: async () => config;
19-
18+
const fn = executable(config) ? config : async () => config;
19+
2020
return [name, await fn()];
21-
};
21+
}
2222

2323
function executable<T>(config: Config<T>): config is ExectableConfig<T> {
2424
return typeof config === 'function';
25-
}
25+
}

@commitlint/format/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./lib";
1+
export * from './lib';

@commitlint/format/src/format.test.ts

+67-55
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ test('does nothing without .errors and .warnings', () => {
1616
});
1717

1818
test('returns empty summary if verbose', () => {
19-
const actual = format({
20-
results: [
21-
{
22-
errors: [],
23-
warnings: []
24-
}
25-
]
26-
}, {
27-
verbose: true
28-
});
19+
const actual = format(
20+
{
21+
results: [
22+
{
23+
errors: [],
24+
warnings: []
25+
}
26+
]
27+
},
28+
{
29+
verbose: true
30+
}
31+
);
2932

3033
expect(actual).toContain('0 problems, 0 warnings');
3134
});
@@ -181,67 +184,76 @@ test('format result transforms warning to text', () => {
181184
});
182185

183186
test('format result prints help for errors', () => {
184-
const actual = formatResult({
185-
errors: [
186-
{
187-
level: 2,
188-
name: 'error-name',
189-
message: 'There was an error'
190-
}
191-
]
192-
}, {
193-
helpUrl: 'https://example.com'
194-
});
187+
const actual = formatResult(
188+
{
189+
errors: [
190+
{
191+
level: 2,
192+
name: 'error-name',
193+
message: 'There was an error'
194+
}
195+
]
196+
},
197+
{
198+
helpUrl: 'https://example.com'
199+
}
200+
);
195201

196-
expect(actual).toEqual(expect.arrayContaining([
197-
expect.stringContaining('Get help:')
198-
]));
202+
expect(actual).toEqual(
203+
expect.arrayContaining([expect.stringContaining('Get help:')])
204+
);
199205
});
200206

201207
test('format result prints help for warnings', () => {
202-
const actual = formatResult({
203-
warnings: [
204-
{
205-
level: 2,
206-
name: 'warning-name',
207-
message: 'There was a warning'
208-
}
209-
]
210-
}, {
211-
helpUrl: 'https://example.com'
212-
});
208+
const actual = formatResult(
209+
{
210+
warnings: [
211+
{
212+
level: 2,
213+
name: 'warning-name',
214+
message: 'There was a warning'
215+
}
216+
]
217+
},
218+
{
219+
helpUrl: 'https://example.com'
220+
}
221+
);
213222

214-
expect(actual).toEqual(expect.arrayContaining([
215-
expect.stringContaining('Get help:')
216-
]));
223+
expect(actual).toEqual(
224+
expect.arrayContaining([expect.stringContaining('Get help:')])
225+
);
217226
});
218227

219228
test('format result help cotains options.helpUrl', () => {
220229
const helpUrl = 'https://example.com';
221230

222-
const actual = formatResult({
223-
warnings: [
224-
{
225-
level: 2,
226-
name: 'warning-name',
227-
message: 'There was a warning'
228-
}
229-
]
230-
}, {
231-
helpUrl
232-
});
231+
const actual = formatResult(
232+
{
233+
warnings: [
234+
{
235+
level: 2,
236+
name: 'warning-name',
237+
message: 'There was a warning'
238+
}
239+
]
240+
},
241+
{
242+
helpUrl
243+
}
244+
);
233245

234-
expect(actual).toEqual(expect.arrayContaining([
235-
expect.stringContaining(helpUrl)
236-
]));
246+
expect(actual).toEqual(
247+
expect.arrayContaining([expect.stringContaining(helpUrl)])
248+
);
237249
});
238250

239251
test('format result omits help for empty problems', () => {
240252
const actual = formatResult({
241253
warnings: []
242254
});
243255

244-
expect(actual).not.toEqual(expect.arrayContaining([
245-
expect.stringContaining('Get help:')
246-
]));
256+
expect(actual).not.toEqual(
257+
expect.arrayContaining([expect.stringContaining('Get help:')])
258+
);
247259
});

@commitlint/format/src/format.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export function format(
4444
return results
4545
.filter(r => Array.isArray(r.warnings) || Array.isArray(r.errors))
4646
.map(result => [...fi(result), ...fr(result)])
47-
.reduce((acc, item) => Array.isArray(item) ? [...acc, ...item] : [...acc, item], [])
47+
.reduce(
48+
(acc, item) => (Array.isArray(item) ? [...acc, ...item] : [...acc, item]),
49+
[]
50+
)
4851
.join('\n');
4952
}
5053

@commitlint/format/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default } from './format';
1+
export {default} from './format';
22
export * from './format';

0 commit comments

Comments
 (0)