Allow rubyfmt to be part of the "auto" formatter option
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2k
- Forks
- 281
- Avg merge
- 2h 14m
- Merged PRs (30d)
- 6
Description
I have checked that this feature is not already implemented
- This feature does not exist
Use case
Setting formatter: "auto" should check for add ons as well, if "ruby-lsp-rubyfmt" is available it should allow to fallback to rubyfmt instead of setting formatter to "none".
This is helpful in scenarios when we have to deal with multiple codebases with multiple code linting tools.
Description
I work with multiple codebases using different linters, rubyfmt, rubocop, etc. I can't set my formatter to "rubocop" or "auto", because I need "rubyfmt" for some.
The only workaround for me is to constantly change my formatter everytime I work on a different codebase.
It seems, "auto" only supports "rubocop" and "syntax trees" as these are Lsp Supported.
I propose to allow add-ons to be part of "auto" if it exists in the workspace.
Implementation
I did a quick tour of the codebase and I'm assuming while setting global state for the formatter we need to detect add-ons formatters too:
def detect_formatter(direct_dependencies, all_dependencies)
# NOTE: Intentionally no $ at end, since we want to match rubocop-shopify, etc.
return "rubocop_internal" if direct_dependencies.any?(/^rubocop/)
syntax_tree_is_direct_dependency = direct_dependencies.include?("syntax_tree")
return "syntax_tree" if syntax_tree_is_direct_dependency
rubocop_is_transitive_dependency = all_dependencies.include?("rubocop")
return "rubocop_internal" if dot_rubocop_yml_present && rubocop_is_transitive_dependency
"none"
end
If it's accepted I can add the logic to detect add on dependencies
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the detect_formatter entry point shown in the issue and inspect how direct and transitive dependencies determine the auto formatter. Confirm the existing rubocop and syntax_tree behavior, then verify that an available ruby-lsp-rubyfmt add-on makes auto select rubyfmt instead of none without changing other cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100