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

feat(experimental-utils): allow rule options to be a readonly tuple #1924

Merged

Conversation

ulrichb
Copy link
Contributor

@ulrichb ulrichb commented Apr 21, 2020

  • Change createRule's TOptions to a readonly generic constraint ...
  • ... and make it mutable exactly where it's necessary: within applyDefault() (after cloning it, the mutation happens in line 26 & 28)

=> This allows to create a rule this way:

ESLintUtils.RuleCreator(name => name)<readonly [{ readonly prop: string }],
    "defaultMessage">({
    name: "name", meta: { /* ... */ },
    create(context, options) {

        // This is now a compile error ("Cannot assign to '0' because it
        //  is a read-only property"), which is gooodd:
        options[0] = { prop: "x" };

        return {};
    },
});

…` tuple

* Change `createRule`'s `TOptions` to a readonly generic constraint ...
* ... and make it mutable exactly where it's necessary: within `applyDefault()` (after cloning it)
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ulrichb!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Apr 21, 2020

Codecov Report

Merging #1924 into master will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1924   +/-   ##
=======================================
  Coverage   94.36%   94.36%           
=======================================
  Files         166      166           
  Lines        7608     7608           
  Branches     2185     2185           
=======================================
  Hits         7179     7179           
  Misses        183      183           
  Partials      246      246           
Flag Coverage Δ
#unittest 94.36% <100.00%> (ø)
Impacted Files Coverage Δ
...experimental-utils/src/eslint-utils/RuleCreator.ts 66.66% <ø> (ø)
...xperimental-utils/src/eslint-utils/applyDefault.ts 100.00% <100.00%> (ø)

@bradzacher bradzacher added enhancement New feature or request package: utils Issues related to the @typescript-eslint/utils package labels Apr 21, 2020
@bradzacher bradzacher changed the title chore(experimental-utils): Allow rules to specify a readonly Options tuple feat(experimental-utils): allow rule options to be a readonly tuple Apr 21, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've been wanting to get in and do this for a while

@bradzacher bradzacher merged commit 4ef6788 into typescript-eslint:master Apr 21, 2020
@ulrichb
Copy link
Contributor Author

ulrichb commented Apr 21, 2020

Thanks! I've been wanting to get in and do this for a while

:)

Thanks for merging!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request package: utils Issues related to the @typescript-eslint/utils package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants