rfmt 1.3.0-aarch64-linux
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 +7 -0
- data/CHANGELOG.md +223 -0
- data/LICENSE.txt +21 -0
- data/README.md +397 -0
- data/exe/rfmt +21 -0
- data/lib/rfmt/3.1/rfmt.so +0 -0
- data/lib/rfmt/3.2/rfmt.so +0 -0
- data/lib/rfmt/3.3/rfmt.so +0 -0
- data/lib/rfmt/cache.rb +112 -0
- data/lib/rfmt/cli.rb +308 -0
- data/lib/rfmt/configuration.rb +95 -0
- data/lib/rfmt/prism_bridge.rb +390 -0
- data/lib/rfmt/prism_node_extractor.rb +115 -0
- data/lib/rfmt/version.rb +5 -0
- data/lib/rfmt.rb +172 -0
- data/lib/ruby_lsp/rfmt/addon.rb +20 -0
- data/lib/ruby_lsp/rfmt/formatter_runner.rb +26 -0
- metadata +68 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8f31d662c2977021e1bd710ced7ab98329b120aa6435e067940ba801a0b33137
|
|
4
|
+
data.tar.gz: c67e61e3957e05b0627e052eac6731268667cf2394145cb31ec247258b246430
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2a8a714446ac4f11ea91244d2cca9f6c461c6d3f5fe0eabe5674904afa52e7cd7ef38ebc8e522b6669c13dfd45883cde409e57e398d5072a5836e391e41a06df
|
|
7
|
+
data.tar.gz: 6f47cc62a5ef55152899a548279bcd1ff71f09f1c3048a804fac6878aa574af86665ab9794429396d2e3c51c12a2b04a686efffe16995a3d2a9873d168fde308
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [1.3.0] - 2026-01-07
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Precompiled native gem support for multiple platforms:
|
|
7
|
+
- Linux x86_64 (glibc and musl)
|
|
8
|
+
- Linux aarch64 (glibc and musl)
|
|
9
|
+
- macOS x86_64 (Intel) and arm64 (Apple Silicon)
|
|
10
|
+
- Windows x64
|
|
11
|
+
- Users no longer need Rust toolchain (cargo) to install rfmt
|
|
12
|
+
- GitHub issue and PR templates
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Release workflow now uses `oxidize-rb/actions/cross-gem` for cross-compilation
|
|
16
|
+
- gemspec updated to exclude compiled artifacts from source gem
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- CI cross-compile compatibility: Downgrade Cargo.lock to version 3 for older Cargo
|
|
20
|
+
- Remove `.ruby-version` from repository to avoid rbenv errors in CI containers
|
|
21
|
+
|
|
22
|
+
## [1.2.7] - 2026-01-04
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- Remove OpenSSL dependency: Use mtime instead of SHA256 hash for cache invalidation
|
|
26
|
+
|
|
27
|
+
## [1.2.6] - 2026-01-04
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Version bump
|
|
31
|
+
|
|
32
|
+
## [1.2.5] - 2026-01-04
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
- Fix trailing comments on `end` keyword (e.g., `end # rubocop:disable`)
|
|
36
|
+
- Fix block internal comments being moved outside the block
|
|
37
|
+
- Fix blank line preservation between code and comments inside blocks
|
|
38
|
+
- Fix leading blank line being added to comment-only files
|
|
39
|
+
|
|
40
|
+
## [1.2.4] - 2026-01-04
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
- Fix comment indent space handling
|
|
44
|
+
|
|
45
|
+
## [1.2.3] - 2026-01-04
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
- Fix migration file formatting (`emit_rescue` handling for rescue blocks)
|
|
49
|
+
|
|
50
|
+
## [1.2.2] - 2026-01-04
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
- Ruby 3.4.1 compatibility: Use `OpenSSL::Digest::SHA256` instead of `Digest::SHA2` to avoid `metadata is not initialized properly` error in Ruby 3.4.1
|
|
54
|
+
|
|
55
|
+
## [1.2.1] - 2026-01-04
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
- Ruby 3.4 compatibility: Fix `Digest::SHA256::metadata is not initialized properly` error by using `Digest::SHA2.new(256)` instead of `Digest::SHA256`
|
|
59
|
+
|
|
60
|
+
## [1.2.0] - 2026-01-04
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
- Loop node types support (`for`, `while`, `until`)
|
|
64
|
+
- Case/When statement support
|
|
65
|
+
- Ensure and Lambda node support
|
|
66
|
+
- Begin/End block handling for explicit `begin...end` blocks
|
|
67
|
+
- High-priority node types support
|
|
68
|
+
- Medium-priority node types support
|
|
69
|
+
- Prism supported node viewer task
|
|
70
|
+
|
|
71
|
+
### Changed
|
|
72
|
+
- Consolidated and simplified test suite
|
|
73
|
+
|
|
74
|
+
### Fixed
|
|
75
|
+
- Exclude `.DS_Store` from Git tracking (@topi0247)
|
|
76
|
+
- Repository URL changed from `fujitanisora` to `fs0414` (@topi0247)
|
|
77
|
+
- End line space handling
|
|
78
|
+
- Comment location fix
|
|
79
|
+
- End expression indent fix
|
|
80
|
+
- Begin formatting fix
|
|
81
|
+
|
|
82
|
+
## [1.1.0] - 2025-12-12
|
|
83
|
+
|
|
84
|
+
### Added
|
|
85
|
+
- Editor integration (Ruby LSP support)
|
|
86
|
+
- Required/Optional keyword parameter node type support
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
- Migration file superclass corruption (ActiveRecord::Migration[8.1] etc.)
|
|
90
|
+
|
|
91
|
+
### Changed
|
|
92
|
+
- Removed unused scripts and test files (reduced Ruby code by ~38%)
|
|
93
|
+
|
|
94
|
+
## [1.0.0] - 2025-12-11
|
|
95
|
+
|
|
96
|
+
### Breaking Changes
|
|
97
|
+
- First stable release (v1.0.0)
|
|
98
|
+
|
|
99
|
+
### Added
|
|
100
|
+
- Neovim integration: format-on-save support with autocmd configuration
|
|
101
|
+
|
|
102
|
+
### Changed
|
|
103
|
+
- Set JSON as default output format
|
|
104
|
+
- Updated Japanese documentation
|
|
105
|
+
- Code formatting improvements
|
|
106
|
+
|
|
107
|
+
### Fixed
|
|
108
|
+
- TOML configuration parsing fix
|
|
109
|
+
- Logger initialization fix
|
|
110
|
+
|
|
111
|
+
## [0.5.0] - 2025-12-07
|
|
112
|
+
|
|
113
|
+
### Changed
|
|
114
|
+
- Synchronized markdown command documentation
|
|
115
|
+
- Added project logo
|
|
116
|
+
|
|
117
|
+
### Fixed
|
|
118
|
+
- Removed unnecessary exec command
|
|
119
|
+
|
|
120
|
+
## [0.4.1] - 2025-11-28
|
|
121
|
+
|
|
122
|
+
### Fixed
|
|
123
|
+
- CLI exec message output optimization for better user experience
|
|
124
|
+
- RuboCop compliance issues resolved
|
|
125
|
+
|
|
126
|
+
### Changed
|
|
127
|
+
- Improved output formatting with colored success/failure messages
|
|
128
|
+
- Debug logs now only shown with `--verbose` flag or debug environment variables
|
|
129
|
+
- Enhanced progress indicators during file processing
|
|
130
|
+
|
|
131
|
+
## [0.4.0] - 2025-11-26
|
|
132
|
+
|
|
133
|
+
### Added
|
|
134
|
+
- Verbose mode option (`--verbose` flag) for detailed output during formatting
|
|
135
|
+
- Git commit hook configuration with Lefthook integration for automatic formatting
|
|
136
|
+
- RubyGems badge and installation instructions in README
|
|
137
|
+
|
|
138
|
+
### Changed
|
|
139
|
+
- Improved documentation structure and readability in user guides (English and Japanese)
|
|
140
|
+
- Enhanced logging system with verbose output support
|
|
141
|
+
- Updated benchmark documentation in README
|
|
142
|
+
|
|
143
|
+
### Fixed
|
|
144
|
+
- Command formatting to execution conversion issues
|
|
145
|
+
- Documentation version command display
|
|
146
|
+
- Various code quality improvements based on Clippy suggestions
|
|
147
|
+
|
|
148
|
+
## [0.3.0] - 2025-11-25
|
|
149
|
+
|
|
150
|
+
### Changed
|
|
151
|
+
- **BREAKING**: Default configuration file name changed from `rfmt.yml` to `.rfmt.yml`
|
|
152
|
+
- `rfmt init` now creates `.rfmt.yml` instead of `rfmt.yml`
|
|
153
|
+
- Configuration file search order updated: `.rfmt.yml` > `.rfmt.yaml` > `rfmt.yml` > `rfmt.yaml`
|
|
154
|
+
- This follows Ruby community conventions for hidden configuration files
|
|
155
|
+
- Backward compatibility maintained: `rfmt.yml` is still supported
|
|
156
|
+
- Updated README.md to use `.rfmt.yml` in all examples and documentation
|
|
157
|
+
- Updated benchmark data with latest accurate measurements (3,241 lines, more realistic performance ratios)
|
|
158
|
+
- Removed exaggerated performance claims from README and documentation
|
|
159
|
+
- Simplified feature descriptions in README (removed Error Handling and Logging from Features section)
|
|
160
|
+
|
|
161
|
+
### Documentation
|
|
162
|
+
- Updated user guides (English and Japanese) to reflect `.rfmt.yml` as default
|
|
163
|
+
- Updated version information in documentation to 0.2.4 → 0.3.0
|
|
164
|
+
- Updated benchmark documentation with accurate data from latest measurements
|
|
165
|
+
- Added configuration verification examples in examples/ directory
|
|
166
|
+
- Improved Ruby API examples with clearer input/output distinction
|
|
167
|
+
|
|
168
|
+
## [0.2.4] - 2025-11-25
|
|
169
|
+
|
|
170
|
+
### Fixed
|
|
171
|
+
- Fixed if-else expression formatting
|
|
172
|
+
|
|
173
|
+
## [0.2.3] - 2025-01-25
|
|
174
|
+
|
|
175
|
+
### Added
|
|
176
|
+
- Configuration file (rfmt.yml) is now automatically loaded and applied during formatting
|
|
177
|
+
- Automatic config file discovery in current directory, parent directories, and home directory
|
|
178
|
+
- Support for custom indent_width and other formatting options via rfmt.yml
|
|
179
|
+
|
|
180
|
+
### Changed
|
|
181
|
+
- Default config file name changed from .rfmt.yml to rfmt.yml (hidden file to regular file)
|
|
182
|
+
- Backward compatibility maintained: .rfmt.yml is still supported with lower priority
|
|
183
|
+
- Config file search order: rfmt.yml > rfmt.yaml > .rfmt.yml > .rfmt.yaml
|
|
184
|
+
- README updated to remove exaggerated expressions and focus on factual, data-driven descriptions
|
|
185
|
+
|
|
186
|
+
## [0.2.2] - 2025-01-25
|
|
187
|
+
|
|
188
|
+
### Fixed
|
|
189
|
+
- Fixed blank line formatting to output single blank line instead of double blank lines
|
|
190
|
+
|
|
191
|
+
## [0.2.1] - 2025-01-25
|
|
192
|
+
|
|
193
|
+
### Fixed
|
|
194
|
+
- Fixed GitHub Actions release workflow bundler installation issue
|
|
195
|
+
- Resolved clippy warnings in Rust codebase
|
|
196
|
+
- Improved enum Default trait implementations using derive macros
|
|
197
|
+
- Added `#[cfg(test)]` attributes to test-only code
|
|
198
|
+
|
|
199
|
+
### Changed
|
|
200
|
+
- Updated release workflow to use `bundler-cache: true` for better dependency management
|
|
201
|
+
|
|
202
|
+
## [0.2.0] - 2025-01-25
|
|
203
|
+
|
|
204
|
+
### Added
|
|
205
|
+
- Security policy implementation with input validation and resource limits
|
|
206
|
+
- File size validation (default: 10MB max)
|
|
207
|
+
- Source code encoding validation
|
|
208
|
+
- Comprehensive error handling with sanitized error messages
|
|
209
|
+
|
|
210
|
+
### Changed
|
|
211
|
+
- Simplified RSpec test suite (reduced from ~200 to 7 essential tests)
|
|
212
|
+
- Removed redundant and duplicate tests
|
|
213
|
+
- Improved code organization and removed unnecessary comments
|
|
214
|
+
- Disabled Windows CI temporarily due to rb-sys compatibility issues
|
|
215
|
+
|
|
216
|
+
### Fixed
|
|
217
|
+
- Rust code formatting issues
|
|
218
|
+
- Removed phase-related comments and code noise
|
|
219
|
+
- Fixed import order and formatting inconsistencies
|
|
220
|
+
|
|
221
|
+
## [0.1.0] - 2025-09-08
|
|
222
|
+
|
|
223
|
+
- Initial release
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 fujitani sora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# rfmt
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
A Ruby code formatter written in Rust
|
|
6
|
+
|
|
7
|
+
[](https://rubygems.org/gems/rfmt)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
[Installation](#installation) •
|
|
11
|
+
[Usage](#usage) •
|
|
12
|
+
[Features](#features) •
|
|
13
|
+
[Editor Integration](#editor-integration) •
|
|
14
|
+
[Documentation](#documentation) •
|
|
15
|
+
[Contributing](#contributing)
|
|
16
|
+
|
|
17
|
+
<a href="https://flatt.tech/oss/gmo/trampoline" target="_blank"><img src="https://flatt.tech/assets/images/badges/gmo-oss.svg" height="24px"/></a>
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## What is rfmt?
|
|
24
|
+
|
|
25
|
+
[RubyGems reference](https://rubygems.org/gems/rfmt)
|
|
26
|
+
|
|
27
|
+
**rfmt** is a Ruby code formatter that enforces consistent style across your codebase. Key characteristics:
|
|
28
|
+
|
|
29
|
+
- **Opinionated**: Minimal configuration with consistent output
|
|
30
|
+
- **Idempotent**: Running multiple times produces identical results
|
|
31
|
+
- **Comment preservation**: Maintains existing comment placement
|
|
32
|
+
- **Rust implementation**: Core formatter implemented in Rust
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
### Performance
|
|
37
|
+
|
|
38
|
+
Built with Rust for improved execution speed. See Performance Benchmarks section for details.
|
|
39
|
+
|
|
40
|
+
### Consistent Style
|
|
41
|
+
|
|
42
|
+
Enforces code style rules:
|
|
43
|
+
|
|
44
|
+
- Automatic indentation
|
|
45
|
+
- Spacing and alignment normalization
|
|
46
|
+
- Quote style standardization
|
|
47
|
+
- Method definition formatting
|
|
48
|
+
|
|
49
|
+
## Performance Benchmarks
|
|
50
|
+
|
|
51
|
+
Execution time comparison on a Rails project (111 files, 3,241 lines):
|
|
52
|
+
|
|
53
|
+
| Test Type | Files | rfmt | RuboCop | Ratio |
|
|
54
|
+
|-----------|-------|------|---------|-------|
|
|
55
|
+
| Single File | 1 | 191ms | 1.38s | 7.2x |
|
|
56
|
+
| Directory | 14 | 176ms | 1.68s | 9.6x |
|
|
57
|
+
| Full Project (check) | 111 | 172ms | 4.36s | 25.4x |
|
|
58
|
+
|
|
59
|
+
**About this comparison:**
|
|
60
|
+
- RuboCop times include startup overhead and loading all cops (linting rules)
|
|
61
|
+
- RuboCop was run with default configuration (all cops enabled)
|
|
62
|
+
- rfmt is a formatting-only tool with minimal overhead
|
|
63
|
+
- Both tools were measured in check mode (no file modifications)
|
|
64
|
+
- Results are averages from 10 runs per test
|
|
65
|
+
|
|
66
|
+
**Observations:**
|
|
67
|
+
- rfmt execution time remains constant (172-191ms) regardless of file count
|
|
68
|
+
- Low variance across runs (standard deviation: 8-23ms)
|
|
69
|
+
|
|
70
|
+
**Test Environment:**
|
|
71
|
+
- CPU: Apple Silicon (arm64)
|
|
72
|
+
- Ruby: 3.4.5
|
|
73
|
+
- rfmt: 0.3.0, RuboCop: 1.81.7
|
|
74
|
+
|
|
75
|
+
See [detailed benchmark report](docs/benchmark.md) for complete data.
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
### Requirements
|
|
80
|
+
|
|
81
|
+
- Ruby 3.0 or higher
|
|
82
|
+
- Rust 1.70 or higher (for building from source)
|
|
83
|
+
|
|
84
|
+
### From RubyGems
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
gem install rfmt
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### In Your Gemfile
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
gem 'rfmt'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Then run:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
bundle install
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### From Source
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
git clone https://github.com/fs0414/rfmt.git
|
|
106
|
+
cd rfmt
|
|
107
|
+
bundle install
|
|
108
|
+
bundle exec rake compile
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Usage
|
|
112
|
+
|
|
113
|
+
### Initialize Configuration
|
|
114
|
+
|
|
115
|
+
First, create a configuration file with default settings:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
rfmt init
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
This creates a `.rfmt.yml` file with default settings:
|
|
122
|
+
|
|
123
|
+
```yaml
|
|
124
|
+
version: "1.0"
|
|
125
|
+
|
|
126
|
+
formatting:
|
|
127
|
+
line_length: 100 # Maximum line length (40-500)
|
|
128
|
+
indent_width: 2 # Spaces/tabs per indent (1-8)
|
|
129
|
+
indent_style: "spaces" # "spaces" or "tabs"
|
|
130
|
+
quote_style: "double" # "double", "single", or "consistent"
|
|
131
|
+
|
|
132
|
+
include:
|
|
133
|
+
- "**/*.rb"
|
|
134
|
+
- "**/*.rake"
|
|
135
|
+
- "**/Rakefile"
|
|
136
|
+
- "**/Gemfile"
|
|
137
|
+
|
|
138
|
+
exclude:
|
|
139
|
+
- "vendor/**/*"
|
|
140
|
+
- "tmp/**/*"
|
|
141
|
+
- "node_modules/**/*"
|
|
142
|
+
- "db/schema.rb"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Options:**
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Specify custom path
|
|
149
|
+
rfmt init --path config/.rfmt.yml
|
|
150
|
+
|
|
151
|
+
# Overwrite existing configuration
|
|
152
|
+
rfmt init --force
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Command Line
|
|
156
|
+
|
|
157
|
+
Format a single file:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
rfmt lib/user.rb
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Format multiple files:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
rfmt lib/**/*.rb
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Check if files need formatting (CI/CD):
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
rfmt check .
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Show diff without modifying files:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
rfmt lib/user.rb --diff
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Enable verbose output for debugging:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
rfmt lib/user.rb --verbose
|
|
185
|
+
# or use environment variable
|
|
186
|
+
DEBUG=1 rfmt lib/user.rb
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Ruby API
|
|
190
|
+
|
|
191
|
+
**Input (unformatted code):**
|
|
192
|
+
|
|
193
|
+
```ruby
|
|
194
|
+
require 'rfmt'
|
|
195
|
+
|
|
196
|
+
source = <<~RUBY
|
|
197
|
+
class User
|
|
198
|
+
def initialize(name)
|
|
199
|
+
@name=name
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
RUBY
|
|
203
|
+
|
|
204
|
+
formatted = Rfmt.format(source)
|
|
205
|
+
puts formatted
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Output (formatted code):**
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
class User
|
|
212
|
+
def initialize(name)
|
|
213
|
+
@name=name
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Configuration
|
|
219
|
+
|
|
220
|
+
#### Configuration File Discovery
|
|
221
|
+
|
|
222
|
+
rfmt automatically searches for configuration files in this order:
|
|
223
|
+
|
|
224
|
+
1. Current directory (`.rfmt.yml`, `.rfmt.yaml`, `rfmt.yml`, or `rfmt.yaml`)
|
|
225
|
+
2. Parent directories (up to root)
|
|
226
|
+
3. User home directory (`.rfmt.yml`, `.rfmt.yaml`, `rfmt.yml`, or `rfmt.yaml`)
|
|
227
|
+
4. Default settings (if no file found)
|
|
228
|
+
|
|
229
|
+
#### Ruby API for Configuration
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
require 'rfmt'
|
|
233
|
+
|
|
234
|
+
# Generate configuration file
|
|
235
|
+
Rfmt::Config.init('.rfmt.yml', force: false)
|
|
236
|
+
|
|
237
|
+
# Find configuration file
|
|
238
|
+
config_path = Rfmt::Config.find
|
|
239
|
+
# => "/Users/username/project/.rfmt.yml"
|
|
240
|
+
|
|
241
|
+
# Check if configuration exists
|
|
242
|
+
Rfmt::Config.exists?
|
|
243
|
+
# => true
|
|
244
|
+
|
|
245
|
+
# Load configuration
|
|
246
|
+
config = Rfmt::Config.load
|
|
247
|
+
# => {"version"=>"1.0", "formatting"=>{"line_length"=>100, ...}, ...}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Examples
|
|
251
|
+
|
|
252
|
+
### Before Formatting
|
|
253
|
+
|
|
254
|
+
```ruby
|
|
255
|
+
class User<ApplicationRecord
|
|
256
|
+
has_many :posts
|
|
257
|
+
validates :email,presence: true
|
|
258
|
+
def full_name
|
|
259
|
+
"#{first_name} #{last_name}"
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### After Formatting
|
|
265
|
+
|
|
266
|
+
```ruby
|
|
267
|
+
class User < ApplicationRecord
|
|
268
|
+
has_many :posts
|
|
269
|
+
validates :email, presence: true
|
|
270
|
+
|
|
271
|
+
def full_name
|
|
272
|
+
"#{first_name} #{last_name}"
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Editor Integration
|
|
278
|
+
|
|
279
|
+
### Neovim
|
|
280
|
+
|
|
281
|
+
Format Ruby files on save using autocmd:
|
|
282
|
+
|
|
283
|
+
```lua
|
|
284
|
+
-- ~/.config/nvim/init.lua
|
|
285
|
+
|
|
286
|
+
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
287
|
+
pattern = { "*.rb", "*.rake", "Gemfile", "Rakefile" },
|
|
288
|
+
callback = function()
|
|
289
|
+
local filepath = vim.fn.expand("%:p")
|
|
290
|
+
local result = vim.fn.system({ "rfmt", filepath })
|
|
291
|
+
if vim.v.shell_error == 0 then
|
|
292
|
+
vim.cmd("edit!")
|
|
293
|
+
end
|
|
294
|
+
end,
|
|
295
|
+
})
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Coming Soon
|
|
299
|
+
|
|
300
|
+
- **VS Code** - Extension in development
|
|
301
|
+
- **RubyMine** - Plugin in development
|
|
302
|
+
- **Zed** - Extension in development
|
|
303
|
+
|
|
304
|
+
## Development
|
|
305
|
+
|
|
306
|
+
### Setup
|
|
307
|
+
|
|
308
|
+
After cloning the repository:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
bundle install
|
|
312
|
+
bundle exec lefthook install
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Git Hooks
|
|
316
|
+
|
|
317
|
+
This project uses [lefthook](https://github.com/evilmartians/lefthook) for automated validation before push:
|
|
318
|
+
|
|
319
|
+
**Pre-push checks:**
|
|
320
|
+
- RuboCop (Ruby linting)
|
|
321
|
+
- cargo fmt --check (Rust formatting)
|
|
322
|
+
- cargo clippy (Rust linting)
|
|
323
|
+
|
|
324
|
+
**Skip hooks temporarily:**
|
|
325
|
+
```bash
|
|
326
|
+
# Skip all hooks for this push
|
|
327
|
+
LEFTHOOK=0 git push
|
|
328
|
+
|
|
329
|
+
# Skip specific hook
|
|
330
|
+
LEFTHOOK_EXCLUDE=rubocop git push
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Running Tests
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
# Ruby tests
|
|
337
|
+
bundle exec rspec
|
|
338
|
+
|
|
339
|
+
# Rust tests
|
|
340
|
+
cargo test --manifest-path ext/rfmt/Cargo.toml
|
|
341
|
+
|
|
342
|
+
# All tests
|
|
343
|
+
bundle exec rake dev:test_all
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Documentation
|
|
347
|
+
|
|
348
|
+
Documentation is available in the [docs](docs/) directory:
|
|
349
|
+
|
|
350
|
+
- [User Guide](docs/user_guide.md) - Comprehensive usage guide
|
|
351
|
+
- [Error Reference](docs/error_reference.md) - Error codes and troubleshooting
|
|
352
|
+
- [Contributing Guide](CONTRIBUTING.md) - How to contribute
|
|
353
|
+
|
|
354
|
+
## Contributing
|
|
355
|
+
|
|
356
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
357
|
+
|
|
358
|
+
## Comparison with Other Tools
|
|
359
|
+
|
|
360
|
+
### rfmt vs RuboCop
|
|
361
|
+
|
|
362
|
+
| Feature | rfmt | RuboCop |
|
|
363
|
+
|---------|------|---------|
|
|
364
|
+
| **Primary Purpose** | Code formatting | Linting + formatting |
|
|
365
|
+
| **Configuration** | Minimal | Extensive |
|
|
366
|
+
| **Code Quality Checks** | No | Yes |
|
|
367
|
+
| **Bug Detection** | No | Yes |
|
|
368
|
+
|
|
369
|
+
**Note**: rfmt focuses on code formatting, while RuboCop provides additional code quality analysis. They can be used together.
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
374
|
+
|
|
375
|
+
## Code of Conduct
|
|
376
|
+
|
|
377
|
+
Everyone interacting in the rfmt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
|
378
|
+
|
|
379
|
+
## Support
|
|
380
|
+
|
|
381
|
+
- 📖 [Documentation](docs/)
|
|
382
|
+
- 🐛 [Issues](https://github.com/fs0414/rfmt/issues)
|
|
383
|
+
- 📧 Email: fujitanisora0414@gmail.com
|
|
384
|
+
|
|
385
|
+
## Acknowledgments
|
|
386
|
+
|
|
387
|
+
- Built with [Prism](https://github.com/ruby/prism) - Modern Ruby parser
|
|
388
|
+
- Powered by [Rust](https://www.rust-lang.org/) - Performance and safety
|
|
389
|
+
- FFI via [Magnus](https://github.com/matsadler/magnus) - Ruby-Rust bridge
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
<div align="center">
|
|
394
|
+
|
|
395
|
+
Created by [Fujitani Sora](https://github.com/fs0414)
|
|
396
|
+
|
|
397
|
+
</div>
|
data/exe/rfmt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'rfmt/cli'
|
|
5
|
+
|
|
6
|
+
# Known subcommands - if first arg is not one of these, prepend 'format'
|
|
7
|
+
SUBCOMMANDS = %w[format check version config cache init help].freeze
|
|
8
|
+
|
|
9
|
+
args = ARGV.dup
|
|
10
|
+
args.unshift('format') if args.empty? || (!SUBCOMMANDS.include?(args.first) && !args.first.start_with?('-'))
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
Rfmt::CLI.start(args)
|
|
14
|
+
rescue Interrupt
|
|
15
|
+
puts "\nInterrupted"
|
|
16
|
+
exit(130)
|
|
17
|
+
rescue StandardError => e
|
|
18
|
+
warn "Error: #{e.message}"
|
|
19
|
+
warn e.backtrace.join("\n") if ENV['DEBUG']
|
|
20
|
+
exit(1)
|
|
21
|
+
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|