prettier-linter-helpers

raw JSON →
1.0.1 verified Sat Apr 25 auth: no javascript maintenance

Utilities to help expose prettier output in linting tools. Version 1.0.1 provides two helper functions: showInvisibles and generateDifferences. Extracted from eslint-plugin-prettier v2.7.0, it is stable but rarely updated. Key differentiator: offers a shared, tested way to compute and display differences from prettier output, avoiding duplication across multiple linter integrations. Lightweight with no dependencies, but relies on prettier being installed separately.

error TypeError: (0 , prettier_linter_helpers.showInvisibles) is not a function
cause Using CommonJS require incorrectly with ES module bundlers like Webpack.
fix
Change to: import { showInvisibles } from 'prettier-linter-helpers'
error Module not found: Can't resolve 'prettier-linter-helpers'
cause Package not installed or not in node_modules.
fix
Run: npm install prettier-linter-helpers
error Cannot read property 'showInvisibles' of undefined
cause Attempting to access a named export as a property of the default export.
fix
Use named import: import { showInvisibles } from 'prettier-linter-helpers'
gotcha generateDifferences returns an array of difference objects that are not deeply immutable; do not mutate them.
fix Treat the returned differences as read-only; copy if modification needed.
deprecated Package is in maintenance mode; no new features are planned.
fix Consider directly using prettier's own diffing utilities if more advanced features are needed.
gotcha showInvisibles is intended for display purposes only; do not use it for programmatic string manipulation.
fix Use the original string for any logic; showInvisibles changes characters (e.g., space to ·).
npm install prettier-linter-helpers
yarn add prettier-linter-helpers
pnpm add prettier-linter-helpers

Imports the two helper functions, shows use of showInvisibles to make whitespace visible, and generateDifferences to compare two strings.

import { showInvisibles, generateDifferences } from 'prettier-linter-helpers';

const source = 'const x = 1;\n';
const prettierSource = 'const x = 1;\n';

// Show invisible characters (tab, space, newline)
const visible = showInvisibles(source);
console.log(visible);
// 'const x = 1;·\n'

// Generate differences between source and prettierSource
const diffs = generateDifferences(source, prettierSource);
console.log(diffs);
// []

// Example with a difference
const source2 = 'const x = 1';
const prettierSource2 = 'const x = 1;\n';
const diffs2 = generateDifferences(source2, prettierSource2);
console.log(diffs2);
// [ { offset: 11, operation: 'insert', insertText: ';\n' } ]