Skip to content
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

Allow shfmt fixer to use .editorconfig #4244

Merged
merged 7 commits into from
Jul 2, 2022
Merged

Allow shfmt fixer to use .editorconfig #4244

merged 7 commits into from
Jul 2, 2022

Conversation

hbarcelos
Copy link
Contributor

[Fix #4233]

Motivation

As discussed in #4233, shfmt has some peculiarities that prevent it from working seamlessly standalone and from within ALE.

Currently, the shfmt fixer tries to derive the CLI arguments to pass to the executable from expandtab, shiftwidth and tabstop.

While it seems like a good default at first sight, shfmt docs state:

If any EditorConfig files are found, they will be used to apply formatting options. If any parser or printer flags are given to the tool, no EditorConfig files will be used.

This means that the current fixer is currently preventing shfmt from being customized on a more granular level with an .editorconfig. The worst part is that it's currently impossible to have project-level configuration for shfmt without resorting to things like local .vimrcs.

I have reached out to the author of shfmt (see issue #889) and came to the conclusion that the best approach is to use the -filename option to pass the original file path.

I would also like to highlight this specific comment made by the author:

You can't really specify one editorconfig file, because the spec explains how multiple can be used at once - they overlap until one "root" editorconfig file is found, or until the root of the filesystem is hit.

Given that this an implementation detail, I think the best approach is to treat it as a black-box. For that reason, I didn't try to add test cases covering the behavior of shfmt when a .editorconfig is present, just stuck to its default behavior by default.

Users are still free to configure their own CLI arguments through g:ale_sh_shfmt_option, which will still disable .editorconfig support, but that is an opt-in behavior (maybe this should be documented somewhere).

Commit List

  • refactor(shfmt-fixer): remove derivation of default CLI arguments

@hbarcelos hbarcelos changed the title Allow shfmt to use .editorconfig Allow shfmt fixer to use .editorconfig Jun 30, 2022
Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the investigation and work. Looks good, t

@hsanson hsanson merged commit d6f3d49 into dense-analysis:master Jul 2, 2022
cyyever pushed a commit to cyyever/ale that referenced this pull request Jul 11, 2022
* fix: added support for local solhint executable

* feat: added support for matching parse errors

* test: added test for solhint command callback and handler

* chore: removed command callback test

* refactor: made solhint handler structure closer to eslint

* refactor(shfmt-fixer): remove derivation of default CLI arguments
cyyever pushed a commit to cyyever/ale that referenced this pull request Jul 11, 2022
* fix: added support for local solhint executable

* feat: added support for matching parse errors

* test: added test for solhint command callback and handler

* chore: removed command callback test

* refactor: made solhint handler structure closer to eslint

* refactor(shfmt-fixer): remove derivation of default CLI arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shfmt options on .editorconfig not being applied
2 participants