@@ -145,31 +145,46 @@ const exampleRoute: Route = {
145
145
}
146
146
147
147
const write = async ( data : string , ...path : string [ ] ) : Promise < void > => {
148
- const filepath = resolve ( ...path )
149
- const eslint = new ESLint ( { fix : true } )
148
+ const filePath = resolve ( ...path )
149
+ const fixedOutput = await eslintFixOutput ( data , filePath )
150
+ const prettyOutput = await prettierOutput ( fixedOutput , filePath )
151
+ await writeFile ( filePath , prettyOutput )
152
+ }
150
153
151
- const prettierConfig = await resolveConfig ( filepath )
152
- if ( prettierConfig == null ) {
154
+ const prettierOutput = async (
155
+ data : string ,
156
+ filepath : string ,
157
+ ) : Promise < string > => {
158
+ const config = await resolveConfig ( filepath )
159
+ if ( config == null ) {
153
160
throw new Error ( 'Failed to resolve Prettier config' )
154
161
}
162
+ return await format ( data , { ...config , filepath } )
163
+ }
155
164
156
- const [ linted ] = await eslint . lintText ( data )
165
+ const eslintFixOutput = async (
166
+ data : string ,
167
+ filePath : string ,
168
+ ) : Promise < string > => {
169
+ const eslint = new ESLint ( { fix : true } )
170
+
171
+ const [ linted ] = await eslint . lintText ( data , { filePath } )
157
172
158
173
if ( linted == null ) {
159
174
throw new Error ( 'ESLint returned empty results' )
160
175
}
161
176
162
177
if ( linted . fatalErrorCount > 0 ) {
163
- // TODO: ESLint is failing to parse, seems it may not be loading the right config.
164
- // throw new Error(
165
- // `ESLint returned fatal errors: ${JSON.stringify(linted.messages)}`,
166
- // )
178
+ throw new Error (
179
+ `ESLint returned fatal errors:\n${ JSON . stringify (
180
+ linted . messages ,
181
+ null ,
182
+ 2 ,
183
+ ) } `,
184
+ )
167
185
}
168
186
169
- const output = linted . output ?? linted . source ?? ''
170
-
171
- const prettyData = await format ( output , { ...prettierConfig , filepath } )
172
- await writeFile ( filepath , prettyData )
187
+ return linted . output ?? linted . source ?? data
173
188
}
174
189
175
190
const routeRootPath = resolve ( 'src' , 'lib' , 'seam' , 'connect' , 'routes' )
0 commit comments