-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: sqlfluff to allow config file other than .sqlfluff #4562
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@@ -19,7 +22,7 @@ function! ale_linters#sql#sqlfluff#Command(buffer) abort | |||
\ ale#Escape(l:executable) | |||
\ . ' lint' | |||
|
|||
let l:config_file = ale#path#FindNearestFile(a:buffer, '.sqlfluff') | |||
let l:config_file = ale#path#FindNearestFile(a:buffer, ale#Var(a:buffer, 'sql_sqlfluff_config_file')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of manually specifying the location of the configuration file or adding an option for which file to use, I wonder if we can edit the linter command by prefixing the command with a work directory so sqlfluff automatically determines which configuration file to load. The project specifies some behaviour for searching for configuration files. https://docs.sqlfluff.com/en/2.1.4/configuration.html#nesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@w0rp tbh that would be much preferred.
My original idea was to replace %t
with %s
in the linter and fixer and let the tool determines which configuration to load. The reason why it didn't load was because the linter/fixer was pointed to %t and it couldn't find any config files. Alternatively using cwd
could probably help ?
I just recently migrated to ale from null-ls and not the author of the original code, so I wasn't sure if replacing the command with %s
for both linter and fixer will have unintended consequences so I tried to make the code to be as backward compatible as possible.
Appreciate the guidance 🙏🏽 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to get it to work by adding 'cwd': '%s:h'
to the linter config. You can look at the rstcheck.vim
file for an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to get it to work by adding
'cwd': '%s:h'
to the linter config. You can look at therstcheck.vim
file for an example.
I've tried adding this, but doesn't really help in my case; e.g., my directory structure would be something like
repo # Project working directory
├── pyproject.toml # The config I want applied
└── queries
└── query.sql # The file I'm editing
So, if I start vim from the project root (in this case, repo
), open queries/query.sql
, then cwd
for the linter is set to repo/queires
instead of repo
, and sqlfluff
fails to find pyproject.toml
; i.e., the lint command is
['bash', '-c', 'cd ''/repo/queries'' && ''sqlfluff'' lint ...]
instead of the desired
['bash', '-c', 'cd ''/repo'' && ''sqlfluff'' lint ...]
If I run sqlfluff
from vim
directly (e.g., :!sqlfluff lint %
) it does find the correct config; so it looks like vim
"knows" the correct cwd
, but I couldn't find any format strings in ale-command-format-strings
that would give me that path.
This pull request has been automatically marked as stale because it has not been updated recently. Make sure to write tests and document your changes. See |
This pull request has been automatically marked as stale because it has not been updated recently. Make sure to write tests and document your changes. See |
Closes #4554
This PR allows config file other than
.sqlfluff
to be used as listed:Adding a new variable
ale_sql_sqlfluff_config_file
to be added to allow sqlfluff to use config file nearest to the buffer.