@@ -2,6 +2,7 @@ import { writeFile } from 'node:fs/promises'
2
2
import { resolve } from 'node:path'
3
3
4
4
import { camelCase , pascalCase , snakeCase } from 'change-case'
5
+ import { ESLint } from 'eslint'
5
6
import { format , resolveConfig } from 'prettier'
6
7
7
8
interface Route {
@@ -140,12 +141,30 @@ const exampleRoute: Route = {
140
141
141
142
const write = async ( data : string , ...path : string [ ] ) : Promise < void > => {
142
143
const filepath = resolve ( ...path )
144
+ const eslint = new ESLint ( { fix : true } )
145
+
143
146
const prettierConfig = await resolveConfig ( filepath )
144
147
if ( prettierConfig == null ) {
145
148
throw new Error ( 'Failed to resolve Prettier config' )
146
149
}
147
- const output = await format ( data , { ...prettierConfig , filepath } )
148
- await writeFile ( filepath , output )
150
+
151
+ const [ linted ] = await eslint . lintText ( data )
152
+
153
+ if ( linted == null ) {
154
+ throw new Error ( 'ESLint returned empty results' )
155
+ }
156
+
157
+ if ( linted . fatalErrorCount > 0 ) {
158
+ // TODO: ESLint is failing to parse, seems it may not be loading the right config.
159
+ // throw new Error(
160
+ // `ESLint returned fatal errors: ${JSON.stringify(linted.messages)}`,
161
+ // )
162
+ }
163
+
164
+ const output = linted . output ?? linted . source ?? ''
165
+
166
+ const prettyData = await format ( output , { ...prettierConfig , filepath } )
167
+ await writeFile ( filepath , prettyData )
149
168
}
150
169
151
170
const routeRootPath = resolve ( 'src' , 'lib' , 'seam' , 'connect' , 'routes' )
0 commit comments