Skip to content

Commit

Permalink
fix: report node when loc not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Jan 13, 2025
1 parent b307125 commit bda3879
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @typedef {import('prettier').FileInfoOptions} FileInfoOptions
* @typedef {import('prettier').Options} PrettierOptions
* @typedef {PrettierOptions & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean }} Options
* @typedef {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string} PrettierFormat
*/

'use strict';
Expand All @@ -39,7 +40,7 @@ const { INSERT, DELETE, REPLACE } = generateDifferences;

// Lazily-loaded Prettier.
/**
* @type {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string}
* @type {PrettierFormat}
*/
let prettierFormat;

Expand Down Expand Up @@ -160,11 +161,11 @@ const eslintPluginPrettier = {
const source = sourceCode.text;

return {
Program() {
Program(node) {
if (!prettierFormat) {
// Prettier is expensive to load, so only load it if needed.
prettierFormat = require('synckit').createSyncFn(
require.resolve('./worker'),
prettierFormat = /** @type {PrettierFormat} */ (
require('synckit').createSyncFn(require.resolve('./worker'))
);
}

Expand Down Expand Up @@ -226,9 +227,13 @@ const eslintPluginPrettier = {
}
if (error.loc) {
message = message.replace(/ \(\d+:\d+\)$/, '');

context.report({ message, loc: error.loc });

return;
}

context.report({ message, loc: error.loc });
context.report({ message, node });

return;
}
Expand Down

0 comments on commit bda3879

Please sign in to comment.