Skip to content

Commit 084c496

Browse files
authored
Do not warn for markdown code blocks (#232)
Closes #222 This will stop throwing error messages for un-parsable code blocks in markdown (and mdx) files. This isn't ideal, but it matches the behavior of Prettier itself. See #222 (comment) for some discussion.
1 parent 299ae65 commit 084c496

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/preprocessors/preprocessor.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ export function preprocessor(
4343
try {
4444
ast = babelParser(parseableCode ?? originalCode, parserOptions);
4545
} catch (err) {
46-
console.error(
47-
' [error] [prettier-plugin-sort-imports]: import sorting aborted due to parsing error:\n%s',
48-
err,
49-
);
46+
// Don't throw warning messages if this is a codeblock in markdown. (Prettier doesn't either)
47+
if (
48+
options.parentParser !== 'markdown' &&
49+
options.parentParser !== 'mdx'
50+
) {
51+
console.error(
52+
' [error] [prettier-plugin-sort-imports]: import sorting aborted due to parsing error:\n%s',
53+
err,
54+
);
55+
}
5056
return originalCode;
5157
}
5258

0 commit comments

Comments
 (0)