sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

`.sql-formatter.json` being ignored by CLI #787

Closed musjj closed 1 month ago

musjj commented 1 month ago

Describe the bug

The .sql-formatter.json in the current directory is ignored, unless specified with --config:

$ cat .sql-formatter.json
{
  "language": "postgresql"
}

$ echo "SELECT 2 :: numeric AS foo;" | sql-formatter
Error: Parse error: Unexpected ":: numeric" at line 1 column 10.
This likely happens because you're using the default "sql" dialect.
If possible, please select a more specific dialect (like sqlite, postgresql, etc).

$ echo "SELECT 2 :: numeric AS foo;" | sql-formatter --config .sql-formatter.json
SELECT
  2::numeric AS foo;

I suspect that this is caused by this:

https://github.com/sql-formatter-org/sql-formatter/blob/2c495334f1ea78e07fea0ddd6b2ddbe9dd9f5583/bin/sql-formatter-cli.cjs#L102

Which means it defaults to searching in the installed directory instead of the current directory.

Expected behavior .sql-formatter.json should be automatically read

Actual behavior .sql-formatter.json is not automatically read

Usage

nene commented 1 month ago

Fixed in 15.4.4