Skip to content

Bug: possible regression of TypeOrValueSpecifier for scoped packages with restrict-template-expressions #10038

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

Open
4 tasks done
simon-v-swyftx opened this issue Sep 23, 2024 · 1 comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: type-utils Issues related to the @typescript-eslint/type-utils package

Comments

@simon-v-swyftx
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

I was using the new allow option for restrict-template-expressions that landed in 8.6.0

I expected that:

// packages/flat-config-typed-tsconfig/src/index.ts
import { Uuid } from '@company/core'

export class Service {
  public createPosition(
    id: Uuid,
  ): void {
    // Invalid type "Uuid" of template literal expression
    const a = `someUrl/${id}`;
                      //  ^ specifically not working when specifying package: @company/core
  }
}

does not report @typescript-eslint/restrict-template-expressions with the following config:

"@typescript-eslint/restrict-template-expressions": [
  "error",
  {
    allow: [
      // doesn't appear to be working
      {
        from: "package",
        name: "Uuid",
        package: "@company/core",
      },
    ],
  },
],

The uuid file in question exports a class with a custom .toString so I don't want it to error 🙂 See reproduction repo

Feels related to this old fix: #6780 but I might be barking up the wrong tree

Reproduction Repository Link

https://github.com/simon-v-swyftx/typescript-eslint-reproducable

Repro Steps

  1. clone the repo
  2. yarn install
  3. view packages/flat-config-typed-tsconfig/src/index.ts
  4. observe error on line 8

Versions

package version
@typescript-eslint/eslint-plugin 8.6.0
@typescript-eslint/parser 8.6.0
@typescript-eslint/scope-manager 8.6.0
@typescript-eslint/typescript-estree 8.6.0
@typescript-eslint/type-utils 8.6.0
@typescript-eslint/utils 8.6.0
TypeScript 5.6.2
ESLint 9.11.0
node 20.10.0
@simon-v-swyftx simon-v-swyftx added bug Something isn't working triage Waiting for team members to take a look labels Sep 23, 2024
@auvred
Copy link
Member

auvred commented Sep 25, 2024

2. yarn install

It fails with the following error (I assumed the yarn should be v3. if so, it would be nice to specify packageManager in the package.json)

yarn install logs
> yarn
! Corepack is about to download https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz
? Do you want to continue? [Y/n]

! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610.
! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager

yarn install v1.22.22
warning Missing version in workspace at "/tmp/repro/typescript-eslint-reproducable/packages/core", ignoring.
[1/4] Resolving packages...
error Couldn't find package "@company/core@workspace:*" required by "flat-config-typed-tsconfig@0.0.0" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

The result of a little investigation: the issue is that typescript doesn't have @company/core in the program.sourceFileToPackageName
https://github.com/typescript-eslint/typescript-eslint/blob/896c7312dfe8374312df9404cb11db8378cd091c/packages/type-utils/src/typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile.ts#L38j

Looks like TS has a special behavior for locally linked workspace packages.

@auvred auvred added accepting prs Go ahead, send a pull request that resolves this issue package: type-utils Issues related to the @typescript-eslint/type-utils package and removed triage Waiting for team members to take a look labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: type-utils Issues related to the @typescript-eslint/type-utils package
Projects
None yet
Development

No branches or pull requests

2 participants