eslint-formatting-reporter

raw JSON →
0.0.0 verified Sat Apr 25 auth: no javascript

A utility library for ESLint plugins that report formatting differences between original and formatted code. Version 0.0.0, actively maintained by Anthony Fu. Extracted from eslint-plugin-prettier, it provides `reportDifferences` function and `messages` object to simplify creating custom formatting rules. Ships TypeScript types, peer dependency on ESLint >=8.40.0. Lightweight alternative to directly using prettier-linter-helpers.

error Cannot find module 'eslint-formatting-reporter'
cause Package not installed or incorrect import path.
fix
npm install eslint-formatting-reporter
error ERR_REQUIRE_ESM
cause Using require() for an ESM-only package.
fix
Change to import { reportDifferences } from 'eslint-formatting-reporter'
gotcha reportDifferences requires context.source.text. In older ESLint versions, use context.getSourceCode().getText().
fix Use context.source.text for ESLint 8.40+; for older versions, upgrade or pass source code manually.
gotcha Package is ESM-only. Using require() will fail with ERR_REQUIRE_ESM.
fix Use import syntax or dynamic import().
npm install eslint-formatting-reporter
yarn add eslint-formatting-reporter
pnpm add eslint-formatting-reporter

Creates a custom ESLint rule that reports formatting differences using reportDifferences.

import { messages, reportDifferences } from 'eslint-formatting-reporter';
import type { Rule } from 'eslint';

export default <Rule.RuleModule>{
  meta: {
    type: 'layout',
    fixable: 'whitespace',
    messages
  },
  create(context) {
    return {
      Program() {
        const source = context.source.text;
        const formatted = source.replace(/\s+$/, ''); // example formatter
        reportDifferences(context, source, formatted);
      }
    };
  }
};