Skip to content

Commit 66db26e

Browse files
fix: include options.bin in ESLint allowDefaultProject (#1866)
## PR Checklist - [x] Addresses an existing open issue: fixes #1846 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview 💖
1 parent 8bab69c commit 66db26e

File tree

4 files changed

+139
-3
lines changed

4 files changed

+139
-3
lines changed

src/next/blocks/blockESLint.test.ts

+134
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,138 @@ describe("blockESLint", () => {
436436
}
437437
`);
438438
});
439+
440+
test("with options.bin", () => {
441+
const creation = testBlock(blockESLint, {
442+
options: {
443+
...optionsBase,
444+
bin: "bin/index.js",
445+
},
446+
});
447+
448+
expect(creation).toMatchInlineSnapshot(`
449+
{
450+
"addons": [
451+
{
452+
"addons": {
453+
"words": [
454+
"tseslint",
455+
],
456+
},
457+
"block": [Function],
458+
},
459+
{
460+
"addons": {
461+
"sections": {
462+
"Linting": {
463+
"contents": {
464+
"after": [
465+
"
466+
For example, ESLint can be run with \`--fix\` to auto-fix some lint rule complaints:
467+
468+
\`\`\`shell
469+
pnpm run lint --fix
470+
\`\`\`
471+
",
472+
],
473+
"before": "
474+
This package includes several forms of linting to enforce consistent code quality and styling.
475+
Each should be shown in VS Code, and can be run manually on the command-line:
476+
",
477+
"items": [
478+
"- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files",
479+
],
480+
"plural": "Read the individual documentation for each linter to understand how it can be configured and used best.",
481+
},
482+
},
483+
},
484+
},
485+
"block": [Function],
486+
},
487+
{
488+
"addons": {
489+
"jobs": [
490+
{
491+
"name": "Lint",
492+
"steps": [
493+
{
494+
"run": "pnpm build",
495+
},
496+
{
497+
"run": "pnpm lint",
498+
},
499+
],
500+
},
501+
],
502+
},
503+
"block": [Function],
504+
},
505+
{
506+
"addons": {
507+
"properties": {
508+
"devDependencies": {
509+
"@eslint/js": "9.17.0",
510+
"@types/node": "22.10.2",
511+
"eslint": "9.17.0",
512+
"typescript-eslint": "8.19.0",
513+
},
514+
"scripts": {
515+
"lint": "eslint . --max-warnings 0",
516+
},
517+
},
518+
},
519+
"block": [Function],
520+
},
521+
{
522+
"addons": {
523+
"extensions": [
524+
"dbaeumer.vscode-eslint",
525+
],
526+
"settings": {
527+
"editor.codeActionsOnSave": {
528+
"source.fixAll.eslint": "explicit",
529+
},
530+
"eslint.probe": [
531+
"javascript",
532+
"javascriptreact",
533+
"json",
534+
"jsonc",
535+
"markdown",
536+
"typescript",
537+
"typescriptreact",
538+
"yaml",
539+
],
540+
"eslint.rules.customizations": [
541+
{
542+
"rule": "*",
543+
"severity": "warn",
544+
},
545+
],
546+
},
547+
},
548+
"block": [Function],
549+
},
550+
],
551+
"files": {
552+
"eslint.config.js": "import eslint from "@eslint/js";
553+
import tseslint from "typescript-eslint";
554+
555+
export default tseslint.config(
556+
{ ignores: ["lib", "node_modules", "pnpm-lock.yaml"] },
557+
{ linterOptions: {"reportUnusedDisableDirectives":"error"} },
558+
eslint.configs.recommended,
559+
{ extends: [tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked], files: ["**/*.js", "**/*.ts"], languageOptions: {"parserOptions":{"projectService":{"allowDefaultProject":["*.config.*s","bin/index.js"]},"tsconfigRootDir":import.meta.dirname}}, }
560+
);",
561+
},
562+
"scripts": [
563+
{
564+
"commands": [
565+
"pnpm lint --fix",
566+
],
567+
"phase": 3,
568+
},
569+
],
570+
}
571+
`);
572+
});
439573
});

src/next/blocks/blockESLint.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export const blockESLint = base.createBlock({
103103
languageOptions: {
104104
parserOptions: {
105105
projectService: {
106-
allowDefaultProject: ["*.config.*s"],
106+
allowDefaultProject: Array.from(
107+
new Set(["*.config.*s", options.bin].filter(Boolean).sort()),
108+
),
107109
},
108110
tsconfigRootDir: "import.meta.dirname",
109111
},

src/steps/writing/creation/createESLintConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default tseslint.config(
8080
files: ["**/*.js", "**/*.ts"],
8181
languageOptions: {
8282
parserOptions: {
83-
projectService: { allowDefaultProject: ["*.config.*s"] },
83+
projectService: { allowDefaultProject: ${JSON.stringify(["*.config.*s", options.bin].filter(Boolean).sort())} },
8484
tsconfigRootDir: import.meta.dirname
8585
},
8686
},${

src/steps/writing/creation/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const optionsBaseline: Options = {
180180
access: "public",
181181
author: "Test Author",
182182
base: "everything",
183-
bin: "bin/test.js",
183+
bin: "bin/index.js",
184184
description: "Test Description",
185185
directory: "test-directory",
186186
email: { github: "[email protected]", npm: "[email protected]" },

0 commit comments

Comments
 (0)