Skip to content

Commit 3181aee

Browse files
authored
chore: Adding eslint and prettier to toolchain options (#70)
As per [this](#36) comment thread, I've added eslint+prettier as a toolchain option. I've tested start configurations in the contributing guide and all looks to be working. [This](https://github.com/TanStack/config/blob/main/prettier.config.js) was my source for the prettier config. I used the tanstack config as implemented [here](https://tanstack.com/config/latest/docs/eslint) in the docs. Let me know if anything looks off, or feel free to push changes!
1 parent 09af3f5 commit 3181aee

15 files changed

+133
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Available options:
4646
- `--template <type>`: Choose between `file-router`, `typescript`, or `javascript`
4747
- `--tailwind`: Enable Tailwind CSS
4848
- `--package-manager`: Specify your preferred package manager (`npm`, `yarn`, `pnpm`, `bun`, or `deno`)
49-
- `--toolchain`: Specify your toolchain solution for formatting/linting (`biome`)
49+
- `--toolchain`: Specify your toolchain solution for formatting/linting (`biome`, `eslint+prettier`)
5050
- `--no-git`: Do not initialize a git repository
5151
- `--add-ons`: Enable add-on selection or specify add-ons to install
5252

@@ -102,6 +102,8 @@ Choose your preferred solution for formatting and linting either through the int
102102

103103
Setting this flag to `biome` will configure it as your toolchain of choice, adding a `biome.json` to the root of the project. Consult the [biome documentation](https://biomejs.dev/guides/getting-started/) for further customization.
104104

105+
Setting this flag to `eslint+prettier` will configure it as your toolchain of choice, adding an `eslint.config.js` and `prettier.config.js` to the root of the project, as well as a `.prettierignore` file. Consult the [eslint documentation](https://eslint.org/docs/latest/) and [prettier documentation](https://prettier.io/docs/) for further customization.
106+
105107
## Add-ons (experimental)
106108

107109
You can enable add-on selection:

src/create-app.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,25 @@ async function createPackageJSON(
216216
},
217217
}
218218
}
219+
if (options.toolchain === 'eslint+prettier') {
220+
const eslintPrettierPackageJSON = JSON.parse(
221+
await environment.readFile(
222+
resolve(templateDir, 'package.eslintprettier.json'),
223+
'utf-8',
224+
),
225+
)
226+
packageJSON = {
227+
...packageJSON,
228+
scripts: {
229+
...packageJSON.scripts,
230+
...eslintPrettierPackageJSON.scripts,
231+
},
232+
devDependencies: {
233+
...packageJSON.devDependencies,
234+
...eslintPrettierPackageJSON.devDependencies,
235+
},
236+
}
237+
}
219238
if (options.mode === FILE_ROUTER) {
220239
const frPackageJSON = JSON.parse(
221240
await environment.readFile(resolve(routerDir, 'package.fr.json'), 'utf8'),
@@ -400,6 +419,18 @@ export async function createApp(
400419
copyFiles(templateDirBase, ['./toolchain/biome.json'], true)
401420
}
402421

422+
if (options.toolchain === 'eslint+prettier') {
423+
copyFiles(
424+
templateDirBase,
425+
[
426+
'./toolchain/eslint.config.js',
427+
'./toolchain/prettier.config.js',
428+
'./toolchain/.prettierignore',
429+
],
430+
true,
431+
)
432+
}
433+
403434
// Setup reportWebVitals
404435
if (!isAddOnEnabled('start') && options.framework === 'react') {
405436
if (options.typescript) {
@@ -431,7 +462,7 @@ export async function createApp(
431462
)
432463
}
433464

434-
// Setup the package.json file, optionally with typescript, tailwind and biome
465+
// Setup the package.json file, optionally with typescript, tailwind and formatter/linter
435466
await createPackageJSON(
436467
environment,
437468
options.projectName,
@@ -696,6 +727,16 @@ export async function createApp(
696727
s?.stop(`Applied toolchain ${options.toolchain}...`)
697728
}
698729

730+
if (options.toolchain === 'eslint+prettier') {
731+
s?.start(`Applying toolchain ${options.toolchain}...`)
732+
await environment.execute(
733+
options.packageManager,
734+
['run', 'check'],
735+
targetDir,
736+
)
737+
s?.stop(`Applied toolchain ${options.toolchain}...`)
738+
}
739+
699740
if (options.git) {
700741
s?.start(`Initializing git repository...`)
701742
await environment.execute('git', ['init'], resolve(targetDir))

src/toolchain.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
export const SUPPORTED_TOOLCHAINS = ['none', 'biome'] as const
1+
export const SUPPORTED_TOOLCHAINS = [
2+
'none',
3+
'biome',
4+
'eslint+prettier',
5+
] as const
26
export type ToolChain = (typeof SUPPORTED_TOOLCHAINS)[number]
37
export const DEFAULT_TOOLCHAIN: ToolChain = 'none'

templates/react/base/README.md.ejs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
3131
<% } else { %>
3232
This project uses CSS for styling.
3333
<% } %>
34-
<% if (toolchain && toolchain === 'biome') { %>
34+
<% if (toolchain && toolchain !== 'none') { %>
3535
## Linting & Formatting
36+
<% if (toolchain === 'biome') { %>
3637
This project uses [Biome](https://biomejs.dev/) for linting and formatting. The following scripts are available:
37-
38+
<% } %>
39+
<% if (toolchain === 'eslint+prettier') { %>
40+
This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.io/) for linting and formatting. Eslint is configured using [tanstack/eslint-config](https://tanstack.com/config/latest/docs/eslint). The following scripts are available:
41+
<% } %>
3842
```bash
3943
<%= getPackageManagerRunScript('lint') %>
4044
<%= getPackageManagerRunScript('format') %>
4145
<%= getPackageManagerRunScript('check') %>
4246
```
4347
<% } %>
44-
4548
<% for(const addon of addOns.filter(addon => addon.readme)) { %>
4649
<%- addon.readme %>
4750
<% } %>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"scripts": {
3+
"lint": "eslint",
4+
"format": "prettier",
5+
"check": "prettier --write . && eslint --fix"
6+
},
7+
"devDependencies": {
8+
"@tanstack/eslint-config": "^0.1.0",
9+
"prettier": "^3.5.3"
10+
}
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package-lock.json
2+
pnpm-lock.yaml
3+
yarn.lock
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-check
2+
3+
import { tanstackConfig } from "@tanstack/eslint-config";
4+
5+
export default [...tanstackConfig];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
3+
/** @type {import('prettier').Config} */
4+
const config = {
5+
semi: false,
6+
singleQuote: true,
7+
trailingComma: "all",
8+
};
9+
10+
export default config;

templates/react/base/tsconfig.json.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"include": ["**/*.ts", "**/*.tsx"],
2+
<% if (toolchain && toolchain === 'eslint+prettier') { %>"include": ["**/*.ts", "**/*.tsx", "eslint.config.js", "prettier.config.js", "vite.config.js"],
3+
<% } else { %>"include": ["**/*.ts", "**/*.tsx"],<% } %>
34
"compilerOptions": {
45
"target": "ES2022",
56
"jsx": "react-jsx",

templates/solid/base/README.md.ejs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ Loaders simplify your data fetching logic dramatically. Check out more informati
195195
196196
Files prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.
197197
198+
<% if (toolchain && toolchain !== 'none') { %>
199+
## Linting & Formatting
200+
<% if (toolchain === 'biome') { %>
201+
This project uses [Biome](https://biomejs.dev/) for linting and formatting. The following scripts are available:
202+
<% } %>
203+
<% if (toolchain === 'eslint+prettier') { %>
204+
This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.io/) for linting and formatting. Eslint is configured using [tanstack/eslint-config](https://tanstack.com/config/latest/docs/eslint). The following scripts are available:
205+
<% } %>
206+
```bash
207+
<%= getPackageManagerRunScript('lint') %>
208+
<%= getPackageManagerRunScript('format') %>
209+
<%= getPackageManagerRunScript('check') %>
210+
```
211+
<% } %>
212+
198213
# Learn More
199214
200215
You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).

0 commit comments

Comments
 (0)