rufo 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +4 -0
- data/.rufo +0 -22
- data/.travis.yml +4 -4
- data/CHANGELOG.md +51 -0
- data/Guardfile +5 -0
- data/README.md +39 -70
- data/docs/developing-rufo.md +17 -0
- data/docs/releasing-a-gem.md +17 -0
- data/docs/settings.md +219 -0
- data/lib/rufo.rb +1 -1
- data/lib/rufo/command.rb +64 -20
- data/lib/rufo/dot_file.rb +26 -0
- data/lib/rufo/formatter.rb +137 -289
- data/lib/rufo/settings.rb +27 -0
- data/lib/rufo/version.rb +1 -1
- data/rufo.gemspec +1 -0
- metadata +24 -4
- data/lib/rufo/formatter/settings.rb +0 -198
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 568bbd1f6cd032ca58647141b94d48748688a1af
|
4
|
+
data.tar.gz: f4d143cd048591f4a98869d7709384fdfd8b362c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0854453cd81dbaaa44175c794c595ce171de33320b2c51ba2e5a6f61dec76f175e82c0a0c572d1826aca71ff289f777d01c2ea283ba9713a7bed643123a31f30'
|
7
|
+
data.tar.gz: 1c6469b61a0f9601a48a93811df18131fae20ff226965cbd7962f92b7427d17d7d98a8fb9c157cb2074794707d671126377573b3329aa1936b4d18045a9e5470
|
data/.rufo
CHANGED
@@ -1,24 +1,2 @@
|
|
1
|
-
indent_size 2
|
2
|
-
spaces_inside_hash_brace :never
|
3
|
-
spaces_inside_array_bracket :never
|
4
|
-
spaces_around_equal :one
|
5
|
-
spaces_in_ternary :one
|
6
|
-
spaces_in_suffix :one
|
7
|
-
spaces_in_commands :dynamic
|
8
|
-
spaces_around_block_brace :one
|
9
|
-
spaces_after_comma :dynamic
|
10
|
-
spaces_around_hash_arrow :one
|
11
|
-
spaces_around_when :one
|
12
|
-
spaces_around_dot :no
|
13
|
-
spaces_after_lambda_arrow :no
|
14
|
-
spaces_around_unary :no
|
15
|
-
spaces_around_binary :one
|
16
|
-
parens_in_def :yes
|
17
|
-
double_newline_inside_type :no
|
18
|
-
visibility_indent :align
|
19
|
-
trailing_commas :always
|
20
|
-
align_comments true
|
21
|
-
align_assignments false
|
22
|
-
align_hash_keys false
|
23
1
|
align_case_when true
|
24
2
|
align_chained_calls true
|
data/.travis.yml
CHANGED
@@ -2,10 +2,10 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
|
-
- 2.4.
|
6
|
-
- 2.3.
|
7
|
-
- 2.2.
|
5
|
+
- 2.4.2
|
6
|
+
- 2.3.5
|
7
|
+
- 2.2.8
|
8
8
|
- ruby-head
|
9
|
-
before_install: gem install bundler -v 1.15.
|
9
|
+
before_install: gem install bundler -v 1.15.4
|
10
10
|
script:
|
11
11
|
- bundle exec rake ci
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.2.0] - 2017-11-13
|
10
|
+
### Changed
|
11
|
+
Config parsing and handling:
|
12
|
+
- No longer using `eval` to parse config files
|
13
|
+
- Warnings have been added for invalid config keys and values
|
14
|
+
|
15
|
+
The default for the following options has changed:
|
16
|
+
- parens_in_def: `:dynamic` > `:yes`
|
17
|
+
- trailing_commas: `:dynamic` > `true`
|
18
|
+
|
19
|
+
Valid options for:
|
20
|
+
- trailing_commas: `[:always, :never]` > `[true, false]`
|
21
|
+
|
22
|
+
### Removed
|
23
|
+
The following configuration options have been **removed**, and replaced with non-configurable sane defaults, [per discussion](https://github.com/ruby-formatter/rufo/issues/2):
|
24
|
+
- align_assignments
|
25
|
+
- align_comments
|
26
|
+
- align_hash_keys
|
27
|
+
- indent_size
|
28
|
+
- spaces_after_comma
|
29
|
+
- spaces_after_lambda_arrow
|
30
|
+
- spaces_around_block_brace
|
31
|
+
- spaces_around_dot
|
32
|
+
- spaces_around_equal
|
33
|
+
- spaces_around_hash_arrow
|
34
|
+
- spaces_around_unary
|
35
|
+
- spaces_around_when
|
36
|
+
- spaces_in_commands
|
37
|
+
- spaces_in_suffix
|
38
|
+
- spaces_in_ternary
|
39
|
+
- spaces_inside_array_bracket
|
40
|
+
- spaces_inside_hash_brace
|
41
|
+
- visibility_indent
|
42
|
+
- double_newline_inside_type
|
43
|
+
- spaces_around_binary
|
44
|
+
|
45
|
+
### Fixed
|
46
|
+
- Fix crash in Ruby <= 2.3.4, <= 2.4.1 in the presence of certain squiggly doc (`<<~`) with multiple embedded expressions. The real fix here is to upgrade Ruby to >= 2.3.5 / >= 2.4.2
|
47
|
+
- Fix dedent bug and bad formatting caused by comments within chained calls (issue [#49](https://github.com/ruby-formatter/rufo/issues/49))
|
48
|
+
- Fix formatting bug for `for i, in [[1, 2]] ; x ; end` (issue [#45](https://github.com/ruby-formatter/rufo/issues/45))
|
49
|
+
|
50
|
+
## [0.1.0] - 2017-10-08
|
51
|
+
Beginning of logging changes!
|
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,23 +1,48 @@
|
|
1
1
|
# Rufo
|
2
2
|
|
3
3
|
[](https://travis-ci.org/ruby-formatter/rufo)
|
4
|
+
[](https://rubygems.org/gems/rufo)
|
4
5
|
|
5
6
|
**Ru**by **fo**rmatter
|
6
7
|
|
7
|
-
## Why
|
8
8
|
|
9
|
-
Rufo
|
10
|
-
on demand. For this reason it needs to be fast. If the formatter is slow, saving
|
11
|
-
a file becomes painful.
|
9
|
+
Rufo is as an _opinionated_ ruby formatter, intended to be used via the command line as a text-editor plugin, to autoformat files on save or on demand.
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
Unlike the best known Ruby formatter [RuboCop](https://github.com/bbatsov/rubocop), Rufo offers little in the way of configuration. Like other language formatters such as [gofmt](https://golang.org/cmd/gofmt/), [prettier](https://github.com/prettier/prettier), and [autopep8](https://github.com/hhatto/autopep8), we strive to find a "one true format" for Ruby code, and make sure your code adheres to it, with zero config where possible.
|
12
|
+
|
13
|
+
RuboCop does much more than just format code though, so feel free to run them both!
|
14
|
+
|
15
|
+
Rufo supports all Ruby versions >= 2.2.4, but works most reliably with >= 2.3.**5** / >= 2.4.**2**, due to a bug in Ruby's Ripper parser.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'rufo'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it system wide with:
|
30
|
+
|
31
|
+
$ gem install rufo
|
32
|
+
|
33
|
+
## Editor support
|
34
|
+
|
35
|
+
Once the gem is installed, enable format on save integration in your editor of choice with the following libraries:
|
36
|
+
|
37
|
+
- Atom: [rufo-atom](https://github.com/bmulvihill/rufo-atom) :construction:
|
38
|
+
- Emacs [emacs-rufo](https://github.com/aleandros/emacs-rufo) :construction: or [rufo.el](https://github.com/danielma/rufo.el)
|
39
|
+
- Sublime Text: [sublime-rufo](https://github.com/ruby-formatter/sublime-rufo)
|
40
|
+
- Vim: [rufo-vim](https://github.com/splattael/rufo-vim)
|
41
|
+
- Visual Studio Code: [vscode-rufo](https://marketplace.visualstudio.com/items?itemName=mbessey.vscode-rufo) or [rufo-vscode](https://marketplace.visualstudio.com/items?itemName=siliconsenthil.rufo-vscode)
|
42
|
+
|
43
|
+
If you're interested in developing your own plugin check out the [development docs](docs/developing-rufo.md). Did you already write a plugin? That's great! Let us know about it and
|
44
|
+
we will list it here.
|
16
45
|
|
17
|
-
There's at least one other good Ruby formatter I know: [RuboCop](https://github.com/bbatsov/rubocop).
|
18
|
-
However, it takes between 2 and 5 seconds to format a 3000+ lines file, and about 1 second to format
|
19
|
-
a 500 lines file. A second is too much delay for a plugin editor. Additionally, RuboCop is much more
|
20
|
-
than just a code formatter. Rufo is and will always be a code formatter.
|
21
46
|
|
22
47
|
## Unobtrusive by default
|
23
48
|
|
@@ -48,7 +73,7 @@ register :action, "Save"
|
|
48
73
|
```
|
49
74
|
|
50
75
|
Here too, an extra space is added to align `"Format"` with `"Save"`. Again, Rufo will preserve
|
51
|
-
this choice.
|
76
|
+
this choice, while still enforcing that truly badly aligned code is formatted.
|
52
77
|
|
53
78
|
Another example is aligning call parameters:
|
54
79
|
|
@@ -90,36 +115,6 @@ All of the alignment choices above are fine depending on the context where they
|
|
90
115
|
used, and Rufo will not destroy that choice. It will, however, keep things aligned
|
91
116
|
so they look good.
|
92
117
|
|
93
|
-
If Rufo does not change these things by default, what does it do? Well, it makes sure that:
|
94
|
-
|
95
|
-
- code at the beginning of a line is correctly indented
|
96
|
-
- array and hash elements are aligned
|
97
|
-
- there are no spaces **before** commas
|
98
|
-
- there are no more than one consecutive empty lines
|
99
|
-
- methods are separated by an empty line
|
100
|
-
- no trailing semicolons remain
|
101
|
-
- no trailing whitespace remains
|
102
|
-
- a trailing newline at the end of the file remains
|
103
|
-
|
104
|
-
And of course it can be configured to do much more.
|
105
|
-
Check the [Settings](https://github.com/ruby-formatter/rufo/wiki/Settings) section in the [Wiki](https://github.com/ruby-formatter/rufo/wiki) for more details.
|
106
|
-
|
107
|
-
## Installation
|
108
|
-
|
109
|
-
Add this line to your application's Gemfile:
|
110
|
-
|
111
|
-
```ruby
|
112
|
-
gem 'rufo'
|
113
|
-
```
|
114
|
-
|
115
|
-
And then execute:
|
116
|
-
|
117
|
-
$ bundle
|
118
|
-
|
119
|
-
Or install it yourself as:
|
120
|
-
|
121
|
-
$ gem install rufo
|
122
|
-
|
123
118
|
## Usage
|
124
119
|
|
125
120
|
### Format files or directories
|
@@ -151,41 +146,15 @@ according to **Rufo**, and will exit with exit code 3.
|
|
151
146
|
| `1` | Error. Either `Ripper` could not parse syntax or input file is missing |
|
152
147
|
| `3` | Input changed. Formatted code differs from input |
|
153
148
|
|
154
|
-
## Editor support
|
155
|
-
|
156
|
-
- Atom: [rufo-atom](https://github.com/bmulvihill/rufo-atom) :construction:
|
157
|
-
- Emacs [emacs-rufo](https://github.com/aleandros/emacs-rufo) :construction: or [rufo.el](https://github.com/danielma/rufo.el)
|
158
|
-
- Sublime Text: [sublime-rufo](https://github.com/ruby-formatter/sublime-rufo)
|
159
|
-
- Vim: [rufo-vim](https://github.com/splattael/rufo-vim)
|
160
|
-
- Visual Studio Code: [rufo-vscode](https://marketplace.visualstudio.com/items?itemName=siliconsenthil.rufo-vscode) or [vscode-rufo](https://marketplace.visualstudio.com/items?itemName=mbessey.vscode-rufo)
|
161
|
-
|
162
|
-
|
163
|
-
Did you write a plugin for your favorite editor? That's great! Let me know about it and
|
164
|
-
I will list it here.
|
165
|
-
|
166
|
-
### Tips for editor plugin implementors
|
167
|
-
|
168
|
-
It is especially convenient if your code is automatically _formatted on save_.
|
169
|
-
For example, surrounding a piece of code with `if ... end` will automatically indent
|
170
|
-
the code when you save. Likewise, it will be automatically unindented should you remove it.
|
171
|
-
|
172
|
-
For this to work best, the cursor position must be preserved, otherwise it becomes
|
173
|
-
pretty annoying if the cursor is reset to the top of the editor.
|
174
|
-
|
175
|
-
You should compute a diff between the old content and new content
|
176
|
-
and apply the necessary changes. You can check out how this is done in the
|
177
|
-
[Sublime Text plugin for Rufo](https://github.com/ruby-formatter/sublime-rufo):
|
178
|
-
|
179
|
-
- [diff_match_patch.py](https://github.com/ruby-formatter/sublime-rufo/blob/master/diff_match_patch.py) contains the diff algorithm (you can port it to other languages or try to search for a similar algorithm online)
|
180
|
-
- [rufo_format.py](https://github.com/ruby-formatter/sublime-rufo/blob/master/rufo_format.py#L46-L53) consumes the diff result and applies it chunk by chunk in the editor's view
|
181
149
|
|
182
150
|
## Configuration
|
183
151
|
|
152
|
+
Rufo supports limited configuration.
|
184
153
|
To configure Rufo, place a `.rufo` file in your project. Then when you format a file or a directory,
|
185
154
|
Rufo will look for a `.rufo` file in that directory or parent directories and apply the configuration.
|
186
155
|
|
187
156
|
The `.rufo` file is a Ruby file that is evaluated in the context of the formatter.
|
188
|
-
The available settings are listed [here](
|
157
|
+
The available settings are listed [here](docs/settings.md).
|
189
158
|
|
190
159
|
## How it works
|
191
160
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Rufo Development
|
2
|
+
|
3
|
+
## Tips for editor plugin implementors
|
4
|
+
|
5
|
+
It is especially convenient if your code is automatically _formatted on save_.
|
6
|
+
For example, surrounding a piece of code with `if ... end` will automatically indent
|
7
|
+
the code when you save. Likewise, it will be automatically unindented should you remove it.
|
8
|
+
|
9
|
+
For this to work best, the cursor position must be preserved, otherwise it becomes
|
10
|
+
pretty annoying if the cursor is reset to the top of the editor.
|
11
|
+
|
12
|
+
You should compute a diff between the old content and new content
|
13
|
+
and apply the necessary changes. You can check out how this is done in the
|
14
|
+
[Sublime Text plugin for Rufo](https://github.com/ruby-formatter/sublime-rufo):
|
15
|
+
|
16
|
+
- [diff_match_patch.py](https://github.com/ruby-formatter/sublime-rufo/blob/master/diff_match_patch.py) contains the diff algorithm (you can port it to other languages or try to search for a similar algorithm online)
|
17
|
+
- [rufo_format.py](https://github.com/ruby-formatter/sublime-rufo/blob/master/rufo_format.py#L46-L53) consumes the diff result and applies it chunk by chunk in the editor's view
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Releasing a gem
|
2
|
+
|
3
|
+
1. Ensure that the tests pass and everything is working!
|
4
|
+
|
5
|
+
2. Add missing release notes to `CHANGELOG.md`
|
6
|
+
|
7
|
+
3. Bump version in
|
8
|
+
* `lib/rufo/version.rb`
|
9
|
+
* `CHANGELOG.md`
|
10
|
+
|
11
|
+
4. Commit version bump via
|
12
|
+
* `git commit -v "Version X.Y.Z"`
|
13
|
+
|
14
|
+
5. Release gem to RubyGems via
|
15
|
+
* `rake release`
|
16
|
+
|
17
|
+
6. :tada:
|
data/docs/settings.md
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
# Settings
|
2
|
+
|
3
|
+
Rufo supports limited configuration.
|
4
|
+
To configure Rufo, place a `.rufo` file in your project.
|
5
|
+
Each configuration is a call with one argument. For example:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# .rufo
|
9
|
+
trailing_commas false
|
10
|
+
parens_in_def :dynamic
|
11
|
+
```
|
12
|
+
|
13
|
+
## :warning: Settings are going away! :warning:
|
14
|
+
|
15
|
+
The settings described below will be removed from future versions of rufo :skull:
|
16
|
+
|
17
|
+
See https://github.com/ruby-formatter/rufo/issues/2 for more context!
|
18
|
+
|
19
|
+
## Table of contents
|
20
|
+
|
21
|
+
- [align_case_when](#align_case_when)
|
22
|
+
- [align_chained_calls](#align_chained_calls)
|
23
|
+
- [parens_in_def](#parens_in_def)
|
24
|
+
- [trailing_commas](#trailing_commas)
|
25
|
+
|
26
|
+
### align_case_when
|
27
|
+
|
28
|
+
Align successive case when?
|
29
|
+
|
30
|
+
- `false`: (default) don't align case when (preserve existing code)
|
31
|
+
- `true`: align successive case when
|
32
|
+
|
33
|
+
Given this code:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
case exp
|
37
|
+
when foo then 2
|
38
|
+
when barbaz then 3
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
With `true`, the formatter will change it to:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
case exp
|
46
|
+
when foo then 2
|
47
|
+
when barbaz then 3
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
With `false` it won't modify it.
|
52
|
+
|
53
|
+
### align_chained_calls
|
54
|
+
|
55
|
+
Align chained calls to the dot?
|
56
|
+
|
57
|
+
- `false`: (default) don't align chained calls to the dot (preserve existing code)
|
58
|
+
- `true`: align chained calls to the dot
|
59
|
+
|
60
|
+
Given this code:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
foo.bar
|
64
|
+
.baz
|
65
|
+
|
66
|
+
foo.bar
|
67
|
+
.baz
|
68
|
+
```
|
69
|
+
|
70
|
+
With `true`, the formatter will change it to:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
foo.bar
|
74
|
+
.baz
|
75
|
+
|
76
|
+
foo.bar
|
77
|
+
.baz
|
78
|
+
```
|
79
|
+
|
80
|
+
With `false` it won't modify it.
|
81
|
+
|
82
|
+
Note that with `false` it will keep it aligned to the dot if it's already like that.
|
83
|
+
|
84
|
+
### parens_in_def
|
85
|
+
|
86
|
+
Use parentheses in defs?
|
87
|
+
|
88
|
+
- `:yes`: (default) always use parentheses (add them if they are not there)
|
89
|
+
- `:dynamic`: don't modify existing methods parentheses choice
|
90
|
+
|
91
|
+
Given this code:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
def foo x, y
|
95
|
+
end
|
96
|
+
|
97
|
+
def bar(x, y)
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
With `:yes` the formatter will change it to:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
def foo(x, y)
|
105
|
+
end
|
106
|
+
|
107
|
+
def bar(x, y)
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
With `:dynamic` it won't modify it.
|
112
|
+
|
113
|
+
### trailing_commas
|
114
|
+
|
115
|
+
Use trailing commas in array and hash literals, and keyword arguments?
|
116
|
+
|
117
|
+
- `:always`: (default) always put a trailing comma
|
118
|
+
- `:never`: never put a trailing comma
|
119
|
+
|
120
|
+
Given this code:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
[
|
124
|
+
1,
|
125
|
+
2
|
126
|
+
]
|
127
|
+
|
128
|
+
[
|
129
|
+
1,
|
130
|
+
2,
|
131
|
+
]
|
132
|
+
|
133
|
+
{
|
134
|
+
foo: 1,
|
135
|
+
bar: 2
|
136
|
+
}
|
137
|
+
|
138
|
+
{
|
139
|
+
foo: 1,
|
140
|
+
bar: 2,
|
141
|
+
}
|
142
|
+
|
143
|
+
foo(
|
144
|
+
x: 1,
|
145
|
+
y: 2
|
146
|
+
)
|
147
|
+
|
148
|
+
foo(
|
149
|
+
x: 1,
|
150
|
+
y: 2,
|
151
|
+
)
|
152
|
+
```
|
153
|
+
|
154
|
+
With `:always`, the formatter will change it to:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
[
|
158
|
+
1,
|
159
|
+
2,
|
160
|
+
]
|
161
|
+
|
162
|
+
[
|
163
|
+
1,
|
164
|
+
2,
|
165
|
+
]
|
166
|
+
|
167
|
+
{
|
168
|
+
foo: 1,
|
169
|
+
bar: 2,
|
170
|
+
}
|
171
|
+
|
172
|
+
{
|
173
|
+
foo: 1,
|
174
|
+
bar: 2,
|
175
|
+
}
|
176
|
+
|
177
|
+
foo(
|
178
|
+
x: 1,
|
179
|
+
y: 2,
|
180
|
+
)
|
181
|
+
|
182
|
+
foo(
|
183
|
+
x: 1,
|
184
|
+
y: 2,
|
185
|
+
)
|
186
|
+
```
|
187
|
+
With `:never`, the formatter will change it to:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
[
|
191
|
+
1,
|
192
|
+
2
|
193
|
+
]
|
194
|
+
|
195
|
+
[
|
196
|
+
1,
|
197
|
+
2
|
198
|
+
]
|
199
|
+
|
200
|
+
{
|
201
|
+
foo: 1,
|
202
|
+
bar: 2
|
203
|
+
}
|
204
|
+
|
205
|
+
{
|
206
|
+
foo: 1,
|
207
|
+
bar: 2
|
208
|
+
}
|
209
|
+
|
210
|
+
foo(
|
211
|
+
x: 1,
|
212
|
+
y: 2
|
213
|
+
)
|
214
|
+
|
215
|
+
foo(
|
216
|
+
x: 1,
|
217
|
+
y: 2
|
218
|
+
)
|
219
|
+
```
|