@nx/eslint plugin - add option to write results to a file and pretty-print to console #30430
jeremyhofer
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
As part of running our tasks in CI via Nx Cloud we have the desire to not only pretty print the lint results in the console for devs to read / triage / fix issues, but also to save results to a file for external analysis of applied lint rules, configured overrides, ignores, etc. for tech-debt tracking and investment.
Relevant executor logic:
nx/packages/eslint/src/executors/lint/lint.impl.ts
Lines 182 to 195 in 2a0d89d
Current State
Today the @nx/eslint lint executor allows for the
format
of the output to be specified and anoutputFile
to save the output in to be specified. See docs for specifics: https://nx.dev/nx-api/eslint/executors/lintDesired State
I would like to be able to configure the lint executor to write to an
outputFile
with a given format (e.g.json
) while also outputting to the console with a given format (e.g. the defaultstylish
format).Considering the formats available, it may be helpful to allow configuring multiple different output file formats as part of a single lint execution, such as writing a
json
file for programmatic consumption and ahtml
file for a more user-friendly and accessible view than CLI text output.Considered Approaches
Different Targets
I considered adding a separate e.g.
lint-with-output-file
target onto our projects in order to allow for us to run alint
target that pretty prints to the console, as is BAU today, and have this other target that would output data injson
format to a file.The issue with this approach is that it would require running eslint twice per-project, as the lint results of the lint would be cached based on the target, not the actual lint invocation. Ideally eslint itself would only have to be executed once, and its results output in different formats as desired.
Output a json file and post-process into other forms
The
json
formatter for eslint simply writes the eslint output (which is already json) to a file. Given this a custom executor that wraps the @nx/eslint lint executor could be developed to orchestrate the logic around running eslint, generating the json output, then post-processing it into other formats and outputting to additional files as necessary.This approach is very flexible, but this could easily be integrated with the existing lint executor instead of requiring Nx users to introduce custom executors and custom logic to solve this.
Beta Was this translation helpful? Give feedback.
All reactions