rfmt 1.2.5 → 1.2.7
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 +11 -0
- data/Cargo.lock +1 -1
- data/ext/rfmt/Cargo.toml +1 -1
- data/ext/rfmt/src/emitter/mod.rs +19 -6
- data/lib/rfmt/cache.rb +7 -15
- data/lib/rfmt/rfmt.so +0 -0
- data/lib/rfmt/version.rb +1 -1
- 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: 5ab6ecad407c85286dad54ee0f744f6adc601c9778d0a2171bbae197d7d5c58d
|
|
4
|
+
data.tar.gz: c3f7f178538d64891d60936e9303b93e63a28403aa6e4f50adab4b7eaa1f641b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1f272f73406b14d1d5a735bdb0e66138f753b64ba26d369262a824cefda6d2fc0df14665a2c4f85ae62f3139845c8c01a8f9ad39c2d5fa3db4ad821b7aa7c29
|
|
7
|
+
data.tar.gz: 0a40da5d6084cfd3e3c4ccfd66d3b4be39d7f0a534a5ba7161ca151d98cce039820c587de0109a3065585cceee0a7eeaaaae2c8a4889ec7eb3bd60f843801bc6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.2.7] - 2026-01-04
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Remove OpenSSL dependency: Use mtime instead of SHA256 hash for cache invalidation
|
|
7
|
+
|
|
8
|
+
## [1.2.6] - 2026-01-04
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Version bump
|
|
12
|
+
|
|
3
13
|
## [1.2.5] - 2026-01-04
|
|
4
14
|
|
|
5
15
|
### Fixed
|
|
6
16
|
- Fix trailing comments on `end` keyword (e.g., `end # rubocop:disable`)
|
|
7
17
|
- Fix block internal comments being moved outside the block
|
|
8
18
|
- Fix blank line preservation between code and comments inside blocks
|
|
19
|
+
- Fix leading blank line being added to comment-only files
|
|
9
20
|
|
|
10
21
|
## [1.2.4] - 2026-01-04
|
|
11
22
|
|
data/Cargo.lock
CHANGED
data/ext/rfmt/Cargo.toml
CHANGED
data/ext/rfmt/src/emitter/mod.rs
CHANGED
|
@@ -79,24 +79,37 @@ impl Emitter {
|
|
|
79
79
|
/// Emit all comments that haven't been emitted yet
|
|
80
80
|
fn emit_remaining_comments(&mut self, last_code_line: usize) -> Result<()> {
|
|
81
81
|
let mut last_end_line: Option<usize> = Some(last_code_line);
|
|
82
|
+
let mut is_first_comment = true;
|
|
83
|
+
|
|
82
84
|
for (idx, comment) in self.all_comments.iter().enumerate() {
|
|
83
85
|
if self.emitted_comment_indices.contains(&idx) {
|
|
84
86
|
continue;
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
|
|
89
|
+
// For the first remaining comment:
|
|
90
|
+
// - If buffer is empty, don't add any leading newline
|
|
91
|
+
// - If buffer has content, ensure we start on a new line
|
|
92
|
+
if is_first_comment && self.buffer.is_empty() {
|
|
93
|
+
// Don't add leading newline for first comment when buffer is empty
|
|
94
|
+
} else if !self.buffer.ends_with('\n') {
|
|
88
95
|
self.buffer.push('\n');
|
|
89
96
|
}
|
|
97
|
+
|
|
90
98
|
// Preserve blank lines between code/comments
|
|
91
|
-
if
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
// But only if this is not the first comment in an empty buffer
|
|
100
|
+
if !(is_first_comment && self.buffer.is_empty()) {
|
|
101
|
+
if let Some(prev_line) = last_end_line {
|
|
102
|
+
let gap = comment.location.start_line.saturating_sub(prev_line);
|
|
103
|
+
for _ in 1..gap {
|
|
104
|
+
self.buffer.push('\n');
|
|
105
|
+
}
|
|
95
106
|
}
|
|
96
107
|
}
|
|
108
|
+
|
|
97
109
|
writeln!(self.buffer, "{}", comment.text)?;
|
|
98
110
|
self.emitted_comment_indices.push(idx);
|
|
99
111
|
last_end_line = Some(comment.location.end_line);
|
|
112
|
+
is_first_comment = false;
|
|
100
113
|
}
|
|
101
114
|
Ok(())
|
|
102
115
|
}
|
data/lib/rfmt/cache.rb
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'openssl'
|
|
4
3
|
require 'json'
|
|
5
4
|
require 'fileutils'
|
|
6
5
|
|
|
7
6
|
module Rfmt
|
|
8
7
|
# Cache system for formatted files
|
|
9
|
-
# Uses
|
|
8
|
+
# Uses mtime (modification time) to determine if formatting is needed
|
|
10
9
|
class Cache
|
|
11
10
|
class CacheError < StandardError; end
|
|
12
11
|
|
|
@@ -23,22 +22,22 @@ module Rfmt
|
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
# Check if file needs formatting
|
|
26
|
-
# Returns true if file
|
|
25
|
+
# Returns true if file mtime has changed or not in cache
|
|
27
26
|
def needs_formatting?(file_path)
|
|
28
27
|
return true unless File.exist?(file_path)
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
current_mtime = File.mtime(file_path).to_i
|
|
30
|
+
cached_mtime = @cache_data.dig(file_path, 'mtime')
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
current_mtime != cached_mtime
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
# Mark file as formatted with current
|
|
35
|
+
# Mark file as formatted with current mtime
|
|
37
36
|
def mark_formatted(file_path)
|
|
38
37
|
return unless File.exist?(file_path)
|
|
39
38
|
|
|
40
39
|
@cache_data[file_path] = {
|
|
41
|
-
'
|
|
40
|
+
'mtime' => File.mtime(file_path).to_i,
|
|
42
41
|
'formatted_at' => Time.now.to_i,
|
|
43
42
|
'version' => CACHE_VERSION
|
|
44
43
|
}
|
|
@@ -103,13 +102,6 @@ module Rfmt
|
|
|
103
102
|
@cache_data = {}
|
|
104
103
|
end
|
|
105
104
|
|
|
106
|
-
def file_hash(file_path)
|
|
107
|
-
content = File.read(file_path)
|
|
108
|
-
OpenSSL::Digest::SHA256.hexdigest(content)
|
|
109
|
-
rescue StandardError => e
|
|
110
|
-
raise CacheError, "Failed to read file #{file_path}: #{e.message}"
|
|
111
|
-
end
|
|
112
|
-
|
|
113
105
|
def cache_size
|
|
114
106
|
cache_file = File.join(@cache_dir, 'cache.json')
|
|
115
107
|
return 0 unless File.exist?(cache_file)
|
data/lib/rfmt/rfmt.so
CHANGED
|
Binary file
|
data/lib/rfmt/version.rb
CHANGED