Open
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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;
}