Skip to content

Enhancement: typeMatchesSpecifier add ability to match via a pattern #6839

Open
@RebeccaStevens

Description

@RebeccaStevens

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

Relevant Package

utils

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Add ability to provide a regex expression of the type name instead of a string that has to match exactly.
Additionally, allow for a glob pattern to be given as the "path" for the FileSpecifier.

Fail

// N/A

Pass

// Match all local types prefix with mutable
typeMatchesSpecifier(
  type,
  {
    from: "file",
    name: /^(M|m)utable.+/u,
  },
  program);

// Match all local types defined in a test or tests director.
typeMatchesSpecifier(
  type,
  {
    from: "file",
    name: /^.+/u,
    path: "**/tests?/**"
  },
  program);

// Match all build in "Readonly" types
typeMatchesSpecifier(
  type,
  {
    from: "lib",
    name: /^Readonly.+/u,
  },
  program);

// Match all types in all @foo/* packages
typeMatchesSpecifier(
  type,
  {
    from: "package",
    name: /^.+/u,
    package: /^@foo\/.+/u,
  },
  program);

Additional Info

New specifier definitions will look something like this:

interface FileSpecifier {
  from: 'file';
  name: string | RegExp | (string | RegExp)[];
  path?: string;
}

interface LibSpecifier {
  from: 'lib';
  name: string | RegExp | (string | RegExp)[];
}

interface PackageSpecifier {
  from: 'package';
  name: string | RegExp | (string | RegExp)[];
  package: string | RegExp;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: type-utilsIssues related to the @typescript-eslint/type-utils package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions