Skip to content

Commit a49293b

Browse files
fix: also work with object bins in blockESLint
1 parent ea73c97 commit a49293b

File tree

2 files changed

+145
-2
lines changed

2 files changed

+145
-2
lines changed

src/blocks/blockESLint.test.ts

+135-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,141 @@ describe("blockESLint", () => {
473473
`);
474474
});
475475

476-
test("with options.bin", () => {
476+
test("with object options.bin", () => {
477+
const creation = testBlock(blockESLint, {
478+
options: {
479+
...optionsBase,
480+
bin: { repo: "bin/index.js" },
481+
},
482+
});
483+
484+
expect(creation).toMatchInlineSnapshot(`
485+
{
486+
"addons": [
487+
{
488+
"addons": {
489+
"words": [
490+
"tseslint",
491+
],
492+
},
493+
"block": [Function],
494+
},
495+
{
496+
"addons": {
497+
"sections": {
498+
"Linting": {
499+
"contents": {
500+
"after": [
501+
"
502+
For example, ESLint can be run with \`--fix\` to auto-fix some lint rule complaints:
503+
504+
\`\`\`shell
505+
pnpm run lint --fix
506+
\`\`\`
507+
",
508+
],
509+
"before": "
510+
This package includes several forms of linting to enforce consistent code quality and styling.
511+
Each should be shown in VS Code, and can be run manually on the command-line:
512+
",
513+
"items": [
514+
"- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files",
515+
],
516+
"plural": "Read the individual documentation for each linter to understand how it can be configured and used best.",
517+
},
518+
},
519+
},
520+
},
521+
"block": [Function],
522+
},
523+
{
524+
"addons": {
525+
"jobs": [
526+
{
527+
"name": "Lint",
528+
"steps": [
529+
{
530+
"run": "pnpm build",
531+
},
532+
{
533+
"run": "pnpm lint",
534+
},
535+
],
536+
},
537+
],
538+
},
539+
"block": [Function],
540+
},
541+
{
542+
"addons": {
543+
"properties": {
544+
"devDependencies": {
545+
"@eslint/js": "9.22.0",
546+
"@types/node": "22.13.10",
547+
"eslint": "9.22.0",
548+
"typescript-eslint": "8.26.1",
549+
},
550+
"scripts": {
551+
"lint": "eslint . --max-warnings 0",
552+
},
553+
},
554+
},
555+
"block": [Function],
556+
},
557+
{
558+
"addons": {
559+
"extensions": [
560+
"dbaeumer.vscode-eslint",
561+
],
562+
"settings": {
563+
"editor.codeActionsOnSave": {
564+
"source.fixAll.eslint": "explicit",
565+
},
566+
"eslint.probe": [
567+
"javascript",
568+
"javascriptreact",
569+
"json",
570+
"jsonc",
571+
"markdown",
572+
"typescript",
573+
"typescriptreact",
574+
"yaml",
575+
],
576+
"eslint.rules.customizations": [
577+
{
578+
"rule": "*",
579+
"severity": "warn",
580+
},
581+
],
582+
},
583+
},
584+
"block": [Function],
585+
},
586+
],
587+
"files": {
588+
"eslint.config.js": "import eslint from "@eslint/js";
589+
import tseslint from "typescript-eslint";
590+
591+
export default tseslint.config(
592+
{ ignores: ["lib", "node_modules", "pnpm-lock.yaml"] },
593+
{ linterOptions: {"reportUnusedDisableDirectives":"error"} },
594+
eslint.configs.recommended,
595+
{ extends: [tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked], files: ["**/*.js", "**/*.ts"], languageOptions: {"parserOptions":{"projectService":{"allowDefaultProject":["*.config.*s","bin/index.js"]},"tsconfigRootDir":import.meta.dirname}}, }
596+
);",
597+
},
598+
"scripts": [
599+
{
600+
"commands": [
601+
"pnpm lint --fix",
602+
],
603+
"phase": 3,
604+
},
605+
],
606+
}
607+
`);
608+
});
609+
610+
test("with string options.bin", () => {
477611
const creation = testBlock(blockESLint, {
478612
options: {
479613
...optionsBase,

src/blocks/blockESLint.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,16 @@ export const blockESLint = base.createBlock({
105105
parserOptions: {
106106
projectService: {
107107
allowDefaultProject: Array.from(
108-
new Set(["*.config.*s", options.bin].filter(Boolean).sort()),
108+
new Set(
109+
[
110+
"*.config.*s",
111+
...(typeof options.bin === "object"
112+
? Object.values(options.bin)
113+
: [options.bin]),
114+
]
115+
.filter(Boolean)
116+
.sort(),
117+
),
109118
),
110119
},
111120
tsconfigRootDir: "import.meta.dirname",

0 commit comments

Comments
 (0)