Skip to content

chore: consider ts files when formatting #690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @commitlint/ensure/src/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,4 @@ test('true for numeric on lowercase', () => {
test('throw TypeError for invalid case name', () => {
const actualFn = () => ensure('anything', 'someweirdcase' as any);
expect(actualFn).toThrowError(TypeError);
});
});
19 changes: 17 additions & 2 deletions @commitlint/ensure/src/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ import * as _ from 'lodash';

export default ensureCase;

type TargetCaseType = 'camel-case' | 'kebab-case' | 'snake-case' | 'pascal-case' | 'start-case' | 'upper-case' | 'uppercase' | 'sentence-case' | 'sentencecase' | 'lower-case' | 'lowercase' | 'lowerCase';
type TargetCaseType =
| 'camel-case'
| 'kebab-case'
| 'snake-case'
| 'pascal-case'
| 'start-case'
| 'upper-case'
| 'uppercase'
| 'sentence-case'
| 'sentencecase'
| 'lower-case'
| 'lowercase'
| 'lowerCase';

function ensureCase(raw: string = '', target: TargetCaseType = 'lowercase'): boolean {
function ensureCase(
raw: string = '',
target: TargetCaseType = 'lowercase'
): boolean {
// We delete any content together with quotes because he can contains proper names (example `refactor: `Eslint` configuration`).
// We need trim string because content with quotes can be at the beginning or end of a line
const input = String(raw)
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/ensure/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import globby from 'globby';
import { camelCase, values } from 'lodash';
import {camelCase, values} from 'lodash';
import * as ensure from '.';

test('exports all checkers', async () => {
Expand Down
3 changes: 2 additions & 1 deletion @commitlint/ensure/src/max-length.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default (value: string, max: number): boolean => typeof value === 'string' && value.length <= max;
export default (value: string, max: number): boolean =>
typeof value === 'string' && value.length <= max;
3 changes: 2 additions & 1 deletion @commitlint/ensure/src/min-length.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default (value: string, min: number): boolean => typeof value === 'string' && value.length >= min;
export default (value: string, min: number): boolean =>
typeof value === 'string' && value.length >= min;
3 changes: 2 additions & 1 deletion @commitlint/ensure/src/not-empty.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default (value: string): boolean => typeof value === 'string' && value.length > 0;
export default (value: string): boolean =>
typeof value === 'string' && value.length > 0;
2 changes: 1 addition & 1 deletion @commitlint/execute-rule/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./lib";
export * from './lib';
14 changes: 7 additions & 7 deletions @commitlint/execute-rule/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ type ExecutedRule<T> = readonly [string, T];

export default execute;

export async function execute<T = unknown>(rule: Rule<T>): Promise<ExecutedRule<T> | null> {
export async function execute<T = unknown>(
rule: Rule<T>
): Promise<ExecutedRule<T> | null> {
if (!Array.isArray(rule)) {
return null;
}

const [name, config] = rule;

const fn = executable(config)
? config
: async () => config;

const fn = executable(config) ? config : async () => config;

return [name, await fn()];
};
}

function executable<T>(config: Config<T>): config is ExectableConfig<T> {
return typeof config === 'function';
}
}
2 changes: 1 addition & 1 deletion @commitlint/format/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./lib";
export * from './lib';
122 changes: 67 additions & 55 deletions @commitlint/format/src/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ test('does nothing without .errors and .warnings', () => {
});

test('returns empty summary if verbose', () => {
const actual = format({
results: [
{
errors: [],
warnings: []
}
]
}, {
verbose: true
});
const actual = format(
{
results: [
{
errors: [],
warnings: []
}
]
},
{
verbose: true
}
);

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

test('format result prints help for errors', () => {
const actual = formatResult({
errors: [
{
level: 2,
name: 'error-name',
message: 'There was an error'
}
]
}, {
helpUrl: 'https://example.com'
});
const actual = formatResult(
{
errors: [
{
level: 2,
name: 'error-name',
message: 'There was an error'
}
]
},
{
helpUrl: 'https://example.com'
}
);

expect(actual).toEqual(expect.arrayContaining([
expect.stringContaining('Get help:')
]));
expect(actual).toEqual(
expect.arrayContaining([expect.stringContaining('Get help:')])
);
});

test('format result prints help for warnings', () => {
const actual = formatResult({
warnings: [
{
level: 2,
name: 'warning-name',
message: 'There was a warning'
}
]
}, {
helpUrl: 'https://example.com'
});
const actual = formatResult(
{
warnings: [
{
level: 2,
name: 'warning-name',
message: 'There was a warning'
}
]
},
{
helpUrl: 'https://example.com'
}
);

expect(actual).toEqual(expect.arrayContaining([
expect.stringContaining('Get help:')
]));
expect(actual).toEqual(
expect.arrayContaining([expect.stringContaining('Get help:')])
);
});

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

const actual = formatResult({
warnings: [
{
level: 2,
name: 'warning-name',
message: 'There was a warning'
}
]
}, {
helpUrl
});
const actual = formatResult(
{
warnings: [
{
level: 2,
name: 'warning-name',
message: 'There was a warning'
}
]
},
{
helpUrl
}
);

expect(actual).toEqual(expect.arrayContaining([
expect.stringContaining(helpUrl)
]));
expect(actual).toEqual(
expect.arrayContaining([expect.stringContaining(helpUrl)])
);
});

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

expect(actual).not.toEqual(expect.arrayContaining([
expect.stringContaining('Get help:')
]));
expect(actual).not.toEqual(
expect.arrayContaining([expect.stringContaining('Get help:')])
);
});
5 changes: 4 additions & 1 deletion @commitlint/format/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export function format(
return results
.filter(r => Array.isArray(r.warnings) || Array.isArray(r.errors))
.map(result => [...fi(result), ...fr(result)])
.reduce((acc, item) => Array.isArray(item) ? [...acc, ...item] : [...acc, item], [])
.reduce(
(acc, item) => (Array.isArray(item) ? [...acc, ...item] : [...acc, item]),
[]
)
.join('\n');
}

Expand Down
2 changes: 1 addition & 1 deletion @commitlint/format/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './format';
export {default} from './format';
export * from './format';
Loading