Skip to content

Commit

Permalink
Print warning for parsed object shorthand notation (#155)
Browse files Browse the repository at this point in the history
* Add test for issue 147

* Print warning for unhandled formatText
  • Loading branch information
Shinigami92 authored Nov 1, 2020
1 parent 601934d commit 0a76573
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ export class PugPrinter {
'[PugPrinter:formatText]: Missing expected ). If you are using Vue, you can ignore this message.',
`code: \`${code.trim()}\``
);
} else if (error.includes('Missing expected :')) {
logger.warn(
'[PugPrinter:formatText]: Missing expected :. If you are using Vue, you can ignore this message.',
`code: \`${code.trim()}\``
);
} else {
logger.warn('[PugPrinter:formatText]: ', error);
}
Expand Down
1 change: 1 addition & 0 deletions tests/issues/issue-147/formatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
span {{ $t(expanded ? 'panel_title_without_title' : 'panel_title', { index: index + 1, title }) }}
14 changes: 14 additions & 0 deletions tests/issues/issue-147/issue-147.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { format } from 'prettier';
import { plugin } from './../../../src/index';

describe('Issues', () => {
test('should ', () => {
const expected: string = readFileSync(resolve(__dirname, 'formatted.pug'), 'utf8');
const code: string = readFileSync(resolve(__dirname, 'unformatted.pug'), 'utf8');
const actual: string = format(code, { parser: 'pug', plugins: [plugin] });

expect(actual).toBe(expected);
});
});
1 change: 1 addition & 0 deletions tests/issues/issue-147/unformatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
span {{$t(expanded ? "panel_title_without_title" : "panel_title", {index: index + 1, title})}}

0 comments on commit 0a76573

Please sign in to comment.