Skip to content

Commit be56d74

Browse files
committed
Add support for ESLint Stylistic
1 parent d0ed8c2 commit be56d74

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async function togglePrompt(message: string, initial = false, active = 'Yes', in
4646
})
4747
}
4848

49+
async function togglePromptIf(condition: boolean, message: string, initial = false, active = 'Yes', inactive = 'No'): Promise<boolean> {
50+
return condition ? togglePrompt(message, initial, active, inactive) : initial
51+
}
52+
4953
type Config = {
5054
scopedPackageName: string
5155
unscopedPackageName: string
@@ -68,6 +72,7 @@ type Config = {
6872
includePlayground: boolean
6973
includeExamples: boolean
7074
includeEsLint: boolean
75+
includeEsLintStylistic: boolean
7176
}
7277

7378
async function init() {
@@ -126,7 +131,8 @@ async function init() {
126131
process.exit(1)
127132
}
128133

129-
const includeEsLint = await togglePrompt('Include ESLint?', true, 'Yes', 'No')
134+
const includeEsLint = await togglePrompt('Include ESLint?', true)
135+
const includeEsLintStylistic = await togglePromptIf(includeEsLint, 'Include ESLint Stylistic for formatting?', includeEsLint)
130136
const includeDocs = await togglePrompt('Include VitePress for documentation?', true)
131137
const includeGithubPages = includeDocs && await togglePrompt('Include GitHub Pages config for documentation?')
132138
const includePlayground = await togglePrompt('Include playground application for development?', true)
@@ -163,7 +169,8 @@ async function init() {
163169
includeGithubPages,
164170
includePlayground,
165171
includeExamples,
166-
includeEsLint
172+
includeEsLint,
173+
includeEsLintStylistic
167174
}
168175

169176
copyTemplate('base', config)

src/template/base/config/package.json.ejs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"devDependencies": {
3737
<%_ if (config.includeEsLint) { _%>
3838
"@eslint/compat": "^1.2.6",
39+
<%_ if (config.includeEsLintStylistic) { _%>
40+
"@stylistic/eslint-plugin": "^4.0.0",
41+
<%_ } _%>
3942
"@typescript-eslint/parser": "^8.23.0",
4043
"@vitest/eslint-plugin": "1.1.25",
4144
"@vue/eslint-config-typescript": "^14.3.0",

src/template/base/config/packages/@projectName@/vite.config.mts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export default defineConfig(({ mode }) => {
1111
throw new Error(`Unknown mode: ${mode}`)
1212
}
1313

14-
const dtsPlugin = mode === 'neutral' ? dts({
15-
rollupTypes: true,
16-
tsconfigPath: './tsconfig.app.json'
17-
}) : null
14+
const dtsPlugin = mode === 'neutral'
15+
? dts({
16+
rollupTypes: true,
17+
tsconfigPath: './tsconfig.app.json'
18+
})
19+
: null
1820

1921
return {
2022
plugins: [
@@ -47,15 +49,18 @@ export default defineConfig(({ mode }) => {
4749

4850
if (format === 'iife') {
4951
name += '.global'
50-
} else if (format === 'es') {
52+
}
53+
else if (format === 'es') {
5154
name += '.esm-' + (mode === 'neutral' ? 'bundler' : 'browser')
5255
}
5356

5457
if (mode === 'production') {
5558
name += '.prod'
56-
} else if (mode === 'development') {
59+
}
60+
else if (mode === 'development') {
5761
name += '.dev'
58-
} else if (mode === 'neutral') {
62+
}
63+
else if (mode === 'neutral') {
5964
extension = format === 'cjs' ? 'cjs' : 'mjs'
6065
}
6166

src/template/eslint/config/eslint.config.mts renamed to src/template/eslint/config/eslint.config.mts.ejs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@ import { fileURLToPath } from 'node:url'
33

44
import { includeIgnoreFile } from '@eslint/compat'
55
import pluginVue from 'eslint-plugin-vue'
6+
<%_ if (config.includeEsLintStylistic) { _%>
7+
import stylistic from '@stylistic/eslint-plugin'
8+
<%_ } _%>
69
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
710
import pluginVitest from '@vitest/eslint-plugin'
811

912
export default defineConfigWithVueTs(
1013
{
1114
name: 'app/files-to-lint',
12-
files: ['**/*.{ts,mts,vue}'],
15+
files: ['**/*.{ts,mts,vue}']
1316
},
1417

1518
includeIgnoreFile(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore')),
1619

1720
pluginVue.configs['flat/essential'],
1821
vueTsConfigs.recommended,
1922

23+
<%_ if (config.includeEsLintStylistic) { _%>
24+
stylistic.configs.customize({
25+
commaDangle: 'never'
26+
}),
27+
<%_ } _%>
28+
2029
{
2130
...pluginVitest.configs.recommended,
22-
files: ['src/**/__tests__/*'],
23-
},
31+
files: ['src/**/__tests__/*']
32+
}
2433
)

src/template/playground/config/packages/playground/vite.config.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import vueDevTools from 'vite-plugin-vue-devtools'
77
export default defineConfig(({ mode }) => ({
88
plugins: [
99
vue(),
10-
vueDevTools(),
10+
vueDevTools()
1111
],
1212
resolve: {
1313
alias: {
1414
'@': fileURLToPath(new URL('./src', import.meta.url)),
1515
'@scopedPackageName@': fileURLToPath(new URL('../@projectName@/src/index.ts', import.meta.url))
16-
},
16+
}
1717
},
1818

1919
define: {

0 commit comments

Comments
 (0)