Repository: JoshuaKGoldberg/eslint-plugin-package-json (ts)

Issue:
🐛 Bug: `no-redundant-files` crashes when `files` contains a wildcard and `main` field is present
### Bug Report Checklist

- [x] I have tried restarting my IDE and the issue persists.
- [x] I have pulled the latest `main` branch of the repository.
- [x] I have [searched for related issues](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=is%3Aissue) and found none that matched my issue.

### Expected

Rule does not crash.

### Actual

`no-redundant-files` crashes when `files` contains a wildcard like `*.d.ts` and `main` field is present.

Minimal reproduction: https://stackblitz.com/edit/vitejs-vite-cczf3mgu

Real-world example: I'm testing my ESLint config on various public repositories, and I found this rule crashing on [this package.json](https://github.com/h3js/crossws/blob/main/package.json).

### Additional Info

Full error message:

```
Oops! Something went wrong! :(

ESLint: 9.27.0

SyntaxError: Invalid regular expression: /^(./)?*.d.ts$/i: Nothing to repeat
Occurred while linting C:\**\package.json:1
Rule: "package-json/no-redundant-files"
    at new RegExp (<anonymous>)
    at getCachedLocalFileRegex (C:\**\node_modules\.pnpm\eslint-plugin-package-json@_94d8e15049f2dddc0262660eae0dce2c\node_modules\eslint-plugin-package-json\lib\rules\no-redundant-files.js:40:13)
```

Pull request description:
fix: prevent `no-redundant-files` crash with wildcard and `main` field
## PR Checklist

- [x] Addresses an existing open issue: fixes #1066
- [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CONTRIBUTING.md) were taken

## Overview

Fixed a crash in the `no-redundant-files` rule when `files` contains wildcard patterns (like `*.d.ts`) and a `main` field is present.

- Added wildcard detection to `getCachedLocalFileRegex` function
- Files with glob patterns (`*`, `?`, `[]`, `{}`, `**`, `!`) are now skipped during validation
- Regular files continue to be validated normally for redundancy
- Added comprehensive test coverage for wildcard patterns

The rule now gracefully handles package.json files with glob patterns while maintaining all existing validation for regular file paths.


Patch:
diff --git a/src/rules/no-redundant-files.ts b/src/rules/no-redundant-files.ts
index ba4455c..d40d829 100644
--- a/src/rules/no-redundant-files.ts
+++ b/src/rules/no-redundant-files.ts
@@ -13,8 +13,14 @@ const defaultFiles = [
 	/^(\.\/)?package\.json$/i,
 ];
 
+const wildcardsRegex = /[*?[\]{}]/;
+
 const cachedRegex = new Map<string, RegExp>();
 const getCachedLocalFileRegex = (filename: string) => {
+	if (wildcardsRegex.test(filename)) {
+		return null;
+	}
+
 	// Strip the leading `./`, if there is one, since we'll be incorporating
 	// it into the regex.
 	const baseFilename = filename.replace("./", "");
@@ -161,7 +167,7 @@ export const rule = createRule({
 								const regex = getCachedLocalFileRegex(
 									fileEntry.value,
 								);
-								if (regex.test(fileToCheck)) {
+								if (regex?.test(fileToCheck)) {
 									report(files, index, validation.messageId);
 								}
 							}


Test patch:
diff --git a/src/tests/rules/no-redundant-files.test.ts b/src/tests/rules/no-redundant-files.test.ts
index c9372c0..35d927f 100644
--- a/src/tests/rules/no-redundant-files.test.ts
+++ b/src/tests/rules/no-redundant-files.test.ts
@@ -370,5 +370,49 @@ ruleTester.run("no-redundant-files", rule, {
   "cli": "./bin/cli.js"
 }}`,
 		`{ "main": "./dist/index.js", "files": ["CHANGELOG.md", "dist"] }`,
+		`{
+		"main": "./index.js",
+		"files": [
+			"*.d.ts",
+			"dist"
+		]
+	}`,
+		`{
+		"main": "./lib/index.js",
+		"files": [
+			"lib/**/*.js",
+			"*.d.ts",
+		]
+	}`,
+		`{
+		"bin": "./bin/cli.js",
+		"files": [
+			"bin/*",
+			"*.json"
+		]
+	}`,
+		`{
+		"files": [
+			"src/**/*",
+			"*.ts",
+			"!src/**/*.test.ts"
+		]
+	}`,
+		`{
+		"files": [
+			"**/*.d.ts",
+			"lib/[abc].js",
+			"src/{utils,helpers}/*.js"
+		]
+	}`,
+
+		`{
+		"main": "./index.js", 
+		"files": [
+			"*.d.ts",
+			"dist/specific-file.js",
+			"lib/**/*"
+		]
+	}`,
 	],
 });