Last active
November 6, 2025 23:59
-
-
Save airtonix/15cb419764ce0f641687132c45989c84 to your computer and use it in GitHub Desktop.
work around for zed not running eslint fix on older versions of eslint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| find_eslint_config() { | |
| local dir | |
| dir="$1" | |
| while [ "$dir" != "/" ]; do | |
| if [ -f "$dir/eslint.config.cjs" ]; then | |
| echo "$dir/eslint.config.cjs" | |
| return | |
| fi | |
| dir=$(dirname "$dir") | |
| done | |
| } | |
| # recieve input via stdin | |
| function eslint() { | |
| local content | |
| local filename | |
| content=$(cat) | |
| filename="$1" | |
| result=$( | |
| npx eslint \ | |
| --config "$(find_eslint_config "$(dirname "$filename")")" \ | |
| --fix-dry-run --stdin --stdin-filename "$filename" --format json <<<"$content" | |
| ) | |
| payload=$(echo "$result" | jq '.[0]') | |
| output=$(echo "$payload" | jq -r '.output // ""') | |
| source=$(echo "$payload" | jq -r '.source // ""') | |
| # if output not empty return output | |
| if [ -n "$output" ]; then | |
| echo "$output" | |
| return 0 | |
| fi | |
| # return source if not empty | |
| if [ -n "$source" ]; then | |
| echo "$source" | |
| return 0 | |
| fi | |
| echo "$content" | |
| } | |
| eslint "$1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "languages": { | |
| "TypeScript": { | |
| "formatter": { | |
| "external": { | |
| "command": ".zed/eslint", | |
| "arguments": [ | |
| "{buffer_path}" | |
| ] | |
| } | |
| }, | |
| "format_on_save": "on", | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment