Is there a way to list all active ESLint / Prettier rules in an Angular project?
Asked Answered
C

2

71

Background:

I'm trying to config ESLint and Prettier using .eslintrc.js and .prettierrc.js by starting with some extends like:

  • eslint:recommended
  • plugin:@typescript-eslint/recommended
  • prettier/@typescript-eslint
  • plugin:prettier/recommended
  • plugin:@angular-eslint/recommended

However these may contain conflicting rules or options / rules I find annoying.


Question:

Is there a script, an IDE plugin (our team uses WebStorm and VS Code) or a standalone tool which will compile a list of effective options and rules based on my current config?


It should ideally list all rules which are actually applied including imported rule sets. For each rule it should show its current setting (maybe even the default and other options) and its origin (rule set, config file). If a rule has been overwritten or has conflicting settings from two ore more imported rule sets it should show that too.

I imagine something similar to an effective Maven POM or a Maven dependencies tree either as a printed output or a GUI tool window.

I looked at https://www.npmjs.com/package/eslint-find-rules which is a start. However so far I only got a list of rules with no info where they come from or what their current setting is.

Motivation:

We are looking for a way to determine which rule set(s) to use as a starting point and which rules we want to overwrite without having to blindly try for ages.

Culpable answered 7/9, 2020 at 10:3 Comment(0)
M
113

The eslint --print-config file.js command should be able to list all the rules with their values applied to a specific file. However, it will not show in which plugin the rule was enabled.

Mirabel answered 9/9, 2020 at 9:41 Comment(3)
usually these config files are really long if you use multiple plugins and/or extends. If that is the case you output that to a text file by simply updating it like this eslint --print-config file.js > eslintconifg.txtLeonialeonid
@Leonialeonid Even better: the output is in JSON, so if you use the .json file extension, your operating system will allow you to easily open the with the appropriate handler app from JSON files (most likely a code editor), and a code editor like VS Code will pretty-print the JSON with indentation/syntax coloring/etc: eslint --print-config file.js > eslintconifg.jsonAlejandrinaalejandro
eslint --print-config file.js There is no eslint command on Windows OS even if I have ESLint extension inside VS code.Hibbard
O
2

ritikaadit2 brought up an issue on Jul 31 at 21:26 (see below) and have a solution for it:

eslint --print-config file.js There is no eslint command on Windows OS even if I have ESLint extension inside VS code.

My solution, which should work on Mac, Windows, or Linux if you have Node.js and npm installed:

  1. Install the eslint npm package in your project's root directory as a dev dependency:
    npm i -D eslint
  2. Then run a command like below (still in your project's root directory) to print out a file named eslint-custom-config.json that will should all your ESLint rules:
    npx eslint --print-config file.js > eslint-custom-conifg.json
  3. If needed add eslint-custom-conifg.json on a separate line to your .gitignore file to ensure this file isn't tracked by git
Objectivity answered 15/8, 2023 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.