1

I am using create-react-app with craco (Create-React-App-Configuration-Override)

Craco is not very exotic. It simply allows me to use my own eslintrc file with create-react-app.

I am trying to use a custom eslint formatter, specifically eslint-formatter-friendly does what I need (link to files at line numbers via iTerm/Guake terminals), but there are plenty of alternative formatters: http://npmsearch.com/?q=eslint-formatter

I tried setting a format: 'unix' or formatter: 'unix' in my .eslintrc.js file - but this didn't work, eslint explicitly gave an error saying something like "unrecognized top-level property".

Devin Rhode
  • 23,026
  • 8
  • 58
  • 72

1 Answers1

0

I looked for any way I could specify formatter in the .eslintrc.js file, but I figured out that's not an option. After searching and scanning through the source for gulp-eslint, eslint-grunt and grunt-eslint, eventually I looked more closely at the source for for craco - where is reads a little eslint configuration: https://github.com/sharegate/craco/blob/master/recipes/use-an-eslintrc-config-file/craco.config.js

The source that processes this: https://github.com/sharegate/craco/blob/master/packages/craco/lib/features/webpack/eslint.js

All I needed to do was use this craco.config.js:

/* globals module */
const { ESLINT_MODES } = require("@craco/craco");
const reactHotReloadPlugin = require('craco-plugin-react-hot-reload');

module.exports = {
    plugins: [{
        plugin: reactHotReloadPlugin
    }],
    eslint: {
        mode: ESLINT_MODES.file,
        loaderOptions: {
            formatter: require("eslint-formatter-friendly")
        }
    },
};
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Devin Rhode
  • 23,026
  • 8
  • 58
  • 72
  • At the end of the day it seems like it is not possible to set a custom formatter via .eslintrc file. You have to set it command line or some tool needs to pass through an option to eslint's CLIEngine api: https://eslint.org/docs/developer-guide/nodejs-api#cliengine – Devin Rhode Aug 18 '19 at 19:13