this repo has no description

nvim: format ts/js with biome if configured, fallback to prettier

seth.computer b708b777 b410b0d4

verified
+20 -5
+20 -5
nvim/lua/plugins/lsp.lua
··· 109 109 languages = (function() 110 110 local prettier_config = { formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true } 111 111 local shfmt_config = { formatCommand = "shfmt -ci", formatStdin = true } 112 + -- Use a shell script to detect biome config and use appropriate formatter 113 + local js_formatter = { 114 + formatCommand = [[sh -c ' 115 + dir="$(dirname "${INPUT}")" 116 + while [ "$dir" != "/" ]; do 117 + if [ -f "$dir/biome.json" ] || [ -f "$dir/biome.jsonc" ]; then 118 + biome format --stdin-file-path "${INPUT}" 119 + exit 0 120 + fi 121 + dir="$(dirname "$dir")" 122 + done 123 + prettier --stdin-filepath "${INPUT}" 124 + ']], 125 + formatStdin = true 126 + } 112 127 113 128 return { 114 129 sh = { shfmt_config }, 115 130 bash = { shfmt_config }, 116 131 zsh = { shfmt_config }, 117 - javascript = { prettier_config }, 118 - typescript = { prettier_config }, 119 - javascriptreact = { prettier_config }, 120 - typescriptreact = { prettier_config }, 121 - json = { prettier_config }, 132 + javascript = { js_formatter }, 133 + typescript = { js_formatter }, 134 + javascriptreact = { js_formatter }, 135 + typescriptreact = { js_formatter }, 136 + json = { js_formatter }, 122 137 css = { prettier_config }, 123 138 scss = { prettier_config }, 124 139 html = { prettier_config },