Skip to content

Commit

Permalink
style(lint): lint files
Browse files Browse the repository at this point in the history
lint all files by executing 'lint' npm script
  • Loading branch information
xeptore committed Mar 31, 2021
1 parent ff051f3 commit f040981
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 150 deletions.
16 changes: 13 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier", "import", "unicorn"],
"plugins": [
"@typescript-eslint",
"prettier",
"import",
"unicorn"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
Expand All @@ -31,13 +36,18 @@
},
"overrides": [
{
"files": ["*.test.ts"],
"files": [
"*.test.ts"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}
],
"settings": {
"import/extensions": [".ts", ".js"]
"import/extensions": [
".ts",
".js"
]
}
}
4 changes: 2 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'scope-enum': [2, 'always', ['deps']]
}
'scope-enum': [2, 'always', ['deps']],
},
};
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts']
collectCoverageFrom: ['src/**/*.ts'],
};
6 changes: 3 additions & 3 deletions src/commit-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('commit-template', () => {
test.each<[Answers, string]>([
[{ type: 'foo', scope: 'bar', subject: 'baz' }, 'foo(bar): baz'],
[{ type: 'foo' }, 'foo: '],
[{ type: 'foo', subject: 'bar' }, 'foo: bar']
[{ type: 'foo', subject: 'bar' }, 'foo: bar'],
])(`should convert answers %o to template '%s'`, (answers, expected) => {
const result = headerTemplate(answers.type, answers.scope, answers.subject);

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

Expand Down
10 changes: 5 additions & 5 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { Question, commitTemplate } from './commit-template';
function buildQuestions(rules: Rules) {
const combinedQuestions = pipeWith<Question[]>(
[],
x => typeMaker(x, rules),
x => scopeMaker(x, rules),
x => subjectMaker(x, rules),
x => bodyMaker(x, rules),
x => footerMaker(x, rules)
(x) => typeMaker(x, rules),
(x) => scopeMaker(x, rules),
(x) => subjectMaker(x, rules),
(x) => bodyMaker(x, rules),
(x) => footerMaker(x, rules)
);

return combinedQuestions;
Expand Down
8 changes: 4 additions & 4 deletions src/prompts/body-maker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('body-maker', () => {
[{ 'body-max-length': [Level.Error, 'always', 3] }, 'too long', 'Body maximum length of 3 has been exceeded'],
[{ 'body-max-length': [Level.Error, 'always', 72] }, 'too long', true],
[{ 'body-min-length': [Level.Error, 'always', 3] }, 'f', 'Body minimum length of 3 has not been met'],
[{ 'body-min-length': [Level.Error, 'always', 3] }, 'foo bar baz', true]
[{ 'body-min-length': [Level.Error, 'always', 3] }, 'foo bar baz', true],
])(`should validate rule '%o', value '%s', expected '%s'`, (rules, value, expected) => {
const factory = validatorFactory(rules);

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

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

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

Expand Down
20 changes: 10 additions & 10 deletions src/prompts/body-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ export function validatorFactory(rules: Rules) {
value,
rule: rules['body-max-length'],
validator: maxLengthValidator,
message: length => `Body maximum length of ${length} has been exceeded`
message: (length) => `Body maximum length of ${length} has been exceeded`,
},
{
value,
rule: rules['body-min-length'],
validator: minLengthValidator,
message: length => `Body minimum length of ${length} has not been met`
}
message: (length) => `Body minimum length of ${length} has not been met`,
},
]);
}

export function filterFactory(rules: Rules) {
return (value: string) =>
pipeWith<string>(
value,
v => maxLineLengthFilter(v, rules['body-max-line-length']),
v => leadingBlankFilter(v, rules['body-leading-blank']),
v => v.replace(/\\n/g, '\n')
(v) => maxLineLengthFilter(v, rules['body-max-line-length']),
(v) => leadingBlankFilter(v, rules['body-leading-blank']),
(v) => v.replace(/\\n/g, '\n')
);
}

Expand All @@ -40,8 +40,8 @@ export function transformerFactory(rules: Rules) {
return (value: string) => {
return pipeWith(
value,
v => v.replace(/\\n/g, '\n'),
v => maxLenTransformer(v)
(v) => v.replace(/\\n/g, '\n'),
(v) => maxLenTransformer(v)
);
};
}
Expand All @@ -54,8 +54,8 @@ export function bodyMaker(questions: Question[], rules: Rules): Question[] {
message: 'Provide a longer description of the change: (press enter to skip, \\n for newline)\n',
validate: validatorFactory(rules),
filter: filterFactory(rules),
transformer: transformerFactory(rules)
}
transformer: transformerFactory(rules),
},
];

return [...questions, ...bodyQuestions];
Expand Down
28 changes: 14 additions & 14 deletions src/prompts/footer-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export function validatorFactory(rules: Rules) {
value: value + breaking,
rule: rules['footer-max-length'],
validator: maxLengthValidator,
message: length => `Footer maximum length of ${length} has been exceeded`
message: (length) => `Footer maximum length of ${length} has been exceeded`,
},
{
value: value + breaking,
rule: rules['footer-min-length'],
validator: minLengthValidator,
message: length => `Footer minimum length of ${length} has not been met`
}
message: (length) => `Footer minimum length of ${length} has not been met`,
},
]);
};
}
Expand All @@ -31,9 +31,9 @@ export function filterFactory(rules: Rules, prefix = '') {
return (value: string): string =>
pipeWith<string>(
value,
v => prefix + v,
v => leadingBlankFilter(v, rules['footer-leading-blank']),
v => maxLineLengthFilter(v, rules['footer-max-line-length'])
(v) => prefix + v,
(v) => leadingBlankFilter(v, rules['footer-leading-blank']),
(v) => maxLineLengthFilter(v, rules['footer-max-line-length'])
);
}

Expand Down Expand Up @@ -99,33 +99,33 @@ export function footerMaker(questions: Question[], rules: Rules): Question[] {
type: 'confirm',
name: 'isBreaking',
message: 'Are there any breaking changes?',
default: false
default: false,
},
{
type: 'input',
name: 'breaking',
message: breakingChangeMessageFactory(rules),
when: answers => !!answers.isBreaking,
when: (answers) => !!answers.isBreaking,
validate: validatorFactory(rules),
transformer: breakingTransformFactory(rules, BREAKING_CHANGE),
filter: filterFactory(rules, BREAKING_CHANGE)
filter: filterFactory(rules, BREAKING_CHANGE),
},
{
type: 'confirm',
name: 'isIssue',
message: 'Does this fix Does this change affect any open issues?',
when: answers => !isFixCommit(answers),
default: false
when: (answers) => !isFixCommit(answers),
default: false,
},
{
type: 'input',
name: 'issue',
message: issuesMessageFactory(rules),
when: answers => isFixCommit(answers) || !!answers.isIssue,
when: (answers) => isFixCommit(answers) || !!answers.isIssue,
validate: validatorFactory(rules),
transformer: issuesTransformerFactory(rules),
filter: filterFactory(rules)
}
filter: filterFactory(rules),
},
];

return [...questions, ...footerQuestions];
Expand Down
18 changes: 9 additions & 9 deletions src/prompts/scope-maker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('scopeMaker', () => {
['foo', { 'scope-case': [Level.Error, 'always', 'lower-case'] }, true],
['foo', { 'scope-case': [Level.Error, 'always', 'upper-case'] }, 'Scope must be in upper-case'],
['foo', { 'scope-case': [Level.Error, 'never', 'lower-case'] }, 'Scope must not be in lower-case'],
['foo', { 'scope-case': [Level.Error, 'never', 'upper-case'] }, true]
['foo', { 'scope-case': [Level.Error, 'never', 'upper-case'] }, true],
])('value: %s, rule: %o, expected: %s', (value, rules, expected) => {
const fixture = validatorFactory(rules);

Expand Down Expand Up @@ -61,16 +61,16 @@ describe('scopeMaker', () => {
expect(scopeConfig.choices).toEqual([
{
name: 'foo',
value: 'foo'
value: 'foo',
},
{
name: 'bar',
value: 'bar'
value: 'bar',
},
{
name: ':skip',
value: ''
}
value: '',
},
]);
}
});
Expand All @@ -79,15 +79,15 @@ describe('scopeMaker', () => {
describe('choicesFactory', () => {
it('should not allow non-empty scope when empty scope is required', () => {
const scopeConfig = choicesFactory({
'scope-empty': [2, 'always', undefined]
'scope-empty': [2, 'always', undefined],
});

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

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

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

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

expect(scopeConfig).toContainEqual({ name: ':skip', value: '' });
Expand All @@ -111,7 +111,7 @@ describe('scopeMaker', () => {
describe('filterFactory', () => {
test.each<[Rule<Case>, string, string]>([
[[Level.Error, 'always', 'camel-case'], 'FOO_BAR', 'fooBar'],
[[Level.Error, 'never', 'camel-case'], 'FOO_BAR', 'FOO_BAR']
[[Level.Error, 'never', 'camel-case'], 'FOO_BAR', 'FOO_BAR'],
])('should return case filtered string rule: %s, value: %s, expected: %s', (rule, value, expected) => {
const rules = { 'scope-case': rule };
const fixture = filterFactory(rules);
Expand Down
16 changes: 8 additions & 8 deletions src/prompts/scope-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ export function validatorFactory(rules: Rules) {
value,
rule: rules['scope-max-length'],
validator: maxLengthValidator,
message: length => `Scope maximum length of ${length} has been exceeded`
message: (length) => `Scope maximum length of ${length} has been exceeded`,
},
{
value,
rule: rules['scope-min-length'],
validator: minLengthValidator,
message: length => `Scope minimum length of ${length} has not been met`
message: (length) => `Scope minimum length of ${length} has not been met`,
},
{
value,
rule: rules['scope-empty'],
validator: emptyValidator,
message: () => 'Scope cannot be empty'
message: () => 'Scope cannot be empty',
},
{
value,
rule: rules['scope-case'],
validator: caseValidator,
message: (ruleValue, applicable) => `Scope must ${applicable == 'never' ? 'not ' : ''}be in ${ruleValue}`
}
message: (ruleValue, applicable) => `Scope must ${applicable == 'never' ? 'not ' : ''}be in ${ruleValue}`,
},
]);
};
}
Expand All @@ -53,7 +53,7 @@ function parseEmptyScopeRule(rule: Rules['scope-empty']): [boolean, ChoiceOption
function parseScopeEnumRule(rule: Rules['scope-enum']): [boolean, ChoiceOptions[] | undefined] {
if (rule !== undefined) {
const [, , scopeEnum] = rule;
return [true, scopeEnum.map(scope => ({ name: scope, value: scope }))];
return [true, scopeEnum.map((scope) => ({ name: scope, value: scope }))];
}
return [false, undefined];
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export function scopeMaker(questions: Question[], rules: Rules): Question[] {
validate: validatorFactory(rules),
filter: filterFactory(rules),
choices,
type: 'list'
type: 'list',
};
} else {
question = {
Expand All @@ -102,7 +102,7 @@ export function scopeMaker(questions: Question[], rules: Rules): Question[] {
when,
validate: validatorFactory(rules),
filter: filterFactory(rules),
type: 'input'
type: 'input',
};
}

Expand Down
Loading

0 comments on commit f040981

Please sign in to comment.