Skip to main content

Formatters

ESLint formatters control the appearance of linting results in the CLI. ESLint comes with several built-in formatters and supports third-party formatters as well.

Using Formatters

Specify a formatter using the --format or -f flag:
npx eslint --format <formatter-name> file.js
npx eslint -f <formatter-name> file.js
The default formatter is stylish, which provides human-readable output with colors.

Built-in Formatters

ESLint includes four built-in formatters:

stylish

Default formatterHuman-readable with colors and context

json

JSON outputFor programmatic processing

json-with-metadata

JSON + metadataIncludes rule metadata

html

HTML reportVisual browser-based report

stylish (Default)

The stylish formatter provides clean, readable output with color coding:
npx eslint --format stylish file.js
file.js
  1:10  error    'addOne' is defined but never used  no-unused-vars
  2:9   error    Use the isNaN function to compare   use-isnan
  3:16  error    Unexpected space before unary       space-unary-ops
  3:20  warning  Missing semicolon                   semi
  5:7   error    Function 'addOne' expected return  consistent-return

✖ 5 problems (4 errors, 1 warning)
  1 error and 1 warning potentially fixable with the `--fix` option.
Colors can be controlled with --color and --no-color flags, or via environment variables like FORCE_COLOR, NO_COLOR, or NODE_DISABLE_COLORS.

json

Outputs JSON-serialized results for programmatic processing:
npx eslint --format json file.js
[
  {
    "filePath": "/path/to/file.js",
    "messages": [
      {
        "ruleId": "no-unused-vars",
        "severity": 2,
        "message": "'addOne' is defined but never used.",
        "line": 1,
        "column": 10,
        "messageId": "unusedVar",
        "endLine": 1,
        "endColumn": 16,
        "suggestions": []
      }
    ],
    "suppressedMessages": [],
    "errorCount": 5,
    "fatalErrorCount": 0,
    "warningCount": 4,
    "fixableErrorCount": 1,
    "fixableWarningCount": 4,
    "source": "function addOne(i) {...}"
  }
]
Use the JSON formatter when:
  • Building CI/CD integrations
  • Creating custom reporting tools
  • Processing results programmatically
  • Storing results in databases

json-with-metadata

Extends the JSON formatter with rule metadata:
npx eslint --format json-with-metadata file.js
{
  "results": [
    {
      "filePath": "/path/to/file.js",
      "messages": [...],
      "errorCount": 5,
      "warningCount": 4
    }
  ],
  "metadata": {
    "cwd": "/path/to/project",
    "rulesMeta": {
      "no-unused-vars": {
        "type": "problem",
        "docs": {
          "description": "Disallow unused variables",
          "recommended": true,
          "url": "https://eslint.org/docs/rules/no-unused-vars"
        },
        "hasSuggestions": true,
        "schema": [...]
      }
    }
  }
}

html

Generates an interactive HTML report:
npx eslint --format html file.js > report.html
Interactive HTML report with:
  • Color-coded violations
  • Sortable columns
  • Filterable results
  • File grouping
  • Rule descriptions
  • Click-to-expand details
  • Summary statistics
  • Professional styling
The HTML formatter is designed for viewing in a browser and includes all necessary CSS and JavaScript inline.

Saving Output to File

# Save JSON results
npx eslint --format json file.js > results.json

# Save HTML report
npx eslint --format html src/ > report.html

# Append to existing file
npx eslint --format json file.js >> all-results.json

Custom Formatters

You can create and use custom formatters:

Local Custom Formatter

1

Create formatter file

my-formatter.js
module.exports = function(results, context) {
  // results: array of linting results
  // context: formatter context object
  
  let output = "";
  let totalErrors = 0;
  let totalWarnings = 0;
  
  results.forEach(result => {
    const { filePath, messages } = result;
    
    if (messages.length > 0) {
      output += `\n${filePath}\n`;
      
      messages.forEach(message => {
        const { line, column, severity, message: msg, ruleId } = message;
        const type = severity === 2 ? "ERROR" : "WARNING";
        
        output += `  ${line}:${column} ${type} ${msg} (${ruleId})\n`;
        
        if (severity === 2) totalErrors++;
        else totalWarnings++;
      });
    }
  });
  
  output += `\n${totalErrors} errors, ${totalWarnings} warnings\n`;
  
  return output;
};
2

Use the formatter

npx eslint --format ./my-formatter.js file.js

NPM Package Formatter

1

Install formatter

npm install --save-dev eslint-formatter-pretty
# or
npm install --save-dev eslint-formatter-table
2

Use the formatter

# With prefix
npx eslint --format eslint-formatter-pretty file.js

# Without prefix (ESLint adds it)
npx eslint --format pretty file.js
ESLint automatically adds the eslint-formatter- prefix if not present.

Formatter Context

Formatters receive two arguments:
module.exports = function(results, context) {
  // results: array of linting results
  // context: formatter context
};

Results Array

[
  {
    filePath: "/absolute/path/to/file.js",
    messages: [
      {
        ruleId: "no-unused-vars",
        severity: 2,  // 1 = warn, 2 = error
        message: "'x' is defined but never used.",
        line: 1,
        column: 5,
        nodeType: "Identifier",
        messageId: "unusedVar",
        endLine: 1,
        endColumn: 6,
        fix: {  // Only if fixable
          range: [0, 10],
          text: ""
        },
        suggestions: [  // Only if has suggestions
          {
            desc: "Remove unused variable",
            fix: { range: [0, 10], text: "" }
          }
        ]
      }
    ],
    suppressedMessages: [],  // Suppressed violations
    errorCount: 1,
    fatalErrorCount: 0,
    warningCount: 0,
    fixableErrorCount: 1,
    fixableWarningCount: 0,
    source: "const x = 5;\n",  // File source code
    usedDeprecatedRules: []  // Deprecated rules used
  }
]

Context Object

{
  cwd: "/absolute/path/to/project",
  maxWarningsExceeded: {
    maxWarnings: 10,
    foundWarnings: 15
  },
  rulesMeta: {  // Only in json-with-metadata
    "no-unused-vars": {
      type: "problem",
      docs: { /* ... */ },
      hasSuggestions: true
    }
  }
}

Comparing Formatters

Best: stylish
npx eslint --format stylish src/
  • Human-readable
  • Color-coded
  • Quick scan of issues
  • Shows line numbers
Beautiful formatter with colors and context:
npm install --save-dev eslint-formatter-pretty
npx eslint --format pretty src/
Features:
  • Syntax highlighting
  • Code context
  • File hyperlinks (VS Code, WebStorm)
  • Summary statistics
Table-based output:
npm install --save-dev eslint-formatter-table
npx eslint --format table src/
Features:
  • Tabular layout
  • Column alignment
  • Clear separation
  • Sortable data
GitLab Code Quality format:
npm install --save-dev eslint-formatter-gitlab
npx eslint --format gitlab src/ > gl-code-quality-report.json
Use for:
  • GitLab CI/CD integration
  • Code Quality widgets
  • Merge request reports
Shows code context with pointers:
npm install --save-dev eslint-formatter-codeframe
npx eslint --format codeframe src/
Features:
  • Code snippets
  • Error pointers
  • Detailed context
  • Multiple lines

Example Workflow

# Quick checks during development
npx eslint src/

# Or with watch mode
npx eslint-watch src/

Best Practices

  • Development: stylish for readability
  • CI/CD: json for processing
  • Reports: html for stakeholders
  • Analysis: json-with-metadata for tooling
# Save to file for later review
npx eslint --format json src/ > results-$(date +%Y%m%d).json

# Archive HTML reports
npx eslint --format html src/ > reports/week-$(date +%U).html
Output to console AND file:
# Using tee (Unix)
npx eslint --format json src/ | tee results.json

# Or run twice
npx eslint src/ && npx eslint --format json src/ > results.json
# Only show errors
npx eslint --quiet src/

# Then check warnings separately
npx eslint src/

Command Line

CLI options including —format

Integrations

Editor and build tool integrations

Configuration

Configure ESLint for your project

Core Concepts

Understanding ESLint fundamentals