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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9981b614b859c7c49e597686b89c79279ba977911b9a62d691aa0b88408eb0f
4
- data.tar.gz: 1461e9bcf3ff3b298855963fdf2e6cdd0aca1b3e29bf6f5b9037e62889903469
3
+ metadata.gz: c712093f002557a29995a2838caede692a26e86d492c7f9f735e8fe9f2a5f5f4
4
+ data.tar.gz: a7ce48fbf06a56879d803cb848786310ff5e6dc091de1d8f8a9ff47a0bb00dac
5
5
  SHA512:
6
- metadata.gz: 0b6aa80fa2df44397d1bdc81a12b860e1446a611f565e3283af8a821e691ca5122041f9622d48e2577740e878d740a1dba95df0a8c6acbea71c8301993f6fb46
7
- data.tar.gz: a1f330f17114d738523adf1fdcc9ccc42590b028a754e32304d2d4724f9966d54e5a7467bd50c8884111bc3ff16780b9b9c7591a0a22d8cd1eb17ffa50a856ed
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
@@ -1219,7 +1219,7 @@ checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001"
1219
1219
 
1220
1220
  [[package]]
1221
1221
  name = "rfmt"
1222
- version = "0.2.2"
1222
+ version = "0.2.3"
1223
1223
  dependencies = [
1224
1224
  "anyhow",
1225
1225
  "clap",
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
- ### Editor Integration
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
- Compatible editors:
88
+ ### Throughput Comparison
71
89
 
72
- - Visual Studio Code
73
- - RubyMine / IntelliJ IDEA
74
- - Vim / Neovim
75
- - Emacs
76
- - Sublime Text
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 `.rfmt.yml` file with default settings:
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 (`.rfmt.yml` or `.rfmt.yaml`)
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 (`~/.rfmt.yml` or `~/.rfmt.yaml`)
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('.rfmt.yml', force: false)
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/.rfmt.yml"
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) | Ruby-based |
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
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rfmt"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  edition = "2021"
5
5
  authors = ["fujitani sora <fujitanisora0414@gmail.com>"]
6
6
  license = "MIT"
@@ -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),
@@ -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
- let config = Config::default();
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))?;
@@ -18,7 +18,7 @@ module Rfmt
18
18
  'exclude' => ['vendor/**/*', 'tmp/**/*', 'node_modules/**/*']
19
19
  }.freeze
20
20
 
21
- CONFIG_FILES = ['.rfmt.yml', '.rfmt.yaml', 'rfmt.yml', 'rfmt.yaml'].freeze
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rfmt
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
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'].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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - fujitani sora