ESLint JSON Relative Formatter
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript maintenance
A formatter for ESLint that outputs linting results in JSON format, but replaces all absolute file paths with paths relative to the current working directory. Version 0.1.0 is the latest stable release. This package is a thin wrapper around ESLint's built-in JSON formatter, with no active development or updates expected. It is designed to produce portable output that can be consumed by tools in CI or other environments where absolute paths may differ. Alternatives include using the native JSON formatter with a post-processing step.
Common errors
error Cannot find module 'eslint-formatter-json-relative' ↓
cause The package is not installed or is not in the current working directory's node_modules.
fix
Run
npm install eslint-formatter-json-relative --save-dev in the project root. error Error: Formatter 'json-relative' not found ↓
cause ESLint cannot resolve the formatter name. The package name must be 'eslint-formatter-json-relative' when installed from npm, but the -f argument uses the short name 'json-relative'.
fix
Use
eslint -f json-relative after installing the package correctly. error TypeError: formatter is not a function ↓
cause Attempting to import the default export incorrectly, e.g., using a named import or importing from the wrong path.
fix
Use
import formatter from 'eslint-formatter-json-relative' (default import) and ensure the package is installed. Warnings
gotcha The formatter only replaces absolute paths with relative ones; all other JSON structure is identical to the built-in JSON formatter. ↓
fix No action needed; this is expected behavior.
gotcha The package is ESM-only; using require() may fail in some Node.js versions or configurations. ↓
fix Use import instead of require, or ensure your project is set up for ESM.
deprecated No updates since initial release; consider using ESLint's built-in JSON formatter and processing paths yourself. ↓
fix Use --format json with a post-processing script to convert absolute paths to relative.
Install
npm install eslint-formatter-json-relative yarn add eslint-formatter-json-relative pnpm add eslint-formatter-json-relative Imports
- default wrong
const formatter = require('eslint-formatter-json-relative')correctimport formatter from 'eslint-formatter-json-relative' - formatter (CommonJS) wrong
import formatter from 'eslint-formatter-json-relative'correctconst formatter = require('eslint-formatter-json-relative') - default (with type assertion) wrong
import formatter from 'eslint-formatter-json-relative'; // missing type import for Linter.Formattercorrectimport type { Linter } from 'eslint'; import formatter from 'eslint-formatter-json-relative';
Quickstart
// Install: npm i eslint-formatter-json-relative --save-dev
// Use via ESLint CLI:
eslint -f json-relative ./src
// Or programmatically in an ESLint plugin or script:
import formatter from 'eslint-formatter-json-relative';
import { ESLint } from 'eslint';
const eslint = new ESLint();
const results = await eslint.lintFiles(['./src']);
const output = formatter(results);
console.log(output);