@@ -10,6 +10,9 @@ import toml from 'smol-toml'
1010import { execa } from 'execa'
1111import { globby } from 'globby'
1212import ansiEscapes from 'ansi-escapes'
13+ import * as jsonc from 'jsonc-parser'
14+ import { xdgConfig } from 'xdg-basedir'
15+ import { getEcosystems } from '../devutils/index.ts'
1316
1417import type { CommandFixOptions , Config , Issue , Project } from '#types'
1518import type { PackageJson } from 'type-fest'
@@ -64,6 +67,35 @@ export async function run(options: CommandFixOptions, positionals: string[]) {
6467 return
6568 }
6669
70+ // FIX EDITOR SETTINGS
71+ if ( await fileExists ( '.vscode/settings.json' ) ) {
72+ const userSettingsJsonFile = path . join ( xdgConfig , 'Code/User/settings.json' )
73+ const defaultTitle =
74+ jsonc . parse ( await fs . readFile ( userSettingsJsonFile , 'utf-8' ) ) [ 'window.title' ]
75+
76+ const settingsText = await fs . readFile ( '.vscode/settings.json' , 'utf-8' )
77+ const settingsJson = jsonc . parse ( settingsText )
78+ const ecosystem = ( await getEcosystems ( Deno . cwd ( ) ) ) [ 0 ]
79+ if ( settingsJson [ 'window.title' ] ) {
80+ const output = settingsText . replace (
81+ / " w i n d o w \. t i t l e " [ \t ] * : [ \t ] * " .* ?" / m,
82+ `"window.title": "${ defaultTitle } (${ ecosystem } )"` ,
83+ )
84+ await fs . writeFile ( '.vscode/settings.json' , output )
85+ } else if ( Object . keys ( settingsJson ) . length === 0 ) {
86+ const output = `{
87+ "window.title": "${ defaultTitle } (${ ecosystem } )"
88+ }`
89+ await fs . writeFile ( '.vscode/settings.json' , output )
90+ } else {
91+ const output = settingsText . replace (
92+ / [ \t ] * { / m,
93+ `{\n\t"window.title": "${ defaultTitle } (${ ecosystem } )",` ,
94+ )
95+ await fs . writeFile ( '.vscode/settings.json' , output )
96+ }
97+ }
98+
6799 const ruleFiles : string [ ] = [ ]
68100 const collect = async ( pattern : string ) => {
69101 const matches = await globby ( pattern , {
@@ -255,34 +287,31 @@ async function fixFromFile(
255287 if ( shouldRunFix ) {
256288 await issue . fix ( )
257289 } else {
258- printWithTips ( `[${ styleText ( 'red' , 'FAIL' ) } ] ${ fixId } ` , [
259- 'Failed because the fix function was not executed' ,
260- ] )
261- failed = true
262- break
290+ console . info ( `[${ styleText ( 'yellow' , 'SKIP' ) } ] ${ fixId } ` )
291+ return
263292 }
264293 }
265294
266295 if ( ! failed ) {
267296 console . info ( `[${ styleText ( 'green' , 'PASS' ) } ] ${ fixId } ` )
268297 } else {
269- process . exit ( 1 )
298+ Deno . exit ( 1 )
270299 }
271300 } catch ( err ) {
272301 printWithTips ( `[${ styleText ( 'red' , 'FAIL' ) } ] ${ fixId } ` , [
273302 'Failed because an error was caught' ,
274303 ] )
275304 console . error ( err )
276- process . exit ( 1 )
305+ Deno . exit ( 1 )
277306 }
278307}
279308
280309async function getProject ( ) : Promise < Project > {
281310 if ( ! ( await fileExists ( '.git' ) ) ) {
282311 return {
283312 type : 'only-directory' ,
284- rootDir : process . cwd ( ) ,
285- name : path . basename ( process . cwd ( ) ) ,
313+ rootDir : Deno . cwd ( ) ,
314+ name : path . basename ( Deno . cwd ( ) ) ,
286315 }
287316 }
288317
@@ -321,8 +350,8 @@ async function getProject(): Promise<Project> {
321350 if ( ! remoteName ) {
322351 return {
323352 type : 'under-version-control' ,
324- rootDir : process . cwd ( ) ,
325- name : path . basename ( process . cwd ( ) ) ,
353+ rootDir : Deno . cwd ( ) ,
354+ name : path . basename ( Deno . cwd ( ) ) ,
326355 branchName,
327356 }
328357 }
@@ -337,12 +366,12 @@ async function getProject(): Promise<Project> {
337366 `Failed to extract repository name and owner for remote name "${ remoteName } "` ,
338367 [ `Remote name has URL of "${ remoteUrl } "` ] ,
339368 )
340- process . exit ( 1 )
369+ Deno . exit ( 1 )
341370 }
342371
343372 return {
344373 type : 'with-remote-url' ,
345- rootDir : process . cwd ( ) ,
374+ rootDir : Deno . cwd ( ) ,
346375 name : match . groups . name ,
347376 branchName,
348377 remoteName,
@@ -351,64 +380,6 @@ async function getProject(): Promise<Project> {
351380 }
352381}
353382
354- export async function getEcosystems ( rootDir : string ) : Promise < string [ ] > {
355- using _ = ( ( origDir : string ) => ( {
356- [ Symbol . dispose ] : ( ) => Deno . chdir ( origDir ) ,
357- } ) ) ( Deno . cwd ( ) )
358- Deno . chdir ( rootDir )
359-
360- const ecosystems : string [ ] = [ ]
361-
362- if ( await fileExists ( 'package.json' ) ) {
363- ecosystems . push ( 'nodejs' )
364-
365- const content : PackageJson = JSON . parse (
366- await fs . readFile ( 'package.json' , 'utf-8' ) ,
367- )
368- if ( content . displayName ) {
369- ecosystems . push ( 'vscode-extension' )
370- }
371- }
372-
373- if ( ( await fileExists ( 'deno.jsonc' ) ) || ( await fileExists ( 'deno.json' ) ) ) {
374- ecosystems . push ( 'deno' )
375- }
376-
377- if ( ( await globby ( '*.c' ) ) . length > 0 ) {
378- ecosystems . push ( 'c' )
379- }
380-
381- // https://cmake.org/cmake/help/latest/command/project.html
382- if ( await fileExists ( 'CMakeLists.txt' ) ) {
383- const content = await fs . readFile ( 'CMakeLists.txt' , 'utf-8' )
384- const language = content . match (
385- / p r o j e c t \( (?: .* ? (?< lang > [ a - z A - Z ] + ) \) | .* ?L A N G U A G E S [ \t ] + (?< lang > [ a - z A - Z ] + ) ) / ,
386- )
387- if ( language ?. groups ?. lang === 'C' ) {
388- ecosystems . push ( 'c' )
389- } else if ( language ?. groups ?. lang === 'CXX' ) {
390- ecosystems . push ( 'cpp' )
391- } else {
392- // TODO
393- console . error (
394- `CMAkeLists.txt should have language defined in project()` ,
395- )
396- process . exit ( 1 )
397- }
398- }
399-
400- if ( await fileExists ( 'basalt.toml' ) ) {
401- ecosystems . push ( 'bash' )
402- }
403-
404- // https://zed.dev/docs/extensions/developing-extensions
405- if ( await fileExists ( 'extension.toml' ) ) {
406- ecosystems . push ( 'zed-extension' )
407- }
408-
409- return ecosystems
410- }
411-
412383function printWithTips ( str : string , tips : string [ ] ) {
413384 console . info ( str )
414385 for ( const tip of tips ) {
0 commit comments