Skip to content

Commit 7bbb21a

Browse files
committed
Fix ESLint in generator
1 parent 23589e4 commit 7bbb21a

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

generate-routes.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,46 @@ const exampleRoute: Route = {
145145
}
146146

147147
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+
}
150153

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) {
153160
throw new Error('Failed to resolve Prettier config')
154161
}
162+
return await format(data, { ...config, filepath })
163+
}
155164

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 })
157172

158173
if (linted == null) {
159174
throw new Error('ESLint returned empty results')
160175
}
161176

162177
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+
)
167185
}
168186

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
173188
}
174189

175190
const routeRootPath = resolve('src', 'lib', 'seam', 'connect', 'routes')

src/lib/seam/connect/routes/workspaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Automaically generated by generate-routes.ts.
3+
* Do not edit this file or add other files to this directory.
4+
*/
5+
16
import type { RouteRequestParams, RouteResponse } from '@seamapi/types/connect'
27
import { Axios } from 'axios'
38
import type { SetNonNullable } from 'type-fest'

0 commit comments

Comments
 (0)