rfmt 0.2.2 → 0.2.3
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/CHANGELOG.md +13 -0
- data/Cargo.lock +1 -1
- data/README.md +34 -45
- data/ext/rfmt/Cargo.toml +1 -1
- data/ext/rfmt/src/config/mod.rs +38 -3
- data/ext/rfmt/src/error/mod.rs +0 -2
- data/ext/rfmt/src/lib.rs +2 -1
- data/lib/rfmt/configuration.rb +1 -1
- data/lib/rfmt/rfmt.so +0 -0
- data/lib/rfmt/version.rb +1 -1
- data/lib/rfmt.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c712093f002557a29995a2838caede692a26e86d492c7f9f735e8fe9f2a5f5f4
|
|
4
|
+
data.tar.gz: a7ce48fbf06a56879d803cb848786310ff5e6dc091de1d8f8a9ff47a0bb00dac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '05954d426b7b6951e330d55d469ea78ebbf75350d755e0107eb0c4de32f5b11afd9373fbeabff3f7c2c902cfada70f4fae276c8b5d0d4d3b00eb3514a467fa0e'
|
|
7
|
+
data.tar.gz: cd4b6992cd4d795dfe8bd91f74504212337bcf7c13c736822919a071abda7ff0e1712f24e277786fa8b9a3ba6150b0727d33f415631c1707b6277c5612c94dbe
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.3] - 2025-01-25
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Configuration file (rfmt.yml) is now automatically loaded and applied during formatting
|
|
7
|
+
- Automatic config file discovery in current directory, parent directories, and home directory
|
|
8
|
+
- Support for custom indent_width and other formatting options via rfmt.yml
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Default config file name changed from .rfmt.yml to rfmt.yml (hidden file to regular file)
|
|
12
|
+
- Backward compatibility maintained: .rfmt.yml is still supported with lower priority
|
|
13
|
+
- Config file search order: rfmt.yml > rfmt.yaml > .rfmt.yml > .rfmt.yaml
|
|
14
|
+
- README updated to remove exaggerated expressions and focus on factual, data-driven descriptions
|
|
15
|
+
|
|
3
16
|
## [0.2.2] - 2025-01-25
|
|
4
17
|
|
|
5
18
|
### Fixed
|
data/Cargo.lock
CHANGED
data/README.md
CHANGED
|
@@ -65,15 +65,36 @@ Built-in logging system:
|
|
|
65
65
|
- Performance metrics and timing data
|
|
66
66
|
- Debug context information
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
## Performance Benchmarks
|
|
69
|
+
|
|
70
|
+
Performance comparison with RuboCop on a Rails project (111 files, 3,231 lines):
|
|
71
|
+
|
|
72
|
+
### Benchmark Results (Rails Project)
|
|
73
|
+
|
|
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** |
|
|
80
|
+
|
|
81
|
+
### Key Metrics
|
|
82
|
+
|
|
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
|
|
69
87
|
|
|
70
|
-
|
|
88
|
+
### Throughput Comparison
|
|
71
89
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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.
|
|
77
98
|
|
|
78
99
|
## Installation
|
|
79
100
|
|
|
@@ -168,7 +189,7 @@ Create a configuration file with default settings:
|
|
|
168
189
|
rfmt init
|
|
169
190
|
```
|
|
170
191
|
|
|
171
|
-
This creates a
|
|
192
|
+
This creates a `rfmt.yml` file with default settings:
|
|
172
193
|
|
|
173
194
|
```yaml
|
|
174
195
|
version: "1.0"
|
|
@@ -206,9 +227,9 @@ rfmt init --force
|
|
|
206
227
|
|
|
207
228
|
rfmt automatically searches for configuration files in this order:
|
|
208
229
|
|
|
209
|
-
1. Current directory (
|
|
230
|
+
1. Current directory (`rfmt.yml`, `rfmt.yaml`, `.rfmt.yml`, or `.rfmt.yaml`)
|
|
210
231
|
2. Parent directories (up to root)
|
|
211
|
-
3. User home directory (
|
|
232
|
+
3. User home directory (`rfmt.yml`, `rfmt.yaml`, `.rfmt.yml`, or `.rfmt.yaml`)
|
|
212
233
|
4. Default settings (if no file found)
|
|
213
234
|
|
|
214
235
|
#### Ruby API for Configuration
|
|
@@ -217,11 +238,11 @@ rfmt automatically searches for configuration files in this order:
|
|
|
217
238
|
require 'rfmt'
|
|
218
239
|
|
|
219
240
|
# Generate configuration file
|
|
220
|
-
Rfmt::Config.init('
|
|
241
|
+
Rfmt::Config.init('rfmt.yml', force: false)
|
|
221
242
|
|
|
222
243
|
# Find configuration file
|
|
223
244
|
config_path = Rfmt::Config.find
|
|
224
|
-
# => "/Users/username/project
|
|
245
|
+
# => "/Users/username/project/rfmt.yml"
|
|
225
246
|
|
|
226
247
|
# Check if configuration exists
|
|
227
248
|
Rfmt::Config.exists?
|
|
@@ -312,37 +333,6 @@ class User < ApplicationRecord
|
|
|
312
333
|
end
|
|
313
334
|
```
|
|
314
335
|
|
|
315
|
-
## Performance Benchmarks
|
|
316
|
-
|
|
317
|
-
Performance comparison with RuboCop on a Rails project (111 files, 3,231 lines):
|
|
318
|
-
|
|
319
|
-
### Benchmark Results (Rails Project)
|
|
320
|
-
|
|
321
|
-
| Scenario | rfmt | RuboCop | Speedup |
|
|
322
|
-
|----------|------|---------|---------|
|
|
323
|
-
| **Single File** | ~190ms | ~1.35s | **7.3x faster** |
|
|
324
|
-
| **Directory (14 files)** | 168ms | 1.67s | **10.0x faster** |
|
|
325
|
-
| **Full Project (111 files)** | 173ms | 10.09s | **58.5x faster** |
|
|
326
|
-
| **Check Mode (CI/CD)** | 172ms | 1.55s | **9.0x faster** |
|
|
327
|
-
|
|
328
|
-
### Key Metrics
|
|
329
|
-
|
|
330
|
-
- Single file: Formats in ~190ms
|
|
331
|
-
- Scaling: 58x faster on full project (111 files)
|
|
332
|
-
- CI/CD: Check time reduced from 10.09s to 0.173s (98% reduction)
|
|
333
|
-
- Variance: Low standard deviation across runs
|
|
334
|
-
|
|
335
|
-
### Throughput Comparison
|
|
336
|
-
|
|
337
|
-
| Directory | rfmt | RuboCop | Difference |
|
|
338
|
-
|-----------|------|---------|------------|
|
|
339
|
-
| app/models (14 files) | 83.5 files/s | 8.4 files/s | **10x throughput** |
|
|
340
|
-
| test/ (30 files) | 168.1 files/s | 18.1 files/s | **9.3x throughput** |
|
|
341
|
-
|
|
342
|
-
*Benchmark environment: Apple Silicon (arm64), macOS Darwin 23.6.0, Ruby 3.4.5*
|
|
343
|
-
|
|
344
|
-
See [detailed benchmark report](docspriv/benchmark_report.md) for full data.
|
|
345
|
-
|
|
346
336
|
## Documentation
|
|
347
337
|
|
|
348
338
|
Documentation is available in the [docs](docs/) directory. See [User Guide](docs/user_guide.md) or [Contributing Guide](CONTRIBUTING.md) for details.
|
|
@@ -358,7 +348,7 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
358
348
|
| Feature | rfmt | RuboCop |
|
|
359
349
|
|---------|------|---------|
|
|
360
350
|
| **Primary Purpose** | Code formatting | Linting + formatting |
|
|
361
|
-
| **Speed** | 58x faster (tested benchmark) |
|
|
351
|
+
| **Speed** | 58x faster (tested benchmark) | Baseline |
|
|
362
352
|
| **Configuration** | Minimal | Extensive |
|
|
363
353
|
| **Code Quality Checks** | No | Yes |
|
|
364
354
|
| **Bug Detection** | No | Yes |
|
|
@@ -377,7 +367,6 @@ Everyone interacting in the rfmt project's codebases, issue trackers, chat rooms
|
|
|
377
367
|
|
|
378
368
|
- 📖 [Documentation](docs/)
|
|
379
369
|
- 🐛 [Issues](https://github.com/fujitanisora/rfmt/issues)
|
|
380
|
-
- 💬 [Discussions](https://github.com/fujitanisora/rfmt/discussions)
|
|
381
370
|
- 📧 Email: fujitanisora0414@gmail.com
|
|
382
371
|
|
|
383
372
|
## Acknowledgments
|
data/ext/rfmt/Cargo.toml
CHANGED
data/ext/rfmt/src/config/mod.rs
CHANGED
|
@@ -99,8 +99,45 @@ pub enum TrailingComma {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
impl Config {
|
|
102
|
+
/// Discover configuration file in current directory or parent directories
|
|
103
|
+
/// Searches in order: rfmt.yml, rfmt.yaml, .rfmt.yml, .rfmt.yaml
|
|
104
|
+
pub fn discover() -> crate::error::Result<Self> {
|
|
105
|
+
let config_files = ["rfmt.yml", "rfmt.yaml", ".rfmt.yml", ".rfmt.yaml"];
|
|
106
|
+
|
|
107
|
+
// Try current directory and parent directories
|
|
108
|
+
if let Ok(mut current_dir) = std::env::current_dir() {
|
|
109
|
+
loop {
|
|
110
|
+
for filename in &config_files {
|
|
111
|
+
let config_path = current_dir.join(filename);
|
|
112
|
+
if config_path.exists() {
|
|
113
|
+
log::debug!("Found config file: {:?}", config_path);
|
|
114
|
+
return Self::load_file(&config_path);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Move to parent directory
|
|
119
|
+
if !current_dir.pop() {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Try home directory
|
|
126
|
+
if let Some(home_dir) = dirs::home_dir() {
|
|
127
|
+
for filename in &config_files {
|
|
128
|
+
let config_path = home_dir.join(filename);
|
|
129
|
+
if config_path.exists() {
|
|
130
|
+
log::debug!("Found config file in home: {:?}", config_path);
|
|
131
|
+
return Self::load_file(&config_path);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
log::debug!("No config file found, using defaults");
|
|
137
|
+
Ok(Config::default())
|
|
138
|
+
}
|
|
139
|
+
|
|
102
140
|
/// Load configuration from a YAML file
|
|
103
|
-
#[cfg(test)]
|
|
104
141
|
pub fn load_file(path: &std::path::Path) -> crate::error::Result<Self> {
|
|
105
142
|
use crate::error::RfmtError;
|
|
106
143
|
|
|
@@ -119,7 +156,6 @@ impl Config {
|
|
|
119
156
|
}
|
|
120
157
|
|
|
121
158
|
/// Validate configuration values
|
|
122
|
-
#[cfg(test)]
|
|
123
159
|
fn validate(&self) -> crate::error::Result<()> {
|
|
124
160
|
use crate::error::RfmtError;
|
|
125
161
|
|
|
@@ -145,7 +181,6 @@ impl Config {
|
|
|
145
181
|
}
|
|
146
182
|
|
|
147
183
|
/// Get the indent string based on configuration
|
|
148
|
-
#[cfg(test)]
|
|
149
184
|
pub fn indent_string(&self) -> String {
|
|
150
185
|
match self.formatting.indent_style {
|
|
151
186
|
IndentStyle::Spaces => " ".repeat(self.formatting.indent_width),
|
data/ext/rfmt/src/error/mod.rs
CHANGED
|
@@ -18,7 +18,6 @@ pub enum RfmtError {
|
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
#[error("Configuration error: {message}")]
|
|
21
|
-
#[cfg(test)]
|
|
22
21
|
ConfigError { message: String },
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -36,7 +35,6 @@ impl RfmtError {
|
|
|
36
35
|
RfmtError::PrismError(_) => "PrismError",
|
|
37
36
|
RfmtError::FormatError(_) => "FormatError",
|
|
38
37
|
RfmtError::UnsupportedFeature { .. } => "UnsupportedFeature",
|
|
39
|
-
#[cfg(test)]
|
|
40
38
|
RfmtError::ConfigError { .. } => "ConfigError",
|
|
41
39
|
};
|
|
42
40
|
|
data/ext/rfmt/src/lib.rs
CHANGED
|
@@ -25,7 +25,8 @@ fn format_ruby_code(ruby: &Ruby, source: String, json: String) -> Result<String,
|
|
|
25
25
|
let parser = PrismAdapter::new();
|
|
26
26
|
let ast = parser.parse(&json).map_err(|e| e.to_magnus_error(ruby))?;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// Load configuration from file or use defaults
|
|
29
|
+
let config = Config::discover().map_err(|e| e.to_magnus_error(ruby))?;
|
|
29
30
|
let mut emitter = Emitter::with_source(config, source);
|
|
30
31
|
|
|
31
32
|
let formatted = emitter.emit(&ast).map_err(|e| e.to_magnus_error(ruby))?;
|
data/lib/rfmt/configuration.rb
CHANGED
|
@@ -18,7 +18,7 @@ module Rfmt
|
|
|
18
18
|
'exclude' => ['vendor/**/*', 'tmp/**/*', 'node_modules/**/*']
|
|
19
19
|
}.freeze
|
|
20
20
|
|
|
21
|
-
CONFIG_FILES = ['
|
|
21
|
+
CONFIG_FILES = ['rfmt.yml', 'rfmt.yaml', '.rfmt.yml', '.rfmt.yaml'].freeze
|
|
22
22
|
|
|
23
23
|
attr_reader :config
|
|
24
24
|
|
data/lib/rfmt/rfmt.so
CHANGED
|
Binary file
|
data/lib/rfmt/version.rb
CHANGED
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:
|
|
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 = '
|
|
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'].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'].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
|