-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and allow to configure rubocop formatter (#403)
* fix(formatter): avoid temporary files when formatting with RuboCop By supplying the file content to RubyCop as a in-memory string the same way as RuboCop's own CLI tool handles STDIN, we completely avoid having to write any temporary files to disk, and formatting can occur purely in-memory. This also has the benefit of Solargraph no longer needing to be responsible for finding and passing along any config file paths. RuboCop will correctly find any relevant .rubocop.yml files for the file being formatted, as RuboCop behaves exactly as if it was running against the real file in it's original location on disk, except with the content it is formatting coming from the in-memory string rather than reading it from the file on disk. A new blank formatter is also passed to RuboCop, just to make it print as little as possible to STDOUT, since we don't need and ignore the STDOUT produced. * feat(formatter): add "formatter" option to .solargraph.yml Allows customizing if format command should run safe, or all cops when formatting files. Also includes a `extra_args` option to pass custom CLI arguments to RuboCop. If you primarily only format via solargraph interactively from an editor, it might be useful to disable certain cops that causes annoyances in interactive use. For example: formatter: cops: safe # use "all" to include unsafe cops extra_args: - --except - Lint/Debugger,Lint/UnusedBlockArgument,Lint/UnusedMethodArgument,Style/EmptyMethod * chore(diagnostics): don't pass .rubocop.yml file path to RuboCop RuboCop will itself find and use any relevant configuration files based on the file path of the file it is analyzing. Hence there is no need for Solargraph to have it's own implementation of this logic. * chore(formatter): future proof rubocop formatter configuration structure Solargraph will gain support for multiple formatters soon, so let's ensure configuration for the rubocop formatter is future proof. New nested configuration: formatter: rubocop: cops: all extra_args: [] Previously: formatter: cops: all extra_args: [] * feat(formatter): add "except" and "only" rubocop formatter options They take a list or comma separated string of cops, which will be passed to rubocop as --except and/or --only. The "except" option is useful to disable cops which can cause annoyance when using solargraph's formatter as a before save hook in text editors. I'm less aware of what the "only" option might be useful for, but might as well add it so both are covered.
- Loading branch information
Showing
6 changed files
with
68 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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