node.jscommand-line-interfaceeslint

ESLint output to file and console at the same time


By default ESLint will print it's results to standard output. If you add the output option, it will redirect the output to a file. So far so good, but is there a way for it to do both?

We need the file output for GitLab to parse the results and display them in the UI, but some of our developers can't be bothered to change the way they do things and want to look at the output instead.

Is there an out-of-the-box way to get both or is my only chance to write my own script for running ESLint using the CLIEngine Node stuff mentioned in their documentation?

Thanks in advance.


Solution

  • So, after some research I think I found the answer myself.

    There's basically 2 ways to have output on both console and file at the same time:

    1. The easy way is by using this JavaScript package called ESLint Output.
    2. The more complicated way is basically building said package yourself. You have to create a JavaScript file which you will run instead of ESLint and import/require ESLint in that file. By importing ESLint as a package instead of running it directly you can then run ESLint using Node's CLIEngine on your files to be linted and store the output in a variable. That output can then be saved to a file and printed again.

    Hopefully, to no one's surprise, the methodology described in Option 2 is exactly what the package in Option 1 does: wrapping option 2 in an easy to understand config file and gathering all the configuration from the default eslintrc file for you.