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

Configs: Allow strict configs to have more strict options than recommended? #7318

Closed
2 tasks done
JoshuaKGoldberg opened this issue Jul 26, 2023 · 8 comments · Fixed by #8364
Closed
2 tasks done

Configs: Allow strict configs to have more strict options than recommended? #7318

JoshuaKGoldberg opened this issue Jul 26, 2023 · 8 comments · Fixed by #8364
Labels
accepting prs Go ahead, send a pull request that resolves this issue package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin preset config change Proposal for an addition, removal, or general change to a preset config

Comments

@JoshuaKGoldberg
Copy link
Member

Before You File a Proposal Please Confirm You Have Done The Following...

Description

Coming over from comment thread #7110 (comment): rules are occasionally in a situation where:

  • Many users in the recommended configs don't want to use their full options, as they're more "strict" than common use cases
  • We still want to enable the strict options for users, especially those on the strict configs

What if we added to the defaultOptions and/or meta.docs sections of rules so that different configs can have different default options?

Impacted Configurations

  • strict
  • strict-type-checked

Additional Info

The example from the thread is https://typescript-eslint.io/rules/restrict-plus-operands/#options.

@JoshuaKGoldberg JoshuaKGoldberg added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look preset config change Proposal for an addition, removal, or general change to a preset config labels Jul 26, 2023
@Zamiell
Copy link
Contributor

Zamiell commented Jul 27, 2023

This sounds like a must-do!

As a user who wants a maximally strict linting config, I'd be super interested to know which rules that I'm using that are inherited from strict and strict-type-checked that are not maximally strictly configured. To start with, can we just document the specific rules that have dumbed-down options? That would allow strict users to fix the problem themselves in the interim until the proposed full multi-option solution exists.

@JoshuaKGoldberg
Copy link
Member Author

document the specific rules that have dumbed-down options?

Hmm, very interesting. I like the root ask of knowing which rules have opt-in "more strict" options...

@bradzacher
Copy link
Member

I'm of two minds - I like the idea but I also dislike it because it does make things quite a bit more complicated to define and strictly type. The options type we use is not for the config inputs - it's for the "after defaults" merging - which is one reason we haven't added strict types for user configs with our options types.

The last thing I'd want is for us to define a stricter config, roll it out, then find we misconfigured it and it's broken!

@JoshuaKGoldberg
Copy link
Member Author

JoshuaKGoldberg commented Feb 4, 2024

Here's a list of rules I'd propose:

it does make things quite a bit more complicated to define and strictly type

Maybe we could make meta.docs.recommended a union type? Perhaps rename it to something like config(s) or recommendation(s)?

Sent #8364 as reference.

@Zamiell
Copy link
Contributor

Zamiell commented Feb 8, 2024

strict-boolean-expressions also has some weird defaults that could be stricter:

  "@typescript-eslint/strict-boolean-expressions": [
    "error",
    {
      allowString: false,
      allowNumber: false,
      allowNullableObject: false,
      allowNullableBoolean: false,
      allowNullableString: false,
      allowNullableNumber: false,
      allowNullableEnum: false,
      allowAny: false,
      allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
    },
  ],

@Zamiell
Copy link
Contributor

Zamiell commented Feb 8, 2024

Also here:

  /**
   * The `allowDefaultCaseForExhaustiveSwitch` option is disabled and the
   * `requireDefaultForNonUnion` option is enabled to make the rule stricter.
   */
  "@typescript-eslint/switch-exhaustiveness-check": [
    "error",
    {
      allowDefaultCaseForExhaustiveSwitch: false,
      requireDefaultForNonUnion: true,
    },
  ],

@Zamiell
Copy link
Contributor

Zamiell commented Feb 8, 2024

And this:

  /** The `capIsConstructor` option is disabled to make the rule stricter. */
  "@typescript-eslint/no-invalid-this": [
    "error",
    {
      capIsConstructor: false,
    },
  ],

And this:

  /**
   * The `args` option is set to `all` make the rule stricter. Additionally, we ignore things that
   * begin with an underscore, since this matches the behavior of the `--noUnusedLocals` TypeScript
   * compiler flag.
   */
  "@typescript-eslint/no-unused-vars": [
    "error",
    {
      args: "all", // "after-used" is the default.
      argsIgnorePattern: "^_", // Optional, this line makes the rule less strict, but is idiomatic
      varsIgnorePattern: "^_", // Optional, this line makes the rule less strict, but is idiomatic
    },
  ],

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Feb 24, 2024
@JoshuaKGoldberg
Copy link
Member Author

Oh @Zamiell just looking at those now: none of those are in the recommended, strict, or stylistic presets. If you think we should enable stricter options for them by default and/or add them to a preset that'd be a separate issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin preset config change Proposal for an addition, removal, or general change to a preset config
Projects
None yet
3 participants