Lädt...

🔧 “Eslint-Summary” — Hack your Eslint Config


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Get full information about used rules and plugins in the eslint-config on the project with just one console command

Introduction

Not very often, but we need to understand what rules are used in our eslint-config on a project. There could be several reasons for this:

  • Control of third-party rules. It’s more profitable for developers to use pre-built style guides from other teams. For example, Google or Airbnb. However, keeping track of other people’s rules is extremely inconvenient, especially if the rules are actively being added and changed.

  • Familiarize team members with the current style guide. If your configuration consists of many plugins, you hardly want to force a person to manually familiarize themselves with each plugin, rule, and area of responsibility from the config.

  • Collecting feedback: Visual presentation and knowledge of the current rules help to collect and incorporate feedback from the team to further improve the ESLint configuration, making it more useful and convenient for everyone

  • Avoiding redundant checks: Understanding of the rules being used avoids redundant rules that can slow down development or complicate the current config

Example of problem

Let’s say you’re a newbie and your first working week has started. You’ve got all the accesses, downloaded the repositories, see the familiar file .eslintrc.json.

You open this file and see in it…

{
 "extends": "next/core-web-vitals"
}

sally mem

What information does this line give to you? — Nothing, except the name of the config. Ask yourself, “Are you willing to waste the time to find a plugin and familiarize yourself with its rules?” — I think not.

What’s the solution?

  • If eslint is familiar to you, you can call the command eslint --print-config ./.eslintrc.json. Calling the command will return a list of all the rules from the config as a long list in the console. But, unfortunately, you will have to search for each rule manually, understand its meaning and rationale, and correlate the current settings. This is extremely inconvenient if there are many rules.

  • You can try using the new solution “Eslint config inspector” — it is a visualization of the current config. The disadvantage of this solution is that it doesn’t support deep rule search along the inheritance chain. Also, it is not documentation, but an application.
    GitHub - eslint/config-inspector: A visual tool for inspecting and understanding your ESLint flat…

  • My solution is npm package @dolgikh-maks/eslint-summary

What is “Eslint-Summary”?

This is an npm-package to generate rules documentation for the current project, custom plugins, sub-projects, and other possible scenarios where eslint configs are used.

Its task is simple — to generate a markdown file on the current configuration for each plugin and the rules involved in it.

But not just to show that “there is such a rule”, but to provide all information about it, as if you were viewing the plugin’s page. You understand what the rule is for, whether it supports autofix, and what files it applies to.

Installation

All you need to do is specify the familiar command to install npm-packages

npm i --save-dev @dolgikh-maks/eslint-summary

Launch

If you are using the .eslintrc.js file as the base config, then no additional configuration is needed, and it is enough to call the command

eslint-summary

After running the command, you will have an eslint-summary-report directory with the .eslintrc.md file.

Report file

When you open the created .eslintrc.md you will be given summary tables for each plugin involved in the .eslintrc.js config.

Report for .eslintrc.js

The table has reserved columns:

  • Rule — name of the rule of an eslint plugin

  • Extension *.<extension> — column showing what settings the rule has for this or that extension file

The remaining columns are columns that display meta data from the rule

Custom Rule Tutorial - ESLint - Pluggable JavaScript Linter

The main feature

If you want to learn more about a rule, you don’t need to search for it manually through the search engine, just select the desired rule from the table.

The name of a rule already contains a direct link to its documentation

Configuration

The .eslint-summary.<js | json | ts | yaml> config file is used for easy configuration of the package. In it, you specify the necessary options for generating reports if you are not satisfied with the default settings of the package

extensions

default['js']

Specify the required file extensions to display the rule settings for each file type in the report.

This is a very convenient option if your project contains different file types, such as json or spec.js, and you want to know how rules work with these file extensions.

Important. Specifying any value will overwrite the current [js] setting. If you want to save the report for js-files, this extension must also be specified

/**
 * @type {import('@dolgikh-maks/eslint-summary').IConfig}
 */
module.exports = {
   extensions: [
       'json',
       'spec.js',
       'js'
   ],
};

output

defaulteslint-summary-report

Change the path of the report directory.

Supports nested directories. If such a directory does not exist at the moment of generation start — it will be created.

/**
 * @type {import('@dolgikh-maks/eslint-summary').IConfig}
 */
module.exports = {
   output: './docs/eslint-summary',
};

ignorePlugins

default[]

Exclude plugins from your report.

Sometimes other people’s configs contain the use of third-party plugins, but they don’t work with our code and its analysis. For example, eslint-config-prettier, which contains plugins for react, vue and flowtype.

/**
 * @type {import('@dolgikh-maks/eslint-summary').IConfig}
 */
module.exports = {
   ignorePlugins: ['eslint-plugin-vue', "eslint-plugin-flowtype"],
};

configs

default['./.eslintrc.js']

Specify eslint-configs for which you want to analyze and generate documentation.

If your eslint config file name is different from the standard one (.eslintrc.js), you can specify where and which file needs to be analyzed.

If you have several files or sub-projects with their configs, it is not a problem to specify paths to them

/**
 * @type {import('@dolgikh-maks/eslint-summary').IConfig}
 */
module.exports = {
    configs: [
        './example-apps/angular/.eslintrc.js',
        './example-apps/next/.eslintrc.json'
    ],
};

The generator will create a different report for each config, according to its name and location

example of reports

Example of usage

In my article on creating a team style guide, we got a way to create and scale @my-team/eslint-plugin

Create your code style for the team from scratch. Eslint, Prettier, Commitlint and etc.

scheme of eslint-plugin

What if we want to allow users of our plugin to see settings and configurations as documentation, similar to this structure?

example of reports

It’s pretty simple:

  • Install the package @dolgikh-maks/eslint-summary

  • Set the desired settings in .eslint-summary.js

/**
 * @type {import('@dolgikh-maks/eslint-summary').IConfig}
 */

module.exports = {
  extensions: [
    'ts',
    'html',
    'spec.ts',
  ],
  ignorePlugins: [
    'eslint-plugin-vue',
    'eslint-plugin-react',
    'eslint-plugin-flowtype',
  ],
  configs: [
    './configs/base.js',
    './configs/recommended.js',
    './configs/spec.js',
    './configs/strict.js',
    './plugins/rxjs/recommended.js',
    './plugins/prettier/index.js',
      // other paths  
  ],
  output: './docs',
};
  • Run the eslint-summary command

  • Get documentation for each configuration 🔥

Now, some users of your plugin can go to the /docs folder and see the current plugin settings.

For example plugins/prettier/index.md

report for prettier/index.js

You can find full example here

In conclusion

At the moment, the npm package is under development and does not take into account many factors such as Eslint 9 and its flat configuration. But nothing stops you from trying to use it with Eslint 8 and older.

If you think this tool would be useful — let me know. I’m happy for any feedback and help

Get an email whenever Maksim Dolgikh publishes.

@dolgikh-maks/eslint-summary

...

🐧 Where should I put my font and color config? In my Terminal config? My shell config?


📈 30.4 Punkte
🐧 Linux Tipps

🔧 Incrementally fixing lots of ESlint errors in a clean way with ESlint Nibble


📈 29.8 Punkte
🔧 Programmierung

📰 Hacky hack on whack 'Hacky Hack Hack' Mac chaps hack attack rap cut some slack


📈 25.56 Punkte
📰 IT Security Nachrichten

🔧 How to Create an ESLint Config Package in Turborepo


📈 25.03 Punkte
🔧 Programmierung

🔧 What 'eslint.config.js' do in React ?


📈 25.03 Punkte
🔧 Programmierung

🔧 EsLint + TypeScript + Prettier (Flat Config)


📈 25.03 Punkte
🔧 Programmierung

🔧 Making Shared ESLint, Prettier Config Files


📈 25.03 Punkte
🔧 Programmierung

🔧 New ESLint flat config file format example


📈 25.03 Punkte
🔧 Programmierung

🔧 Configuring VSCode to Work Vetur and ESLint With The Airbnb Base Config


📈 25.03 Punkte
🔧 Programmierung

🐧 SSH config priorities (aka How to Clean up your SSH Config)


📈 23.14 Punkte
🐧 Linux Tipps

🕵️ Linux Kernel up to 4.13.9 config.c usb_get_bos_descriptor Config memory corruption


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ radare2 1.5.0 DEX File libr/config/config.c r_config_set denial of service


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Config-Model up to 2.x INC Array lib/Config/Model.pm Directory privilege escalation


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ AWStats 6.5 1.857 Config awstats.pl config cross site scripting


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Linux Kernel bis 4.13.9 config.c usb_get_bos_descriptor Config Pufferüberlauf


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ radare2 1.5.0 DEX File libr/config/config.c r_config_set Denial of Service


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Config-Model bis 2.x INC Array lib/Config/Model.pm Directory erweiterte Rechte


📈 20.27 Punkte
🕵️ Sicherheitslücken

📰 Cortex-XDR-Config-Extractor - Cortex XDR Config Extractor


📈 20.27 Punkte
📰 IT Security Nachrichten

🕵️ Apache Traffic Control up to 3.1.0/4.1.0 Config File ip_allow.config permission


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Spring Cloud Config up to 2.1.8/2.2.2 spring-cloud-config-server path traversal


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Google Anroid up to 9.0 Proxy Auto Config spaces.h heap Config File information disclosure


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Spring Cloud Config up to 1.4.5/2.0.3/2.1.1 spring-cloud-config-server directory traversal


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Emerson Liebert Control Access Control config/configUser.htm Config privilege escalation


📈 20.27 Punkte
🕵️ Sicherheitslücken

🕵️ Datenstrom Yellow 0.7.3 Edit Page Action system/config/config.ini cross site scripting


📈 20.27 Punkte
🕵️ Sicherheitslücken

🎥 Learn How to Hack AI Code! #hack Hack #ai #code #coding #ethicalhacking 👉 http://snyk.co/zsec


📈 19.17 Punkte
🎥 Videos

🔧 Setting Up ESLint and Prettier in Your React Project with Webpack and Babel (Continued)


📈 17.78 Punkte
🔧 Programmierung

🔧 How to Use ESLint to Boost Your Programming Skills


📈 17.78 Punkte
🔧 Programmierung