Skip to content

feat: add opt-in blockESLintPlugin #2131

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

Merged
merged 6 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"attw",
"boop",
"dbaeumer",
"eslint-doc-generatorrc.js",
"infile",
"joshuakgoldberg",
"markdownlintignore",
Expand Down
1 change: 1 addition & 0 deletions docs/Blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This table summarizes each block and which base levels they're included in:
| ESLint Node Plugin | `--add-eslint-node-plugin`, `--exclude-eslint-node-plugin` | | | 💯 |
| ESLint package.json Plugin | `--add-eslint-package-json-plugin`, `--exclude-eslint-package-json-plugin` | | | 💯 |
| ESLint Perfectionist Plugin | `--add-eslint-perfectionist-plugin`, `--exclude-eslint-perfectionist-plugin` | | | 💯 |
| ESLint Plugin | `--add-eslint-plugin`, `--exclude-eslint-plugin` | | | |
| ESLint Regexp Plugin | `--add-eslint-regexp-plugin`, `--exclude-eslint-regexp-plugin` | | | 💯 |
| ESLint YML Plugin | `--add-eslint-yml-plugin`, `--exclude-eslint-yml-plugin` | | | 💯 |
| Funding | `--add-funding`, `--exclude-funding` | | ✅ | 💯 |
Expand Down
6 changes: 6 additions & 0 deletions src/blocks/blockESLint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ describe("blockESLint", () => {
imports: [
{ source: "eslint-plugin-markdown", specifier: "a", types: true },
{ source: "eslint-plugin-regexp", specifier: "b" },
{
source: { packageName: "eslint-plugin-unknown", version: "1.2.3" },
specifier: "c",
},
],
rules: {
"a/b": "error",
Expand Down Expand Up @@ -536,6 +540,7 @@ describe("blockESLint", () => {
"eslint": "9.22.0",
"eslint-plugin-markdown": "5.1.0",
"eslint-plugin-regexp": "2.7.0",
"eslint-plugin-unknown": "1.2.3",
"typescript-eslint": "8.26.1",
},
"scripts": {
Expand Down Expand Up @@ -586,6 +591,7 @@ describe("blockESLint", () => {
import eslint from "@eslint/js";
import a from "eslint-plugin-markdown"
import b from "eslint-plugin-regexp"
import c from "eslint-plugin-unknown"
import tseslint from "typescript-eslint";

export default tseslint.config(
Expand Down
48 changes: 35 additions & 13 deletions src/blocks/blockESLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ const zExtension = z.object({
});

const zPackageImport = z.object({
source: z.string(),
source: z.union([
z.string(),
z.object({ packageName: z.string(), version: z.string() }),
]),
specifier: z.string(),
types: z.boolean().optional(),
});
Expand Down Expand Up @@ -88,7 +91,7 @@ export const blockESLint = base.createBlock({
'import tseslint from "typescript-eslint";',
...imports.map(
(packageImport) =>
`import ${packageImport.specifier} from "${packageImport.source}"`,
`import ${packageImport.specifier} from "${typeof packageImport.source === "string" ? packageImport.source : packageImport.source.packageName}"`,
),
].sort((a, b) =>
a.replace(/.+from/, "").localeCompare(b.replace(/.+from/, "")),
Expand Down Expand Up @@ -183,17 +186,36 @@ Each should be shown in VS Code, and can be run manually on the command-line:
}),
blockPackageJson({
properties: {
devDependencies: getPackageDependencies(
"@eslint/js",
"@types/node",
"eslint",
"typescript-eslint",
...imports.flatMap(({ source, types }) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call -- https://github.com/egoist/parse-package-name/issues/30
const { name } = parsePackageName(source) as { name: string };
return types ? [name, `@types/${name}`] : [name];
}),
),
devDependencies: {
...getPackageDependencies(
"@eslint/js",
"@types/node",
"eslint",
"typescript-eslint",
...imports
.filter((imported) => typeof imported.source === "string")
.flatMap(({ source, types }) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call -- https://github.com/egoist/parse-package-name/issues/30
const { name } = parsePackageName(source) as {
name: string;
};
return types ? [name, `@types/${name}`] : [name];
}),
),
...Object.fromEntries(
imports
.filter(
(
imported,
): imported is typeof imported & { source: object } =>
typeof imported.source === "object",
)
.map((imported) => [
imported.source.packageName,
imported.source.version,
]),
),
},
scripts: {
lint: "eslint . --max-warnings 0",
},
Expand Down
Loading