Skip to content

Commit f040981

Browse files
committed
style(lint): lint files
lint all files by executing 'lint' npm script
1 parent ff051f3 commit f040981

18 files changed

+161
-150
lines changed

.eslintrc.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"node": true
55
},
66
"parser": "@typescript-eslint/parser",
7-
"plugins": ["@typescript-eslint", "prettier", "import", "unicorn"],
7+
"plugins": [
8+
"@typescript-eslint",
9+
"prettier",
10+
"import",
11+
"unicorn"
12+
],
813
"extends": [
914
"eslint:recommended",
1015
"plugin:@typescript-eslint/eslint-recommended",
@@ -31,13 +36,18 @@
3136
},
3237
"overrides": [
3338
{
34-
"files": ["*.test.ts"],
39+
"files": [
40+
"*.test.ts"
41+
],
3542
"rules": {
3643
"@typescript-eslint/no-non-null-assertion": "off"
3744
}
3845
}
3946
],
4047
"settings": {
41-
"import/extensions": [".ts", ".js"]
48+
"import/extensions": [
49+
".ts",
50+
".js"
51+
]
4252
}
4353
}

commitlint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
extends: ['@commitlint/config-conventional'],
33
rules: {
4-
'scope-enum': [2, 'always', ['deps']]
5-
}
4+
'scope-enum': [2, 'always', ['deps']],
5+
},
66
};

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
44
collectCoverage: true,
5-
collectCoverageFrom: ['src/**/*.ts']
5+
collectCoverageFrom: ['src/**/*.ts'],
66
};

src/commit-template.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('commit-template', () => {
55
test.each<[Answers, string]>([
66
[{ type: 'foo', scope: 'bar', subject: 'baz' }, 'foo(bar): baz'],
77
[{ type: 'foo' }, 'foo: '],
8-
[{ type: 'foo', subject: 'bar' }, 'foo: bar']
8+
[{ type: 'foo', subject: 'bar' }, 'foo: bar'],
99
])(`should convert answers %o to template '%s'`, (answers, expected) => {
1010
const result = headerTemplate(answers.type, answers.scope, answers.subject);
1111

@@ -17,10 +17,10 @@ describe('commit-template', () => {
1717
test.each<[Answers, string]>([
1818
[
1919
{ type: 'foo', scope: 'bar', subject: 'baz', body: '\nbody', breaking: '\nfooter' },
20-
`foo(bar): baz\n\nbody\n\nfooter`
20+
`foo(bar): baz\n\nbody\n\nfooter`,
2121
],
2222
[{ type: 'foo', subject: 'bar' }, 'foo: bar'],
23-
[{ type: 'foo', subject: 'bar', breaking: '\nbaz', issue: '\nbuz' }, 'foo: bar\n\nbaz\nbuz']
23+
[{ type: 'foo', subject: 'bar', breaking: '\nbaz', issue: '\nbuz' }, 'foo: bar\n\nbaz\nbuz'],
2424
])(`should convert answers %o to template '%s'`, (answers, expected) => {
2525
const result = commitTemplate(answers);
2626

src/engine.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { Question, commitTemplate } from './commit-template';
1212
function buildQuestions(rules: Rules) {
1313
const combinedQuestions = pipeWith<Question[]>(
1414
[],
15-
x => typeMaker(x, rules),
16-
x => scopeMaker(x, rules),
17-
x => subjectMaker(x, rules),
18-
x => bodyMaker(x, rules),
19-
x => footerMaker(x, rules)
15+
(x) => typeMaker(x, rules),
16+
(x) => scopeMaker(x, rules),
17+
(x) => subjectMaker(x, rules),
18+
(x) => bodyMaker(x, rules),
19+
(x) => footerMaker(x, rules)
2020
);
2121

2222
return combinedQuestions;

src/prompts/body-maker.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('body-maker', () => {
88
[{ 'body-max-length': [Level.Error, 'always', 3] }, 'too long', 'Body maximum length of 3 has been exceeded'],
99
[{ 'body-max-length': [Level.Error, 'always', 72] }, 'too long', true],
1010
[{ 'body-min-length': [Level.Error, 'always', 3] }, 'f', 'Body minimum length of 3 has not been met'],
11-
[{ 'body-min-length': [Level.Error, 'always', 3] }, 'foo bar baz', true]
11+
[{ 'body-min-length': [Level.Error, 'always', 3] }, 'foo bar baz', true],
1212
])(`should validate rule '%o', value '%s', expected '%s'`, (rules, value, expected) => {
1313
const factory = validatorFactory(rules);
1414

@@ -21,7 +21,7 @@ describe('body-maker', () => {
2121
describe('filterFactory', () => {
2222
test.each<[Rules, string, string]>([
2323
[{ 'body-leading-blank': [Level.Error, 'always', undefined] }, 'foo bar', '\nfoo bar'],
24-
[{ 'body-max-line-length': [Level.Error, 'always', 4] }, 'foo bar baz buz', 'foo \nbar \nbaz \nbuz']
24+
[{ 'body-max-line-length': [Level.Error, 'always', 4] }, 'foo bar baz buz', 'foo \nbar \nbaz \nbuz'],
2525
])(`should format rule: '%o', value: %s for expected '%s'`, (rules, value, expected) => {
2626
const factory = filterFactory(rules);
2727

@@ -33,7 +33,7 @@ describe('body-maker', () => {
3333
it('should prepend body with and leading empty line', () => {
3434
const rules: Rules = {
3535
'body-leading-blank': [Level.Error, 'always', undefined],
36-
'body-max-line-length': [Level.Error, 'never', Infinity]
36+
'body-max-line-length': [Level.Error, 'never', Infinity],
3737
};
3838
const userTypedBody = 'my message should be prepended with an empty new line';
3939

@@ -48,7 +48,7 @@ describe('body-maker', () => {
4848
[{ 'body-max-length': [Level.Error, 'always', 4] }, 'foo', green('(3) foo')],
4949
[{ 'body-max-length': [Level.Error, 'always', 2] }, 'foo', red('(3) foo')],
5050
[{}, 'foo\\nbar', 'foo\nbar'],
51-
[{}, 'foo', 'foo']
51+
[{}, 'foo', 'foo'],
5252
])(`should transform for rules: '%o', value: '%o' for expected: '%s'`, (rules, value, expected) => {
5353
const factory = transformerFactory(rules);
5454

src/prompts/body-maker.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ export function validatorFactory(rules: Rules) {
1111
value,
1212
rule: rules['body-max-length'],
1313
validator: maxLengthValidator,
14-
message: length => `Body maximum length of ${length} has been exceeded`
14+
message: (length) => `Body maximum length of ${length} has been exceeded`,
1515
},
1616
{
1717
value,
1818
rule: rules['body-min-length'],
1919
validator: minLengthValidator,
20-
message: length => `Body minimum length of ${length} has not been met`
21-
}
20+
message: (length) => `Body minimum length of ${length} has not been met`,
21+
},
2222
]);
2323
}
2424

2525
export function filterFactory(rules: Rules) {
2626
return (value: string) =>
2727
pipeWith<string>(
2828
value,
29-
v => maxLineLengthFilter(v, rules['body-max-line-length']),
30-
v => leadingBlankFilter(v, rules['body-leading-blank']),
31-
v => v.replace(/\\n/g, '\n')
29+
(v) => maxLineLengthFilter(v, rules['body-max-line-length']),
30+
(v) => leadingBlankFilter(v, rules['body-leading-blank']),
31+
(v) => v.replace(/\\n/g, '\n')
3232
);
3333
}
3434

@@ -40,8 +40,8 @@ export function transformerFactory(rules: Rules) {
4040
return (value: string) => {
4141
return pipeWith(
4242
value,
43-
v => v.replace(/\\n/g, '\n'),
44-
v => maxLenTransformer(v)
43+
(v) => v.replace(/\\n/g, '\n'),
44+
(v) => maxLenTransformer(v)
4545
);
4646
};
4747
}
@@ -54,8 +54,8 @@ export function bodyMaker(questions: Question[], rules: Rules): Question[] {
5454
message: 'Provide a longer description of the change: (press enter to skip, \\n for newline)\n',
5555
validate: validatorFactory(rules),
5656
filter: filterFactory(rules),
57-
transformer: transformerFactory(rules)
58-
}
57+
transformer: transformerFactory(rules),
58+
},
5959
];
6060

6161
return [...questions, ...bodyQuestions];

src/prompts/footer-maker.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ export function validatorFactory(rules: Rules) {
1515
value: value + breaking,
1616
rule: rules['footer-max-length'],
1717
validator: maxLengthValidator,
18-
message: length => `Footer maximum length of ${length} has been exceeded`
18+
message: (length) => `Footer maximum length of ${length} has been exceeded`,
1919
},
2020
{
2121
value: value + breaking,
2222
rule: rules['footer-min-length'],
2323
validator: minLengthValidator,
24-
message: length => `Footer minimum length of ${length} has not been met`
25-
}
24+
message: (length) => `Footer minimum length of ${length} has not been met`,
25+
},
2626
]);
2727
};
2828
}
@@ -31,9 +31,9 @@ export function filterFactory(rules: Rules, prefix = '') {
3131
return (value: string): string =>
3232
pipeWith<string>(
3333
value,
34-
v => prefix + v,
35-
v => leadingBlankFilter(v, rules['footer-leading-blank']),
36-
v => maxLineLengthFilter(v, rules['footer-max-line-length'])
34+
(v) => prefix + v,
35+
(v) => leadingBlankFilter(v, rules['footer-leading-blank']),
36+
(v) => maxLineLengthFilter(v, rules['footer-max-line-length'])
3737
);
3838
}
3939

@@ -99,33 +99,33 @@ export function footerMaker(questions: Question[], rules: Rules): Question[] {
9999
type: 'confirm',
100100
name: 'isBreaking',
101101
message: 'Are there any breaking changes?',
102-
default: false
102+
default: false,
103103
},
104104
{
105105
type: 'input',
106106
name: 'breaking',
107107
message: breakingChangeMessageFactory(rules),
108-
when: answers => !!answers.isBreaking,
108+
when: (answers) => !!answers.isBreaking,
109109
validate: validatorFactory(rules),
110110
transformer: breakingTransformFactory(rules, BREAKING_CHANGE),
111-
filter: filterFactory(rules, BREAKING_CHANGE)
111+
filter: filterFactory(rules, BREAKING_CHANGE),
112112
},
113113
{
114114
type: 'confirm',
115115
name: 'isIssue',
116116
message: 'Does this fix Does this change affect any open issues?',
117-
when: answers => !isFixCommit(answers),
118-
default: false
117+
when: (answers) => !isFixCommit(answers),
118+
default: false,
119119
},
120120
{
121121
type: 'input',
122122
name: 'issue',
123123
message: issuesMessageFactory(rules),
124-
when: answers => isFixCommit(answers) || !!answers.isIssue,
124+
when: (answers) => isFixCommit(answers) || !!answers.isIssue,
125125
validate: validatorFactory(rules),
126126
transformer: issuesTransformerFactory(rules),
127-
filter: filterFactory(rules)
128-
}
127+
filter: filterFactory(rules),
128+
},
129129
];
130130

131131
return [...questions, ...footerQuestions];

src/prompts/scope-maker.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('scopeMaker', () => {
1414
['foo', { 'scope-case': [Level.Error, 'always', 'lower-case'] }, true],
1515
['foo', { 'scope-case': [Level.Error, 'always', 'upper-case'] }, 'Scope must be in upper-case'],
1616
['foo', { 'scope-case': [Level.Error, 'never', 'lower-case'] }, 'Scope must not be in lower-case'],
17-
['foo', { 'scope-case': [Level.Error, 'never', 'upper-case'] }, true]
17+
['foo', { 'scope-case': [Level.Error, 'never', 'upper-case'] }, true],
1818
])('value: %s, rule: %o, expected: %s', (value, rules, expected) => {
1919
const fixture = validatorFactory(rules);
2020

@@ -61,16 +61,16 @@ describe('scopeMaker', () => {
6161
expect(scopeConfig.choices).toEqual([
6262
{
6363
name: 'foo',
64-
value: 'foo'
64+
value: 'foo',
6565
},
6666
{
6767
name: 'bar',
68-
value: 'bar'
68+
value: 'bar',
6969
},
7070
{
7171
name: ':skip',
72-
value: ''
73-
}
72+
value: '',
73+
},
7474
]);
7575
}
7676
});
@@ -79,15 +79,15 @@ describe('scopeMaker', () => {
7979
describe('choicesFactory', () => {
8080
it('should not allow non-empty scope when empty scope is required', () => {
8181
const scopeConfig = choicesFactory({
82-
'scope-empty': [2, 'always', undefined]
82+
'scope-empty': [2, 'always', undefined],
8383
});
8484

8585
expect(scopeConfig).toEqual([{ name: ':skip', value: '' }]);
8686
});
8787

8888
it('should not allow skipping scope when is required', () => {
8989
const scopeConfig = choicesFactory({
90-
'scope-empty': [2, 'never', undefined]
90+
'scope-empty': [2, 'never', undefined],
9191
});
9292

9393
expect(scopeConfig).not.toContainEqual({ name: ':skip', value: '' });
@@ -96,7 +96,7 @@ describe('scopeMaker', () => {
9696

9797
it('should allow skipping scope when "scope-empty" severity is "warn"', () => {
9898
const scopeConfig = choicesFactory({
99-
'scope-empty': [1, 'always', undefined]
99+
'scope-empty': [1, 'always', undefined],
100100
});
101101

102102
expect(scopeConfig).toContainEqual({ name: ':skip', value: '' });
@@ -111,7 +111,7 @@ describe('scopeMaker', () => {
111111
describe('filterFactory', () => {
112112
test.each<[Rule<Case>, string, string]>([
113113
[[Level.Error, 'always', 'camel-case'], 'FOO_BAR', 'fooBar'],
114-
[[Level.Error, 'never', 'camel-case'], 'FOO_BAR', 'FOO_BAR']
114+
[[Level.Error, 'never', 'camel-case'], 'FOO_BAR', 'FOO_BAR'],
115115
])('should return case filtered string rule: %s, value: %s, expected: %s', (rule, value, expected) => {
116116
const rules = { 'scope-case': rule };
117117
const fixture = filterFactory(rules);

src/prompts/scope-maker.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ export function validatorFactory(rules: Rules) {
1212
value,
1313
rule: rules['scope-max-length'],
1414
validator: maxLengthValidator,
15-
message: length => `Scope maximum length of ${length} has been exceeded`
15+
message: (length) => `Scope maximum length of ${length} has been exceeded`,
1616
},
1717
{
1818
value,
1919
rule: rules['scope-min-length'],
2020
validator: minLengthValidator,
21-
message: length => `Scope minimum length of ${length} has not been met`
21+
message: (length) => `Scope minimum length of ${length} has not been met`,
2222
},
2323
{
2424
value,
2525
rule: rules['scope-empty'],
2626
validator: emptyValidator,
27-
message: () => 'Scope cannot be empty'
27+
message: () => 'Scope cannot be empty',
2828
},
2929
{
3030
value,
3131
rule: rules['scope-case'],
3232
validator: caseValidator,
33-
message: (ruleValue, applicable) => `Scope must ${applicable == 'never' ? 'not ' : ''}be in ${ruleValue}`
34-
}
33+
message: (ruleValue, applicable) => `Scope must ${applicable == 'never' ? 'not ' : ''}be in ${ruleValue}`,
34+
},
3535
]);
3636
};
3737
}
@@ -53,7 +53,7 @@ function parseEmptyScopeRule(rule: Rules['scope-empty']): [boolean, ChoiceOption
5353
function parseScopeEnumRule(rule: Rules['scope-enum']): [boolean, ChoiceOptions[] | undefined] {
5454
if (rule !== undefined) {
5555
const [, , scopeEnum] = rule;
56-
return [true, scopeEnum.map(scope => ({ name: scope, value: scope }))];
56+
return [true, scopeEnum.map((scope) => ({ name: scope, value: scope }))];
5757
}
5858
return [false, undefined];
5959
}
@@ -93,7 +93,7 @@ export function scopeMaker(questions: Question[], rules: Rules): Question[] {
9393
validate: validatorFactory(rules),
9494
filter: filterFactory(rules),
9595
choices,
96-
type: 'list'
96+
type: 'list',
9797
};
9898
} else {
9999
question = {
@@ -102,7 +102,7 @@ export function scopeMaker(questions: Question[], rules: Rules): Question[] {
102102
when,
103103
validate: validatorFactory(rules),
104104
filter: filterFactory(rules),
105-
type: 'input'
105+
type: 'input',
106106
};
107107
}
108108

0 commit comments

Comments
 (0)