Skip to content
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

feat!: replace mlh-tsd with tsd-lite #41

Merged
merged 19 commits into from
Feb 4, 2022
Merged
Prev Previous commit
Next Next commit
refactor formatter
mrazauskas committed Jan 14, 2022
commit 5127b361660169a1aa93ab77d564062662715283
8 changes: 4 additions & 4 deletions e2e/__snapshots__/errors.test.ts.snap
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@ exports[`throws if nearest tsconfig.json is not valid 1`] = `
Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node12', 'nodenext'.
> 3 | \\"module\\": \\"random\\",
| ^
at e2e/__fixtures__/errors-tsconfig/tsconfig.json:3:15
at e2e/__fixtures__/errors-tsconfig/tsconfig.json:3:15
Compiler option 'strict' requires a value of type boolean.
> 5 | \\"strict\\": \\"yes\\",
| ^
at e2e/__fixtures__/errors-tsconfig/tsconfig.json:5:15
at e2e/__fixtures__/errors-tsconfig/tsconfig.json:5:15
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
@@ -25,11 +25,11 @@ exports[`throws if syntax error is encountered 1`] = `
SyntaxError: ')' expected.
> 4 | expectError(one('foo', 'bar');
| ^
at e2e/__fixtures__/errors-syntax/index.test.ts:4:30
at e2e/__fixtures__/errors-syntax/index.test.ts:4:30
SyntaxError: ',' expected.
> 5 | expectError(one('foo' 'bar'));
| ^
at e2e/__fixtures__/errors-syntax/index.test.ts:5:23
at e2e/__fixtures__/errors-syntax/index.test.ts:5:23
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
29 changes: 16 additions & 13 deletions src/formatter.js
Original file line number Diff line number Diff line change
@@ -38,18 +38,18 @@ function getCodeFrameAndLocation(file, start) {
chalk.cyan(normalizeSlashes(relative('', file.fileName))) +
chalk.dim(':' + (line + 1) + ':' + (character + 1));

return { codeFrame, location };
return [codeFrame, indentEachLine(location, 1)].join('\n\n');
}

module.exports.formatTsdErrors = tsdErrors => {
const messages = tsdErrors.map(error => {
if (error.file) {
const { codeFrame, location } = getCodeFrameAndLocation(
const codeFrameAndLocation = getCodeFrameAndLocation(
error.file,
error.start
);

return [error.message, codeFrame, location].join('\n\n');
return [error.message, codeFrameAndLocation].join('\n\n');
}

return error.message;
@@ -62,16 +62,19 @@ module.exports.formatTsdResults = tsdResults => {
const title = chalk.bold.red(makeTitle('tsd typecheck'));

const messages = tsdResults.map(result => {
const { codeFrame, location } = getCodeFrameAndLocation(
result.file,
result.start
);

return [
indentEachLine(result.message, 2),
indentEachLine(codeFrame, 2),
indentEachLine(location, 3),
].join('\n\n');
if (result.file) {
const codeFrameAndLocation = getCodeFrameAndLocation(
result.file,
result.start
);

return [
indentEachLine(result.message, 2),
indentEachLine(codeFrameAndLocation, 2),
].join('\n\n');
}

return indentEachLine(result.message, 2);
});

return [title, messages.join('\n\n'), ''].join('\n');