Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@clack/prompts": "^1.2.0",
"@microsoft/api-extractor": "^7.58.7",
"@rslib/core": "0.21.3",
"@rslint/core": "^0.5.0",
"@rslint/core": "^0.5.1",
"@rstest/core": "0.9.9",
"@types/fs-extra": "^11.0.4",
"@types/minimist": "^1.2.5",
Expand Down
83 changes: 53 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ export type ESLintTemplateName =
| 'svelte-js'
| 'svelte-ts';

export type RslintTemplateName =
| 'vanilla-js'
| 'vanilla-ts'
| 'react-js'
| 'react-ts';

const readJSON = async (path: string) =>
JSON.parse(await fs.promises.readFile(path, 'utf-8'));

Expand Down Expand Up @@ -533,6 +539,7 @@ export async function create({
skipFiles,
getTemplateName,
mapESLintTemplate,
mapRslintTemplate,
version,
noteInformation,
extraTools,
Expand All @@ -552,6 +559,14 @@ export async function create({
templateName: string,
context: { distFolder: string },
) => ESLintTemplateName | null;
/**
* Map the template name to the Rslint template name.
* If not provided, reuses mapESLintTemplate and falls back to 'vanilla-ts'.
*/
mapRslintTemplate?: (
templateName: string,
context: { distFolder: string },
) => RslintTemplateName | null;
version?: Record<string, string> | string;
noteInformation?: string[];
/**
Expand Down Expand Up @@ -771,6 +786,30 @@ export async function create({
continue;
}

if (tool === 'rslint') {
const rslintTemplateName = mapRslintTemplate
? mapRslintTemplate(templateName, { distFolder })
: 'vanilla-ts';
Comment thread
chenjiahan marked this conversation as resolved.

if (!rslintTemplateName) {
continue;
}

const subFolder = path.join(toolFolder, rslintTemplateName);
copyFolder({
from: subFolder,
to: distFolder,
version,
skipFiles,
templateParameters,
isMergePackageJson: true,
});

agentsMdSearchDirs.push(toolFolder);
agentsMdSearchDirs.push(subFolder);
continue;
}

copyFolder({
from: toolFolder,
to: distFolder,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "rslint",
"name": "rslint-react-js",
"private": true,
"version": "1.0.0",
"scripts": {
"lint": "rslint"
},
"devDependencies": {
"@rslint/core": "^0.5.0"
"@rslint/core": "^0.5.1"
}
}
7 changes: 7 additions & 0 deletions template-rslint/react-js/rslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, js, reactHooksPlugin, reactPlugin } from '@rslint/core';

export default defineConfig([
js.configs.recommended,
reactPlugin.configs.recommended,
reactHooksPlugin.configs.recommended,
]);
11 changes: 11 additions & 0 deletions template-rslint/react-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rslint-react-ts",
"private": true,
"version": "1.0.0",
"scripts": {
"lint": "rslint"
},
"devDependencies": {
"@rslint/core": "^0.5.1"
}
}
14 changes: 14 additions & 0 deletions template-rslint/react-ts/rslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
defineConfig,
js,
ts,
reactPlugin,
reactHooksPlugin,
} from '@rslint/core';

export default defineConfig([
js.configs.recommended,
ts.configs.recommended,
reactPlugin.configs.recommended,
reactHooksPlugin.configs.recommended,
]);
3 changes: 0 additions & 3 deletions template-rslint/rslint.config.ts

This file was deleted.

11 changes: 11 additions & 0 deletions template-rslint/vanilla-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rslint-vanilla-js",
"private": true,
"version": "1.0.0",
"scripts": {
"lint": "rslint"
},
"devDependencies": {
"@rslint/core": "^0.5.1"
}
}
3 changes: 3 additions & 0 deletions template-rslint/vanilla-js/rslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig, js } from '@rslint/core';

export default defineConfig([js.configs.recommended]);
11 changes: 11 additions & 0 deletions template-rslint/vanilla-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rslint-vanilla-ts",
"private": true,
"version": "1.0.0",
"scripts": {
"lint": "rslint"
},
"devDependencies": {
"@rslint/core": "^0.5.1"
}
}
3 changes: 3 additions & 0 deletions template-rslint/vanilla-ts/rslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig, js, ts } from '@rslint/core';

export default defineConfig([js.configs.recommended, ts.configs.recommended]);
31 changes: 31 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,37 @@ test('should scaffold rslint tool files', async () => {
expect(packageJson.devDependencies['@rslint/core']).toBeTruthy();
});

test('should scaffold mapped rslint tool template', async () => {
const projectDir = path.join(testDir, 'mapped-rslint-tool');

await create({
name: 'test',
root: fixturesDir,
templates: ['vanilla'],
getTemplateName: async () => 'vanilla',
mapRslintTemplate: () => 'react-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('reactPlugin.configs.recommended');
expect(config).toContain('ts.configs.recommended');
expect(fs.existsSync(path.join(projectDir, 'react-ts'))).toBe(false);
});

test('should skip tools selection', async () => {
const projectDir = path.join(testDir, 'comma-separated-tools');

Expand Down
Loading