From 21310e019794d04cff3ec4088d396e91035eeef3 Mon Sep 17 00:00:00 2001 From: Elecmonkey Date: Thu, 14 May 2026 15:19:58 +0800 Subject: [PATCH 1/3] fix: reuse eslint mapping for rslint templates --- src/index.ts | 28 ++++++++++++++++++--- test/cli.test.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 627025f..733b630 100644 --- a/src/index.ts +++ b/src/index.ts @@ -339,6 +339,19 @@ export type RslintTemplateName = | 'react-js' | 'react-ts'; +const rslintTemplateNames = new Set([ + 'vanilla-js', + 'vanilla-ts', + 'react-js', + 'react-ts', +]); + +function isRslintTemplateName( + templateName: ESLintTemplateName | null, +): templateName is RslintTemplateName { + return templateName !== null && rslintTemplateNames.has(templateName); +} + const readJSON = async (path: string) => JSON.parse(await fs.promises.readFile(path, 'utf-8')); @@ -787,9 +800,18 @@ export async function create({ } if (tool === 'rslint') { - const rslintTemplateName = mapRslintTemplate - ? mapRslintTemplate(templateName, { distFolder }) - : 'vanilla-ts'; + let rslintTemplateName: RslintTemplateName | null; + + if (mapRslintTemplate) { + rslintTemplateName = mapRslintTemplate(templateName, { distFolder }); + } else { + const eslintTemplateName = mapESLintTemplate + ? mapESLintTemplate(templateName, { distFolder }) + : null; + rslintTemplateName = isRslintTemplateName(eslintTemplateName) + ? eslintTemplateName + : 'vanilla-ts'; + } if (!rslintTemplateName) { continue; diff --git a/test/cli.test.ts b/test/cli.test.ts index f032799..b7a2ef6 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -110,6 +110,69 @@ test('should scaffold mapped rslint tool template', async () => { expect(fs.existsSync(path.join(projectDir, 'react-ts'))).toBe(false); }); +test('should reuse eslint template mapping for rslint when rslint mapping is not provided', async () => { + const projectDir = path.join(testDir, 'rslint-tool-with-eslint-mapping'); + + await create({ + name: 'test', + root: fixturesDir, + templates: ['vanilla'], + getTemplateName: async () => 'vanilla', + mapESLintTemplate: () => 'react-js', + argv: [ + 'node', + 'test', + '--dir', + projectDir, + '--template', + 'vanilla', + '--tools', + 'rslint', + ], + }); + + const config = fs.readFileSync( + path.join(projectDir, 'rslint.config.ts'), + 'utf-8', + ); + + expect(config).toContain('reactPlugin.configs.recommended'); + expect(config).not.toContain('ts.configs.recommended'); +}); + +test('should fallback to vanilla-ts when eslint mapping cannot be reused for rslint', async () => { + const projectDir = path.join( + testDir, + 'rslint-tool-with-unsupported-eslint-mapping', + ); + + await create({ + name: 'test', + root: fixturesDir, + templates: ['vanilla'], + getTemplateName: async () => 'vanilla', + mapESLintTemplate: () => 'vue-ts', + argv: [ + 'node', + 'test', + '--dir', + projectDir, + '--template', + 'vanilla', + '--tools', + 'rslint', + ], + }); + + const config = fs.readFileSync( + path.join(projectDir, 'rslint.config.ts'), + 'utf-8', + ); + + expect(config).toContain('ts.configs.recommended'); + expect(config).not.toContain('reactPlugin.configs.recommended'); +}); + test('should skip tools selection', async () => { const projectDir = path.join(testDir, 'comma-separated-tools'); From 842d4a78b82d0ec607ff0b5474f64e412e42c263 Mon Sep 17 00:00:00 2001 From: Elecmonkey Date: Thu, 14 May 2026 15:56:12 +0800 Subject: [PATCH 2/3] Revert "fix: reuse eslint mapping for rslint templates" This reverts commit 21310e019794d04cff3ec4088d396e91035eeef3. --- src/index.ts | 28 +++------------------ test/cli.test.ts | 63 ------------------------------------------------ 2 files changed, 3 insertions(+), 88 deletions(-) diff --git a/src/index.ts b/src/index.ts index 733b630..627025f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -339,19 +339,6 @@ export type RslintTemplateName = | 'react-js' | 'react-ts'; -const rslintTemplateNames = new Set([ - 'vanilla-js', - 'vanilla-ts', - 'react-js', - 'react-ts', -]); - -function isRslintTemplateName( - templateName: ESLintTemplateName | null, -): templateName is RslintTemplateName { - return templateName !== null && rslintTemplateNames.has(templateName); -} - const readJSON = async (path: string) => JSON.parse(await fs.promises.readFile(path, 'utf-8')); @@ -800,18 +787,9 @@ export async function create({ } if (tool === 'rslint') { - let rslintTemplateName: RslintTemplateName | null; - - if (mapRslintTemplate) { - rslintTemplateName = mapRslintTemplate(templateName, { distFolder }); - } else { - const eslintTemplateName = mapESLintTemplate - ? mapESLintTemplate(templateName, { distFolder }) - : null; - rslintTemplateName = isRslintTemplateName(eslintTemplateName) - ? eslintTemplateName - : 'vanilla-ts'; - } + const rslintTemplateName = mapRslintTemplate + ? mapRslintTemplate(templateName, { distFolder }) + : 'vanilla-ts'; if (!rslintTemplateName) { continue; diff --git a/test/cli.test.ts b/test/cli.test.ts index b7a2ef6..f032799 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -110,69 +110,6 @@ test('should scaffold mapped rslint tool template', async () => { expect(fs.existsSync(path.join(projectDir, 'react-ts'))).toBe(false); }); -test('should reuse eslint template mapping for rslint when rslint mapping is not provided', async () => { - const projectDir = path.join(testDir, 'rslint-tool-with-eslint-mapping'); - - await create({ - name: 'test', - root: fixturesDir, - templates: ['vanilla'], - getTemplateName: async () => 'vanilla', - mapESLintTemplate: () => 'react-js', - argv: [ - 'node', - 'test', - '--dir', - projectDir, - '--template', - 'vanilla', - '--tools', - 'rslint', - ], - }); - - const config = fs.readFileSync( - path.join(projectDir, 'rslint.config.ts'), - 'utf-8', - ); - - expect(config).toContain('reactPlugin.configs.recommended'); - expect(config).not.toContain('ts.configs.recommended'); -}); - -test('should fallback to vanilla-ts when eslint mapping cannot be reused for rslint', async () => { - const projectDir = path.join( - testDir, - 'rslint-tool-with-unsupported-eslint-mapping', - ); - - await create({ - name: 'test', - root: fixturesDir, - templates: ['vanilla'], - getTemplateName: async () => 'vanilla', - mapESLintTemplate: () => 'vue-ts', - argv: [ - 'node', - 'test', - '--dir', - projectDir, - '--template', - 'vanilla', - '--tools', - 'rslint', - ], - }); - - const config = fs.readFileSync( - path.join(projectDir, 'rslint.config.ts'), - 'utf-8', - ); - - expect(config).toContain('ts.configs.recommended'); - expect(config).not.toContain('reactPlugin.configs.recommended'); -}); - test('should skip tools selection', async () => { const projectDir = path.join(testDir, 'comma-separated-tools'); From 489e67d70a933f16df861fb06a7a521c749c6f55 Mon Sep 17 00:00:00 2001 From: Elecmonkey Date: Thu, 14 May 2026 15:57:33 +0800 Subject: [PATCH 3/3] fix: update wrong comment --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 627025f..7d7c180 100644 --- a/src/index.ts +++ b/src/index.ts @@ -561,7 +561,7 @@ export async function create({ ) => ESLintTemplateName | null; /** * Map the template name to the Rslint template name. - * If not provided, reuses mapESLintTemplate and falls back to 'vanilla-ts'. + * If not provided, defaults to 'vanilla-ts' for all templates. */ mapRslintTemplate?: ( templateName: string,