Switch eslint-plugin-unicorn to the unopinionated preset#13984
Merged
Conversation
`recommended` enables unicorn's opinionated style rules, which we kept switching off one by one, and the v66 upgrade added more of them. `unopinionated` is the baseline without those rules, so it matches what we actually want to enforce: unicorn's bug-catching rules, not its style preferences. Adopting it makes nine of our `off` overrides redundant, along with a few inline `eslint-disable` directives, so they get removed. The overrides that remain stay because `unopinionated` still enables those rules.
The override turned the rule off, but the codebase has no `.apply()` calls for it to flag, so it was inert. Dropping it lets the `unopinionated` preset enforce the rule and guards against future `fn.apply(...)` usage.
The override turned the rule off for one violation in the trusted publishing docs script, which escaped backslashes inside a template literal. That script now uses `String.raw`, so the override is no longer needed and the rule enforces the cleaner form going forward.
The call sites that used `.replace(/.../g, ...)` now use `.replaceAll()`, with simple literal patterns passed as plain strings. With no remaining violations, the override is removed so the rule is enforced going forward.
`Array#toReversed()` is supported well enough now, so the override is removed and the rule enforced. The two call sites reversed throwaway arrays from `.map()`, so they switch to the non-mutating `.toReversed()` without any behavior change.
`Array#toSorted()` is supported well enough now, so the override is removed and the rule enforced. Every flagged `.sort()` ran on a freshly built array or reassigned its result, so switching to the non-mutating `.toSorted()` keeps the same behavior. The token list no longer needs its defensive `[...tokens]` copy, since `.toSorted()` already returns a new array.
The flagged accesses are global properties (`onerror`, `onunhandledrejection`, `crypto`, `location`) that the client-only files reach through `window`. They switch to `globalThis`, which resolves to the same object in the browser.
59516e0 to
b5929ac
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We were enabling unicorn's
recommendedpreset and then switching off a growing list of opinionated style rules.unopinionatedis the same baseline without those rules, so it matches what we actually want to enforce and lets us drop most of the overrides. The remaining commits enable a handful of the non-style rules that were previously off and adjust the affected call sites.All rules and the
unopinionatedconfig already exist in the currently pinnedeslint-plugin-unicorn(65.0.1), so this stands on its own. It also pairs with the v66 update in #13977, which is what surfaced several of these rules.Related