fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #455 from hey-api/feat/support-biome-as-linter-and-formatter

feat: support biomejs as a formatter and linter

authored by

Jordan Shatford and committed by
GitHub
2faa567a 9d9de659

+152 -36
+5
.changeset/cyan-mice-learn.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + change: config option `lint: true` has changed to `lint: 'eslint'`
+5
.changeset/long-peaches-check.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + feat: add support for biomejs as a formatter
+5
.changeset/thirty-olives-drive.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + feat: add support for biomejs as a linter
+5
.changeset/twelve-poets-ring.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + change: config option `format: true` has changed to `format: 'prettier'`
+45 -5
docs/openapi-ts/configuration.md
··· 103 103 104 104 ## Formatting 105 105 106 - By default, `openapi-ts` will automatically format your client according to your project configuration. To disable automatic formatting, set `format` to false 106 + By default, `openapi-ts` will automatically format your client according to your project configuration. To disable automatic formatting, set `format` to false. 107 + 108 + ::: code-group 109 + 110 + ```js{2} [prettier] 111 + export default { 112 + format: 'prettier', 113 + input: 'path/to/openapi.json', 114 + output: 'src/client', 115 + } 116 + ``` 117 + 118 + ```js{2} [biome] 119 + export default { 120 + format: 'biome', 121 + input: 'path/to/openapi.json', 122 + output: 'src/client', 123 + } 124 + ``` 107 125 108 - ```js{2} 126 + ```js{2} [disabled] 109 127 export default { 110 128 format: false, 111 129 input: 'path/to/openapi.json', ··· 113 131 } 114 132 ``` 115 133 134 + ::: 135 + 116 136 You can also prevent your client from being processed by formatters by adding your output path to the tool's ignore file (e.g. `.prettierignore`). 117 137 118 138 ## Linting 119 139 120 - For performance reasons, `openapi-ts` does not automatically lint your client. To enable this feature, set `lint` to true 140 + For performance reasons, `openapi-ts` does not automatically lint your client. To enable this feature, set `lint` to a valid linter. 121 141 122 - ```js{3} 142 + ::: code-group 143 + 144 + ```js{3} [disabled] 145 + export default { 146 + input: 'path/to/openapi.json', 147 + lint: false, 148 + output: 'src/client', 149 + } 150 + ``` 151 + 152 + ```js{3} [eslint] 153 + export default { 154 + input: 'path/to/openapi.json', 155 + lint: 'eslint', 156 + output: 'src/client', 157 + } 158 + ``` 159 + 160 + ```js{3} [biome] 123 161 export default { 124 162 input: 'path/to/openapi.json', 125 - lint: true, 163 + lint: 'biome', 126 164 output: 'src/client', 127 165 } 128 166 ``` 167 + 168 + ::: 129 169 130 170 You can also prevent your client from being processed by linters by adding your output path to the tool's ignore file (e.g. `.eslintignore`). 131 171
+24
docs/openapi-ts/migrating.md
··· 50 50 51 51 ## v0.42.0 52 52 53 + ### Changed `format` 54 + 55 + This config option has changed. You now need to specify a value (`biome` or `prettier`) to format the output (default: `prettier`). 56 + 57 + ```js{2} 58 + export default { 59 + format: 'prettier', 60 + input: 'path/to/openapi.json', 61 + output: 'src/client', 62 + } 63 + ``` 64 + 65 + ### Changed `lint` 66 + 67 + This config option has changed. You now need to specify a value (`biome` or `eslint`) to lint the output (default: `false`). 68 + 69 + ```js{3} 70 + export default { 71 + input: 'path/to/openapi.json', 72 + lint: 'eslint', 73 + output: 'src/client', 74 + } 75 + ``` 76 + 53 77 ### Moved `operationId` 54 78 55 79 This config option has been moved. You can now configure it using the `services.operationId` option.
+56 -15
packages/openapi-ts/src/index.ts
··· 24 24 xhr: [], 25 25 }; 26 26 27 + type OutputProcesser = { 28 + args: (output: string) => string[]; 29 + command: string; 30 + condition: (dependencies: Dependencies) => boolean; 31 + name: string; 32 + }; 33 + 34 + // Map of supported formatters 35 + const formatters: Record<Extract<Config['format'], string>, OutputProcesser> = { 36 + biome: { 37 + args: (output) => ['format', '--write', output], 38 + command: 'biome', 39 + condition: (dependencies) => Boolean(dependencies['@biomejs/biome']), 40 + name: 'Biome (Format)', 41 + }, 42 + prettier: { 43 + args: (output) => [ 44 + '--ignore-unknown', 45 + output, 46 + '--write', 47 + '--ignore-path', 48 + './.prettierignore', 49 + ], 50 + command: 'prettier', 51 + condition: (dependencies) => Boolean(dependencies.prettier), 52 + name: 'Prettier', 53 + }, 54 + }; 55 + 56 + // Map of supported linters 57 + const linters: Record<Extract<Config['lint'], string>, OutputProcesser> = { 58 + biome: { 59 + args: (output) => ['lint', '--apply', output], 60 + command: 'biome', 61 + condition: (dependencies) => Boolean(dependencies['@biomejs/biome']), 62 + name: 'Biome (Lint)', 63 + }, 64 + eslint: { 65 + args: (output) => [output, '--fix'], 66 + command: 'eslint', 67 + condition: (dependencies) => Boolean(dependencies.eslint), 68 + name: 'ESLint', 69 + }, 70 + }; 71 + 27 72 const processOutput = (dependencies: Dependencies) => { 28 73 const config = getConfig(); 29 - 30 74 if (config.format) { 31 - if (dependencies.prettier) { 32 - console.log('✨ Running Prettier'); 33 - sync('prettier', [ 34 - '--ignore-unknown', 35 - config.output, 36 - '--write', 37 - '--ignore-path', 38 - './.prettierignore', 39 - ]); 75 + const formatter = formatters[config.format]; 76 + if (formatter.condition(dependencies)) { 77 + console.log(`✨ Running ${formatter.name}`); 78 + sync(formatter.command, formatter.args(config.output)); 40 79 } 41 80 } 42 - 43 - if (config.lint && dependencies.eslint) { 44 - console.log('✨ Running ESLint'); 45 - sync('eslint', [config.output, '--fix']); 81 + if (config.lint) { 82 + const linter = linters[config.lint]; 83 + if (linter.condition(dependencies)) { 84 + console.log(`✨ Running ${linter.name}`); 85 + sync(linter.command, linter.args(config.output)); 86 + } 46 87 } 47 88 }; 48 89 ··· 165 206 dryRun = false, 166 207 enums = false, 167 208 exportCore = true, 168 - format = true, 209 + format = 'prettier', 169 210 input, 170 211 lint = false, 171 212 name,
+3 -3
packages/openapi-ts/src/types/config.ts
··· 30 30 exportCore?: boolean; 31 31 /** 32 32 * Process output folder with formatter? 33 - * @default true 33 + * @default 'prettier' 34 34 */ 35 - format?: boolean; 35 + format?: 'biome' | 'prettier' | false; 36 36 /** 37 37 * The relative location of the OpenAPI spec 38 38 */ ··· 41 41 * Process output folder with linter? 42 42 * @default false 43 43 */ 44 - lint?: boolean; 44 + lint?: 'biome' | 'eslint' | false; 45 45 /** 46 46 * Custom client class name 47 47 */
+2 -2
packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts
··· 15 15 dryRun: false, 16 16 enums: 'javascript', 17 17 exportCore: true, 18 - format: true, 18 + format: 'prettier', 19 19 input: '', 20 20 lint: false, 21 21 output: '', ··· 42 42 dryRun: false, 43 43 enums: 'javascript', 44 44 exportCore: true, 45 - format: true, 45 + format: 'prettier', 46 46 input: '', 47 47 lint: false, 48 48 output: '',
+1 -1
packages/openapi-ts/src/utils/write/__tests__/client.spec.ts
··· 17 17 dryRun: false, 18 18 enums: 'javascript', 19 19 exportCore: true, 20 - format: true, 20 + format: 'prettier', 21 21 input: '', 22 22 lint: false, 23 23 output: './dist',
+1 -10
packages/openapi-ts/test/bin.spec.ts
··· 160 160 '--output', 161 161 './test/generated/bin', 162 162 '--lint', 163 + 'eslint', 163 164 ]); 164 165 expect(result.stdout.toString()).toContain('ESLint'); 165 166 expect(result.stderr.toString()).toBe(''); ··· 255 256 'true', 256 257 '--services', 257 258 'true', 258 - '--format', 259 - 'true', 260 - '--lint', 261 - 'true', 262 259 '--useOptions', 263 260 'true', 264 261 '--dry-run', ··· 269 266 expect(result.stderr.toString()).toContain('exportCore: true'); 270 267 expect(result.stderr.toString()).toContain('types: true'); 271 268 expect(result.stderr.toString()).toContain('services: true'); 272 - expect(result.stderr.toString()).toContain('format: true'); 273 - expect(result.stderr.toString()).toContain('lint: true'); 274 269 expect(result.stderr.toString()).toContain('schemas: true'); 275 270 expect(result.stderr.toString()).toContain('useOptions: true'); 276 271 }); ··· 289 284 '--schemas', 290 285 '--services', 291 286 'bar', 292 - '--format', 293 - '--lint', 294 287 '--useOptions', 295 288 '--dry-run', 296 289 'true', ··· 298 291 expect(result.stderr.toString()).toContain('debug: true'); 299 292 expect(result.stderr.toString()).toContain('dryRun: true'); 300 293 expect(result.stderr.toString()).toContain('exportCore: true'); 301 - expect(result.stderr.toString()).toContain('format: true'); 302 - expect(result.stderr.toString()).toContain('lint: true'); 303 294 expect(result.stderr.toString()).toContain('schemas: true'); 304 295 expect(result.stderr.toString()).toContain('useOptions: true'); 305 296 expect(result.stderr.toString()).toContain("types: 'foo");