Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint-plugin] Match ESLint rules with options #862

Open
10 tasks
LayZeeDK opened this issue Oct 24, 2024 · 1 comment
Open
10 tasks

[eslint-plugin] Match ESLint rules with options #862

LayZeeDK opened this issue Oct 24, 2024 · 1 comment

Comments

@LayZeeDK
Copy link
Contributor

LayZeeDK commented Oct 24, 2024

User story

As a Code PushUp user,
I want to use a prefix or regex/glob pattern to specify the slug of an audit configuration
So that I can target ESLint rules with custom options like @typescript-eslint/naming-convention without having to specify their hash suffix, including ESLint rules that are commonly project-specific like @angular-eslint/component-selector

{
  "plugins": [
    {
      "groups": [
        {
          "refs": [
            {
              "slug": "typescript-eslint-naming-convention-09e76a48765f01e8",
              "weight": 1
            },
            {
              "slug": "angular-eslint-component-selector-574c6d42a4038009",
              "weight": 1
            },
            {
              "slug": "angular-eslint-component-selector-cfc91be936ea54f4",
              "weight": 1
            },
            {
              "slug": "angular-eslint-component-selector-9a4cd2aa001aa5b4",
              "weight": 1
            },
          ]
        }
      ]
    }
  ]
}

Example ouput of code-pushup print-config.

Acceptance criteria

  • I can enable an ESLint rule that has options specified, simply by specifying the rule slug as a prefix, glob pattern, or regular expression in the configuration, for example:
    • typescript-eslint-naming-convention
    • typescript-eslint-naming-convention-
    • typescript-eslint-naming-convention-*
    • typescript-eslint-naming-convention-[a-f0-9]+
  • I can enable an ESLint rule that has project-specific options specified, simply by specifying the rule slug as a prefix, glob pattern, or regular expression in the configuration, for example:
    • angular-eslint-component-selector
    • angular-eslint-component-selector-
    • angular-eslint-component-selector-*
    • angular-eslint-component-selector-[a-f0-9]+

Implementation details

No response

@matejchalk
Copy link
Collaborator

Thanks for the suggestion, I agree that having to include the options hash is inconvenient for configuration 👍

In general, having to configure custom ESLint groups using audits slugs adds unnecessary complexity. I've proposed an alternative configuration where the rule IDs from ESLint can be used, and any custom options will be matched automatically. I've also taken the wildcard suggestion one step further and proposed to use it for arbitrary rule matching (e.g. @angular-eslint/*).

The example you describe could then be configured with:

{
  slug: 'naming-convention',
  title: 'Naming convention',
  rules: ['@typescript-eslint/naming-convention', '@angular-eslint/component-selector']
}

and would resolve to group:

{
  "slug": "naming-convention",
  "title": "Naming convention",
  "refs": [
    {
      "slug": "typescript-eslint-naming-convention-09e76a48765f01e8",
      "weight": 1
    },
    {
      "slug": "angular-eslint-component-selector-574c6d42a4038009",
      "weight": 0.5
    },
    {
      "slug": "angular-eslint-component-selector-cfc91be936ea54f4",
      "weight": 0.5
    },
    {
      "slug": "angular-eslint-component-selector-9a4cd2aa001aa5b4",
      "weight": 0.5
    },
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants