rfmt 0.2.4 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d42c0061474a8e7ef36fc5cbce1d7bfdad2bc5a9dbbff9b1a2c2b700b373c6ca
4
- data.tar.gz: f12d17ab726936fbdf69e4e5aaf3bca55fadf49230aa641adf0cba61c363f5ca
3
+ metadata.gz: 1344ebd75598608c54dc975f8afecc17be05152039542ac1c1e80007086530fc
4
+ data.tar.gz: b5a29adb45e5163fdfdbbea2526d4ac72bdbca410ee86e888ecb224f3b98c922
5
5
  SHA512:
6
- metadata.gz: 51948c8616f667de54435f87f7e154209c27777e82a84ada9f73d97c8928f68a063da72c1d7268035ca7d8d6e3eec658e4f6d874770658501edaad68a512ecdf
7
- data.tar.gz: e9a794b23d30ba314aa2b0f5fcacb6bbaff7408430bab6623169ef7d76fad53f32f58789e2a0a828a3b9e38dc074ca22bb0c4ff93f023e7c1a8c000081ba66e5
6
+ metadata.gz: 71db0a1b94b8a2288a5fae7e3a09ec41fac6e834abd9760fd45b4ac7dfef71baac7ada32582a6018b74fa22a6d0711f529b8372c491179dfbe66cc9c56c287aa
7
+ data.tar.gz: c7dc265d4ba68a15c653715bd26d8c087be6d361a7bb3170bd59057c0b9a65cfbf2093c02ff8528dcffd8a2b4ca445faef2fdc4fa4c5035016360d64ad297b9e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2025-11-25
4
+
5
+ ### Changed
6
+ - **BREAKING**: Default configuration file name changed from `rfmt.yml` to `.rfmt.yml`
7
+ - `rfmt init` now creates `.rfmt.yml` instead of `rfmt.yml`
8
+ - Configuration file search order updated: `.rfmt.yml` > `.rfmt.yaml` > `rfmt.yml` > `rfmt.yaml`
9
+ - This follows Ruby community conventions for hidden configuration files
10
+ - Backward compatibility maintained: `rfmt.yml` is still supported
11
+ - Updated README.md to use `.rfmt.yml` in all examples and documentation
12
+ - Updated benchmark data with latest accurate measurements (3,241 lines, more realistic performance ratios)
13
+ - Removed exaggerated performance claims from README and documentation
14
+ - Simplified feature descriptions in README (removed Error Handling and Logging from Features section)
15
+
16
+ ### Documentation
17
+ - Updated user guides (English and Japanese) to reflect `.rfmt.yml` as default
18
+ - Updated version information in documentation to 0.2.4 → 0.3.0
19
+ - Updated benchmark documentation with accurate data from latest measurements
20
+ - Added configuration verification examples in examples/ directory
21
+ - Improved Ruby API examples with clearer input/output distinction
22
+
3
23
  ## [0.2.4] - 2025-11-25
4
24
 
5
25
  ### Fixed
data/Cargo.lock CHANGED
@@ -1219,7 +1219,7 @@ checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001"
1219
1219
 
1220
1220
  [[package]]
1221
1221
  name = "rfmt"
1222
- version = "0.2.4"
1222
+ version = "0.3.0"
1223
1223
  dependencies = [
1224
1224
  "anyhow",
1225
1225
  "clap",
data/README.md CHANGED
@@ -22,21 +22,16 @@ A Ruby code formatter written in Rust
22
22
 
23
23
  **rfmt** is a Ruby code formatter that enforces consistent style across your codebase. Key characteristics:
24
24
 
25
- - **Rust implementation**: Provides faster execution than Ruby-based tools
26
25
  - **Opinionated**: Minimal configuration with consistent output
27
26
  - **Idempotent**: Running multiple times produces identical results
28
27
  - **Comment preservation**: Maintains existing comment placement
29
- - **Error handling**: Includes structured error messages and logging
28
+ - **Rust implementation**: Core formatter implemented in Rust
30
29
 
31
30
  ## Features
32
31
 
33
32
  ### Performance
34
33
 
35
- Built with Rust for improved execution speed:
36
-
37
- - Benchmark shows 7-58x faster than RuboCop depending on project size (see Performance Benchmarks section)
38
- - Processes 168 files/second in tested Rails project
39
- - Supports parallel processing
34
+ Built with Rust for improved execution speed. See Performance Benchmarks section for details.
40
35
 
41
36
  ### Consistent Style
42
37
 
@@ -47,54 +42,26 @@ Enforces code style rules:
47
42
  - Quote style standardization
48
43
  - Method definition formatting
49
44
 
50
- ### Error Handling
51
-
52
- Provides structured error messages:
53
-
54
- - Error codes (E001-E999) for categorization
55
- - Code snippets showing error locations
56
- - Help URLs linking to documentation
57
- - Recovery strategies for handling errors
58
-
59
- ### Logging
60
-
61
- Built-in logging system:
62
-
63
- - 5 log levels (ERROR, WARN, INFO, DEBUG, TRACE)
64
- - Structured output format
65
- - Performance metrics and timing data
66
- - Debug context information
67
-
68
45
  ## Performance Benchmarks
69
46
 
70
- Performance comparison with RuboCop on a Rails project (111 files, 3,231 lines):
47
+ Performance comparison with RuboCop on a Rails project (111 files, 3,241 lines):
71
48
 
72
- ### Benchmark Results (Rails Project)
49
+ | Test Type | Files | rfmt | RuboCop | Ratio |
50
+ |-----------|-------|------|---------|-------|
51
+ | Single File | 1 | 191ms | 1.38s | 7.2x |
52
+ | Directory | 14 | 176ms | 1.68s | 9.6x |
53
+ | Full Project (check) | 111 | 172ms | 4.36s | 25.4x |
73
54
 
74
- | Scenario | rfmt | RuboCop | Speedup |
75
- |----------|------|---------|---------|
76
- | **Single File** | ~190ms | ~1.35s | **7.3x faster** |
77
- | **Directory (14 files)** | 168ms | 1.67s | **10.0x faster** |
78
- | **Full Project (111 files)** | 173ms | 10.09s | **58.5x faster** |
79
- | **Check Mode (CI/CD)** | 172ms | 1.55s | **9.0x faster** |
55
+ **Observations:**
56
+ - rfmt execution time remains constant (172-191ms) regardless of file count
57
+ - Low variance across runs (standard deviation: 8-23ms)
80
58
 
81
- ### Key Metrics
59
+ **Test Environment:**
60
+ - CPU: Apple Silicon (arm64)
61
+ - Ruby: 3.4.5
62
+ - rfmt: 0.2.4, RuboCop: 1.81.7
82
63
 
83
- - Single file: Formats in ~190ms
84
- - Scaling: 58x faster on full project (111 files)
85
- - CI/CD: Check time reduced from 10.09s to 0.173s (98% reduction)
86
- - Variance: Low standard deviation across runs
87
-
88
- ### Throughput Comparison
89
-
90
- | Directory | rfmt | RuboCop | Difference |
91
- |-----------|------|---------|------------|
92
- | app/models (14 files) | 83.5 files/s | 8.4 files/s | **10x throughput** |
93
- | test/ (30 files) | 168.1 files/s | 18.1 files/s | **9.3x throughput** |
94
-
95
- *Benchmark environment: Apple Silicon (arm64), macOS Darwin 23.6.0, Ruby 3.4.5*
96
-
97
- See [detailed benchmark report](docspriv/benchmark_report.md) for full data.
64
+ See [detailed benchmark report](docs/benchmark.md) for complete data.
98
65
 
99
66
  ## Installation
100
67
 
@@ -132,6 +99,48 @@ bundle exec rake compile
132
99
 
133
100
  ## Usage
134
101
 
102
+ ### Initialize Configuration
103
+
104
+ First, create a configuration file with default settings:
105
+
106
+ ```bash
107
+ rfmt init
108
+ ```
109
+
110
+ This creates a `.rfmt.yml` file with default settings:
111
+
112
+ ```yaml
113
+ version: "1.0"
114
+
115
+ formatting:
116
+ line_length: 100 # Maximum line length (40-500)
117
+ indent_width: 2 # Spaces/tabs per indent (1-8)
118
+ indent_style: "spaces" # "spaces" or "tabs"
119
+ quote_style: "double" # "double", "single", or "consistent"
120
+
121
+ include:
122
+ - "**/*.rb"
123
+ - "**/*.rake"
124
+ - "**/Rakefile"
125
+ - "**/Gemfile"
126
+
127
+ exclude:
128
+ - "vendor/**/*"
129
+ - "tmp/**/*"
130
+ - "node_modules/**/*"
131
+ - "db/schema.rb"
132
+ ```
133
+
134
+ **Options:**
135
+
136
+ ```bash
137
+ # Specify custom path
138
+ rfmt init --path config/.rfmt.yml
139
+
140
+ # Overwrite existing configuration
141
+ rfmt init --force
142
+ ```
143
+
135
144
  ### Command Line
136
145
 
137
146
  Format a single file:
@@ -152,16 +161,24 @@ Check if files need formatting (CI/CD):
152
161
  rfmt check .
153
162
  ```
154
163
 
164
+ Show diff without modifying files:
165
+
166
+ ```bash
167
+ rfmt format lib/user.rb --diff
168
+ ```
169
+
155
170
  ### Ruby API
156
171
 
172
+ **Input (unformatted code):**
173
+
157
174
  ```ruby
158
175
  require 'rfmt'
159
176
 
160
177
  source = <<~RUBY
161
178
  class User
162
- def initialize(name)
163
- @name=name
164
- end
179
+ def initialize(name)
180
+ @name=name
181
+ end
165
182
  end
166
183
  RUBY
167
184
 
@@ -169,67 +186,25 @@ formatted = Rfmt.format(source)
169
186
  puts formatted
170
187
  ```
171
188
 
172
- **Output:**
189
+ **Output (formatted code):**
173
190
 
174
191
  ```ruby
175
192
  class User
176
193
  def initialize(name)
177
- @name = name
194
+ @name=name
178
195
  end
179
196
  end
180
197
  ```
181
198
 
182
199
  ### Configuration
183
200
 
184
- #### Initializing Configuration
185
-
186
- Create a configuration file with default settings:
187
-
188
- ```bash
189
- rfmt init
190
- ```
191
-
192
- This creates a `rfmt.yml` file with default settings:
193
-
194
- ```yaml
195
- version: "1.0"
196
-
197
- formatting:
198
- line_length: 100 # Maximum line length (40-500)
199
- indent_width: 2 # Spaces/tabs per indent (1-8)
200
- indent_style: "spaces" # "spaces" or "tabs"
201
- quote_style: "double" # "double", "single", or "consistent"
202
-
203
- include:
204
- - "**/*.rb"
205
- - "**/*.rake"
206
- - "**/Rakefile"
207
- - "**/Gemfile"
208
-
209
- exclude:
210
- - "vendor/**/*"
211
- - "tmp/**/*"
212
- - "node_modules/**/*"
213
- - "db/schema.rb"
214
- ```
215
-
216
- **Options:**
217
-
218
- ```bash
219
- # Specify custom path
220
- rfmt init --path config/rfmt.yml
221
-
222
- # Overwrite existing configuration
223
- rfmt init --force
224
- ```
225
-
226
201
  #### Configuration File Discovery
227
202
 
228
203
  rfmt automatically searches for configuration files in this order:
229
204
 
230
- 1. Current directory (`rfmt.yml`, `rfmt.yaml`, `.rfmt.yml`, or `.rfmt.yaml`)
205
+ 1. Current directory (`.rfmt.yml`, `.rfmt.yaml`, `rfmt.yml`, or `rfmt.yaml`)
231
206
  2. Parent directories (up to root)
232
- 3. User home directory (`rfmt.yml`, `rfmt.yaml`, `.rfmt.yml`, or `.rfmt.yaml`)
207
+ 3. User home directory (`.rfmt.yml`, `.rfmt.yaml`, `rfmt.yml`, or `rfmt.yaml`)
233
208
  4. Default settings (if no file found)
234
209
 
235
210
  #### Ruby API for Configuration
@@ -238,11 +213,11 @@ rfmt automatically searches for configuration files in this order:
238
213
  require 'rfmt'
239
214
 
240
215
  # Generate configuration file
241
- Rfmt::Config.init('rfmt.yml', force: false)
216
+ Rfmt::Config.init('.rfmt.yml', force: false)
242
217
 
243
218
  # Find configuration file
244
219
  config_path = Rfmt::Config.find
245
- # => "/Users/username/project/rfmt.yml"
220
+ # => "/Users/username/project/.rfmt.yml"
246
221
 
247
222
  # Check if configuration exists
248
223
  Rfmt::Config.exists?
@@ -253,59 +228,6 @@ config = Rfmt::Config.load
253
228
  # => {"version"=>"1.0", "formatting"=>{"line_length"=>100, ...}, ...}
254
229
  ```
255
230
 
256
- ## Error Handling
257
-
258
- rfmt provides structured error messages:
259
-
260
- ```
261
- [Rfmt::ParseError] Parse error in app/models/user.rb:15:10
262
- Expected closing 'end' for class definition
263
-
264
- Code:
265
- 13 | class User < ApplicationRecord
266
- 14 | def initialize(name)
267
- 15 | @name = name
268
- | ^
269
- 16 | # Missing 'end' for method
270
- 17 | end
271
-
272
- Help: https://rfmt.dev/errors/E001
273
- ```
274
-
275
- ### Error Codes
276
-
277
- | Code | Type | Description |
278
- |------|------|-------------|
279
- | E001 | ParseError | Ruby syntax error |
280
- | E002 | ConfigError | Invalid configuration |
281
- | E003 | IoError | File read/write error |
282
- | E004 | FormattingError | Formatting process error |
283
- | E005 | RuleError | Rule application failed |
284
- | E006 | UnsupportedFeature | Feature not yet supported |
285
- | E007 | PrismError | Parser integration error |
286
- | E008 | FormatError | General formatting error |
287
- | E999 | InternalError | Internal bug (please report!) |
288
-
289
- See the [Error Reference](docs/error_reference.md) for detailed information.
290
-
291
- ## Logging
292
-
293
- rfmt includes a logging system:
294
-
295
- ```ruby
296
- # Logs are automatically output during initialization
297
- require 'rfmt'
298
- # [INFO] rfmt - Initializing rfmt Rust extension
299
- # [INFO] rfmt - rfmt Rust extension initialized successfully
300
- ```
301
-
302
- Log levels:
303
- - **ERROR**: Critical errors
304
- - **WARN**: Warnings
305
- - **INFO**: General information (default)
306
- - **DEBUG**: Debug information
307
- - **TRACE**: Detailed trace information
308
-
309
231
  ## Examples
310
232
 
311
233
  ### Before Formatting
@@ -335,7 +257,11 @@ end
335
257
 
336
258
  ## Documentation
337
259
 
338
- Documentation is available in the [docs](docs/) directory. See [User Guide](docs/user_guide.md) or [Contributing Guide](CONTRIBUTING.md) for details.
260
+ Documentation is available in the [docs](docs/) directory:
261
+
262
+ - [User Guide](docs/user_guide.md) - Comprehensive usage guide
263
+ - [Error Reference](docs/error_reference.md) - Error codes and troubleshooting
264
+ - [Contributing Guide](CONTRIBUTING.md) - How to contribute
339
265
 
340
266
  ## Contributing
341
267
 
@@ -348,12 +274,11 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
348
274
  | Feature | rfmt | RuboCop |
349
275
  |---------|------|---------|
350
276
  | **Primary Purpose** | Code formatting | Linting + formatting |
351
- | **Speed** | 58x faster (tested benchmark) | Baseline |
352
277
  | **Configuration** | Minimal | Extensive |
353
278
  | **Code Quality Checks** | No | Yes |
354
279
  | **Bug Detection** | No | Yes |
355
280
 
356
- **Note**: rfmt focuses on formatting speed, while RuboCop provides additional code quality analysis. They can be used together.
281
+ **Note**: rfmt focuses on code formatting, while RuboCop provides additional code quality analysis. They can be used together.
357
282
 
358
283
  ## License
359
284
 
data/ext/rfmt/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rfmt"
3
- version = "0.2.4"
3
+ version = "0.3.0"
4
4
  edition = "2021"
5
5
  authors = ["fujitani sora <fujitanisora0414@gmail.com>"]
6
6
  license = "MIT"
data/lib/rfmt/rfmt.so CHANGED
Binary file
data/lib/rfmt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rfmt
4
- VERSION = '0.2.4'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/rfmt.rb CHANGED
@@ -95,10 +95,10 @@ module Rfmt
95
95
  YAML
96
96
 
97
97
  # Generate a default configuration file
98
- # @param path [String] Path where to create the config file (default: rfmt.yml)
98
+ # @param path [String] Path where to create the config file (default: .rfmt.yml)
99
99
  # @param force [Boolean] Overwrite existing file if true
100
100
  # @return [Boolean] true if file was created, false if already exists
101
- def self.init(path = 'rfmt.yml', force: false)
101
+ def self.init(path = '.rfmt.yml', force: false)
102
102
  if File.exist?(path) && !force
103
103
  warn "Configuration file already exists: #{path}"
104
104
  warn 'Use force: true to overwrite'
@@ -116,7 +116,7 @@ module Rfmt
116
116
  current_dir = Dir.pwd
117
117
 
118
118
  loop do
119
- ['rfmt.yml', 'rfmt.yaml', '.rfmt.yml', '.rfmt.yaml'].each do |filename|
119
+ ['.rfmt.yml', '.rfmt.yaml', 'rfmt.yml', 'rfmt.yaml'].each do |filename|
120
120
  config_path = File.join(current_dir, filename)
121
121
  return config_path if File.exist?(config_path)
122
122
  end
@@ -134,7 +134,7 @@ module Rfmt
134
134
  nil
135
135
  end
136
136
  if home_dir
137
- ['rfmt.yml', 'rfmt.yaml', '.rfmt.yml', '.rfmt.yaml'].each do |filename|
137
+ ['.rfmt.yml', '.rfmt.yaml', 'rfmt.yml', 'rfmt.yaml'].each do |filename|
138
138
  config_path = File.join(home_dir, filename)
139
139
  return config_path if File.exist?(config_path)
140
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fujitani sora
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-24 00:00:00.000000000 Z
11
+ date: 2025-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys