Skip to content
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

fix: include options.bin in ESLint allowDefaultProject #1866

Merged
merged 1 commit into from
Jan 15, 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
134 changes: 134 additions & 0 deletions src/next/blocks/blockESLint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
}
`);
});
});
4 changes: 3 additions & 1 deletion src/next/blocks/blockESLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
2 changes: 1 addition & 1 deletion src/steps/writing/creation/createESLintConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},${
Expand Down
2 changes: 1 addition & 1 deletion src/steps/writing/creation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
Loading