Skip to content

ESLintUtils.getParserServices should take a Readonly<RuleContext> #2232

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

Closed
danielnixon opened this issue Jun 20, 2020 · 1 comment · Fixed by #2235
Closed

ESLintUtils.getParserServices should take a Readonly<RuleContext> #2232

danielnixon opened this issue Jun 20, 2020 · 1 comment · Fixed by #2235
Labels
bug Something isn't working good first issue Good for newcomers package: utils Issues related to the @typescript-eslint/utils package

Comments

@danielnixon
Copy link
Contributor

Repro

I'm writing an ESLint rule to ban code that leads to the surprising mutability described in TypeScript issue #13347.

I'd like to forbid passing an immutable value to a function that expects a mutable (but otherwise compatible) type.

I've noticed that RuleModule.create gives us an Readonly<RuleContext> but ESLintUtils.getParserServices expects a (mutable) RuleContext. This triggers my rule (see below).

It looks like ESLintUtils.getParserServices doesn't mutate the passed in context, so please consider updating it to take a Readonly<RuleContext>. This would stop my rule from complaining.

const rule: RuleModule<...> = {
  meta: {
      ...
  },
  create: (context) => { // Context is a Readonly<RuleContext>
    const parserServices = ESLintUtils.getParserServices(context); // but getParserServices takes a (mutable) RuleContext

Expected Result

ESLintUtils.getParserServices takes Readonly<RuleContext>

Actual Result

ESLintUtils.getParserServices takes (mutable) RuleContext

Additional Info

Versions

package version
@typescript-eslint/experimental-utils 3.3.0 and earlier
TypeScript NA
node NA
npm NA
@danielnixon danielnixon added package: utils Issues related to the @typescript-eslint/utils package triage Waiting for team members to take a look labels Jun 20, 2020
@bradzacher
Copy link
Member

Happy to accept a PR!

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Jun 20, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: utils Issues related to the @typescript-eslint/utils package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants