1313 * @typedef {import('prettier').FileInfoOptions } FileInfoOptions
1414 * @typedef {import('prettier').Options } PrettierOptions
1515 * @typedef {PrettierOptions & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean } } Options
16+ * @typedef {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string } PrettierFormat
1617 */
1718
1819'use strict' ;
@@ -39,7 +40,7 @@ const { INSERT, DELETE, REPLACE } = generateDifferences;
3940
4041// Lazily-loaded Prettier.
4142/**
42- * @type {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string }
43+ * @type {PrettierFormat }
4344 */
4445let prettierFormat ;
4546
@@ -160,11 +161,11 @@ const eslintPluginPrettier = {
160161 const source = sourceCode . text ;
161162
162163 return {
163- Program ( ) {
164+ Program ( node ) {
164165 if ( ! prettierFormat ) {
165166 // Prettier is expensive to load, so only load it if needed.
166- prettierFormat = require ( 'synckit' ) . createSyncFn (
167- require . resolve ( './worker' ) ,
167+ prettierFormat = /** @type { PrettierFormat } */ (
168+ require ( 'synckit' ) . createSyncFn ( require . resolve ( './worker' ) )
168169 ) ;
169170 }
170171
@@ -213,7 +214,7 @@ const eslintPluginPrettier = {
213214 let message = 'Parsing error: ' + err . message ;
214215
215216 const error =
216- /** @type {SyntaxError & {codeFrame: string; loc: SourceLocation} } */ (
217+ /** @type {SyntaxError & {codeFrame: string; loc? : SourceLocation} } */ (
217218 err
218219 ) ;
219220
@@ -226,10 +227,11 @@ const eslintPluginPrettier = {
226227 }
227228 if ( error . loc ) {
228229 message = message . replace ( / \( \d + : \d + \) $ / , '' ) ;
230+ context . report ( { message, loc : error . loc } ) ;
231+ } else {
232+ context . report ( { message, node } ) ;
229233 }
230234
231- context . report ( { message, loc : error . loc } ) ;
232-
233235 return ;
234236 }
235237
0 commit comments