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 passing flags to rubyfmt binary #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ If your file contains syntax errors it won't be formatted. The syntax error will

## Format on Save / Other settings

Format on save is enabled by default but can be disabled from `Sublime Text -> Preferences -> Package Settings -> Rubyfmt -> Settings - User` and adding `{"format_on_save: false"}`.
* Format on save is enabled by default but can be disabled from `Sublime Text -> Preferences -> Package Settings -> Rubyfmt -> Settings - User` and adding `{"format_on_save: false"}`.
* `rubyfmt_flags` can be added to use `--header-opt-in` or `--header-opt-out` behaviors.

All settings with default values:

```json
{
"ruby_executable": "ruby",
"rubyfmt_executable": "rubyfmt",
"rubyfmt_flags": "",
"format_on_save": true,
}
```
Expand Down
3 changes: 2 additions & 1 deletion Rubyfmt.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ruby_executable": "ruby",
"rubyfmt_executable": "rubyfmt",
"rubyfmt_flags": "",
"format_on_save": true,
}
}
8 changes: 7 additions & 1 deletion format_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ def check_syntax(self, bytes):
def format_bytes(self, bytes):
ruby_executable = self.settings.get("ruby_executable", "ruby")
rubyfmt_executable = self.settings.get("rubyfmt_executable", "rubyfmt")
command = [rubyfmt_executable]
rubyfmt_flags = self.settings.get("rubyfmt_flags", None)

flags = []
if type(rubyfmt_flags) is str:
flags = rubyfmt_flags.split()

command = [rubyfmt_executable] + flags

formatter = subprocess.Popen(command,
stdout=subprocess.PIPE,
Expand Down