From fd95737e4c846226e7cc6fe02ad326690c7c6992 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 14 Jan 2025 19:56:52 -0500 Subject: [PATCH] fix: include options.bin in ESLint allowDefaultProject --- src/next/blocks/blockESLint.test.ts | 134 ++++++++++++++++++ src/next/blocks/blockESLint.ts | 4 +- .../writing/creation/createESLintConfig.ts | 2 +- src/steps/writing/creation/index.test.ts | 2 +- 4 files changed, 139 insertions(+), 3 deletions(-) diff --git a/src/next/blocks/blockESLint.test.ts b/src/next/blocks/blockESLint.test.ts index de6ba66a7..87e50987b 100644 --- a/src/next/blocks/blockESLint.test.ts +++ b/src/next/blocks/blockESLint.test.ts @@ -436,4 +436,138 @@ describe("blockESLint", () => { } `); }); + + test("with options.bin", () => { + const creation = testBlock(blockESLint, { + options: { + ...optionsBase, + bin: "bin/index.js", + }, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "words": [ + "tseslint", + ], + }, + "block": [Function], + }, + { + "addons": { + "sections": { + "Linting": { + "contents": { + "after": [ + " + For example, ESLint can be run with \`--fix\` to auto-fix some lint rule complaints: + + \`\`\`shell + pnpm run lint --fix + \`\`\` + ", + ], + "before": " + This package includes several forms of linting to enforce consistent code quality and styling. + Each should be shown in VS Code, and can be run manually on the command-line: + ", + "items": [ + "- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files", + ], + "plural": "Read the individual documentation for each linter to understand how it can be configured and used best.", + }, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Lint", + "steps": [ + { + "run": "pnpm build", + }, + { + "run": "pnpm lint", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "@eslint/js": "9.17.0", + "@types/node": "22.10.2", + "eslint": "9.17.0", + "typescript-eslint": "8.19.0", + }, + "scripts": { + "lint": "eslint . --max-warnings 0", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "extensions": [ + "dbaeumer.vscode-eslint", + ], + "settings": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit", + }, + "eslint.probe": [ + "javascript", + "javascriptreact", + "json", + "jsonc", + "markdown", + "typescript", + "typescriptreact", + "yaml", + ], + "eslint.rules.customizations": [ + { + "rule": "*", + "severity": "warn", + }, + ], + }, + }, + "block": [Function], + }, + ], + "files": { + "eslint.config.js": "import eslint from "@eslint/js"; + import tseslint from "typescript-eslint"; + + export default tseslint.config( + { ignores: ["lib", "node_modules", "pnpm-lock.yaml"] }, + { linterOptions: {"reportUnusedDisableDirectives":"error"} }, + eslint.configs.recommended, + { extends: [tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked], files: ["**/*.js", "**/*.ts"], languageOptions: {"parserOptions":{"projectService":{"allowDefaultProject":["*.config.*s","bin/index.js"]},"tsconfigRootDir":import.meta.dirname}}, } + );", + }, + "scripts": [ + { + "commands": [ + "pnpm lint --fix", + ], + "phase": 3, + }, + ], + } + `); + }); }); diff --git a/src/next/blocks/blockESLint.ts b/src/next/blocks/blockESLint.ts index 65990ab6b..ed3a14101 100644 --- a/src/next/blocks/blockESLint.ts +++ b/src/next/blocks/blockESLint.ts @@ -103,7 +103,9 @@ export const blockESLint = base.createBlock({ languageOptions: { parserOptions: { projectService: { - allowDefaultProject: ["*.config.*s"], + allowDefaultProject: Array.from( + new Set(["*.config.*s", options.bin].filter(Boolean).sort()), + ), }, tsconfigRootDir: "import.meta.dirname", }, diff --git a/src/steps/writing/creation/createESLintConfig.ts b/src/steps/writing/creation/createESLintConfig.ts index a7891d5eb..b7b319519 100644 --- a/src/steps/writing/creation/createESLintConfig.ts +++ b/src/steps/writing/creation/createESLintConfig.ts @@ -80,7 +80,7 @@ export default tseslint.config( files: ["**/*.js", "**/*.ts"], languageOptions: { parserOptions: { - projectService: { allowDefaultProject: ["*.config.*s"] }, + projectService: { allowDefaultProject: ${JSON.stringify(["*.config.*s", options.bin].filter(Boolean).sort())} }, tsconfigRootDir: import.meta.dirname }, },${ diff --git a/src/steps/writing/creation/index.test.ts b/src/steps/writing/creation/index.test.ts index 5dd7e9b2b..80b2c880e 100644 --- a/src/steps/writing/creation/index.test.ts +++ b/src/steps/writing/creation/index.test.ts @@ -180,7 +180,7 @@ const optionsBaseline: Options = { access: "public", author: "Test Author", base: "everything", - bin: "bin/test.js", + bin: "bin/index.js", description: "Test Description", directory: "test-directory", email: { github: "github@example.com", npm: "npm@example.com" },