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.
Common errors
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'
Warnings
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().
Install
npm install eslint-formatting-reporter yarn add eslint-formatting-reporter pnpm add eslint-formatting-reporter Imports
- reportDifferences wrong
const { reportDifferences } = require('eslint-formatting-reporter')correctimport { reportDifferences } from 'eslint-formatting-reporter' - messages
import { messages } from 'eslint-formatting-reporter' - Rule wrong
import { Rule } from 'eslint-formatting-reporter'correctimport type { Rule } from 'eslint'
Quickstart
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);
}
};
}
};