diff --git a/cspell.json b/cspell.json index 2b6087df5..99987a779 100644 --- a/cspell.json +++ b/cspell.json @@ -15,7 +15,7 @@ "attw", "boop", "dbaeumer", - "eslint-doc-generatorrc.js", + "eslint-doc-generatorrc", "infile", "joshuakgoldberg", "markdownlintignore", diff --git a/src/blocks/blockESLintPlugin.test.ts b/src/blocks/blockESLintPlugin.test.ts index da3bd9f1b..90cc1d0d5 100644 --- a/src/blocks/blockESLintPlugin.test.ts +++ b/src/blocks/blockESLintPlugin.test.ts @@ -5,7 +5,7 @@ import { blockESLintPlugin } from "./blockESLintPlugin.js"; import { optionsBase } from "./options.fakes.js"; describe("blockESLintPlugin", () => { - test("without mode", () => { + test("without options or mode", () => { const creation = testBlock(blockESLintPlugin, { options: optionsBase, }); @@ -16,7 +16,7 @@ describe("blockESLintPlugin", () => { { "addons": { "words": [ - "eslint-doc-generatorrc.js", + "eslint-doc-generatorrc", ], }, "block": [Function], @@ -95,11 +95,6 @@ describe("blockESLintPlugin", () => { "eslint-doc-generator": "2.1.0", "eslint-plugin-eslint-plugin": "6.4.0", }, - "peerDependencies": { - "@typescript-eslint/parser": ">=8", - "eslint": ">=9", - "typescript": ">=5", - }, "scripts": { "build:docs": "eslint-doc-generator", "lint:docs": "eslint-doc-generator --check", @@ -140,6 +135,139 @@ describe("blockESLintPlugin", () => { `); }); + test("with options.type set to commonjs", () => { + const creation = testBlock(blockESLintPlugin, { + options: { + ...optionsBase, + type: "commonjs", + }, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "words": [ + "eslint-doc-generatorrc", + ], + }, + "block": [Function], + }, + { + "addons": { + "sections": { + "Building": { + "innerSections": [ + { + "contents": " + Run [\`eslint-doc-generator\`](https://github.com/bmish/eslint-doc-generator) to generate Markdown files documenting rules. + + \`\`\`shell + pnpm build:docs + \`\`\` + ", + "heading": "Building Docs", + }, + ], + }, + "Linting": { + "contents": { + "items": [ + "- \`pnpm lint:docs\` ([eslint-doc-generator](https://github.com/bmish/eslint-doc-generator)): Generates and validates documentation for ESLint rules", + ], + }, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "extensions": [ + "eslintPlugin.configs["flat/recommended"]", + ], + "ignores": [ + ".eslint-doc-generatorrc.mjs", + "docs/rules/*/*.ts", + ], + "imports": [ + { + "source": { + "packageName": "eslint-plugin-eslint-plugin", + "version": "6.4.0", + }, + "specifier": "eslintPlugin", + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Lint Docs", + "steps": [ + { + "run": "pnpm build || exit 0", + }, + { + "run": "pnpm lint:docs", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "eslint-doc-generator": "2.1.0", + "eslint-plugin-eslint-plugin": "6.4.0", + }, + "scripts": { + "build:docs": "eslint-doc-generator", + "lint:docs": "eslint-doc-generator --check", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "coverage": { + "exclude": [ + "src/index.ts", + "src/rules/index.ts", + ], + }, + }, + "block": [Function], + }, + ], + "files": { + ".eslint-doc-generatorrc.mjs": "import prettier from "prettier"; + + /** @type {import('eslint-doc-generator').GenerateOptions} */ + const config = { + postprocess: async (content, path) => + prettier.format(content, { + ...(await prettier.resolveConfig(path)), + parser: "markdown", + }), + ruleDocTitleFormat: "prefix-name", + }; + + export default config; + ", + }, + } + `); + }); + test("setup mode", () => { const creation = testBlock(blockESLintPlugin, { mode: "setup", @@ -152,7 +280,7 @@ describe("blockESLintPlugin", () => { { "addons": { "words": [ - "eslint-doc-generatorrc.js", + "eslint-doc-generatorrc", ], }, "block": [Function], @@ -231,11 +359,6 @@ describe("blockESLintPlugin", () => { "eslint-doc-generator": "2.1.0", "eslint-plugin-eslint-plugin": "6.4.0", }, - "peerDependencies": { - "@typescript-eslint/parser": ">=8", - "eslint": ">=9", - "typescript": ">=5", - }, "scripts": { "build:docs": "eslint-doc-generator", "lint:docs": "eslint-doc-generator --check", diff --git a/src/blocks/blockESLintPlugin.ts b/src/blocks/blockESLintPlugin.ts index 045403bee..dc7824274 100644 --- a/src/blocks/blockESLintPlugin.ts +++ b/src/blocks/blockESLintPlugin.ts @@ -10,11 +10,13 @@ export const blockESLintPlugin = base.createBlock({ about: { name: "ESLint Plugin", }, - produce() { + produce({ options }) { + const configFileName = `.eslint-doc-generatorrc.${options.type === "commonjs" ? "mjs" : "js"}`; + return { addons: [ blockCSpell({ - words: ["eslint-doc-generatorrc.js"], + words: ["eslint-doc-generatorrc"], }), blockDevelopmentDocs({ sections: { @@ -43,7 +45,7 @@ pnpm build:docs }), blockESLint({ extensions: ['eslintPlugin.configs["flat/recommended"]'], - ignores: [".eslint-doc-generatorrc.js", "docs/rules/*/*.ts"], + ignores: [configFileName, "docs/rules/*/*.ts"], imports: [ { source: { @@ -71,11 +73,6 @@ pnpm build:docs "eslint-doc-generator": "2.1.0", "eslint-plugin-eslint-plugin": "6.4.0", }, - peerDependencies: { - "@typescript-eslint/parser": ">=8", - eslint: ">=9", - typescript: ">=5", - }, scripts: { "build:docs": "eslint-doc-generator", "lint:docs": "eslint-doc-generator --check", @@ -89,7 +86,7 @@ pnpm build:docs }), ], files: { - ".eslint-doc-generatorrc.js": `import prettier from "prettier"; + [configFileName]: `import prettier from "prettier"; /** @type {import('eslint-doc-generator').GenerateOptions} */ const config = {