makenowjust-labs / recheck

The trustworthy ReDoS checker
https://makenowjust-labs.github.io/recheck/
MIT License
231 stars 11 forks source link

Add Eslint Flat-File support for ReDos Eslint plugin #1293

Open ThomasTrepanier opened 5 days ago

ThomasTrepanier commented 5 days ago

What is the problem?

Since eslint@8.21.0, eslint now support a new type of configuration file: the flat-file format.

When migrating our config files to this new format, we realized that the ReDos eslint plugin does not yet support this new file format. More specifically, the rules attribute now has to be a JS object instead of an array of strings (see error below).

A config object has a "plugins" key defined as an array of strings.

Flat config requires "plugins" to be an object in this form:

    {
        plugins: {
            redos: pluginObject
        }
    }

Would you be able to add support for this file format?

How to fix the problem?

eslint released a migration guide for eslint plugins to add support for flat-file configs

ThomasTrepanier commented 5 days ago

For anyone stumbling upon this problem, until flat-file config support is added, you can use the ReDos plugin in your flat-file config like this:

import { FlatCompat } from "@eslint/eslintrc";

const compat = new FlatCompat({
  baseDirectory: import.meta.dirname,
});

const esConfigs = [
  // Rest of your config
  ...compat.extends("plugin:eslint-plugin-redos/recommended"),
  // Rest of your config
]

Source: https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config