Skip to content

Commit

Permalink
Output comment prefix in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeSidSmith committed Mar 8, 2020
1 parent 0b58720 commit 65213ed
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as logger from './logger';
import { indent, isTruthyString } from './utils';
import { version } from './version';

const COMMENT_PREFIX = '@tsassert';
const MATCHES_GLOB = /(?:}|\)|\*+\/?|\.[t]sx?)$/;
const MATCHES_LONELY_COMMENT = /^\s*?\/\/\s?@tsassert(?::|\s)\s*(.+?)\s*?$/;
const MATCHES_TRAILING_COMMENT = /\/\/\s?@tsassert(?::|\s)\s*(.+?)\s*?$/;
Expand All @@ -25,7 +26,7 @@ const assert = (tree: Tree) => {
return version();
}

logger.log('\nChecking type assertion comments...\n');
logger.log(`\nChecking ${COMMENT_PREFIX} comments...\n`);

const cwd = process.cwd();

Expand Down Expand Up @@ -149,7 +150,9 @@ const assert = (tree: Tree) => {

if (lonelyResult) {
if (result) {
errors.push(`${fileLine}Found 2 type comments for the same line`);
errors.push(
`${fileLine}Found 2 ${COMMENT_PREFIX} comments for the same line`
);
return;
} else {
result = lonelyResult;
Expand All @@ -171,7 +174,7 @@ const assert = (tree: Tree) => {
const type = checker.typeToString(typeNode);

if (type !== comment) {
const message = `${fileLine}Type of "${variableName}" did not match type comment:`;
const message = `${fileLine}Type of "${variableName}" did not match ${COMMENT_PREFIX} comment:`;

errors.push({
message,
Expand All @@ -192,7 +195,7 @@ const assert = (tree: Tree) => {
);

if (type !== comment) {
const message = `${fileLine}Return type of "${functionName}" did not match type comment:`;
const message = `${fileLine}Return type of "${functionName}" did not match ${COMMENT_PREFIX} comment:`;

errors.push({
message,
Expand Down Expand Up @@ -251,18 +254,21 @@ const assert = (tree: Tree) => {
}
});

return logger.error('\nSome files failed tsassert checks.\n', true);
return logger.error(
`\nSome files failed ${COMMENT_PREFIX} checks.\n`,
true
);
} else {
if (!filesChecked) {
logger.warn(
'\nCould not find any matching files to check.\nRun with --verbose to see patterns that were checked.\n'
);
} else if (!commentsChecked) {
logger.warn(
'\nCould not find any type assertions in matched files.\nRun with --verbose to see patterns that were checked.\n'
`\nCould not find any ${COMMENT_PREFIX} comments in matched files.\nRun with --verbose to see patterns that were checked.\n`
);
} else {
logger.success('\nAll files passed tsassert checks.\n');
logger.success(`\nAll files passed ${COMMENT_PREFIX} checks.\n`);
}
}
};
Expand Down

0 comments on commit 65213ed

Please sign in to comment.