rubocop-minify 0.1.0 → 0.1.2
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 +8 -0
- data/README.md +13 -5
- data/config/default.yml +3 -0
- data/lib/rubocop/cop/minify/attribute_methods.rb +2 -1
- data/lib/rubocop_minify/rewrite.rb +6 -3
- data/lib/rubocop_minify/version.rb +1 -1
- data/lib/rubocop_minify.rb +21 -3
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0856e38071b562aec5905568ea2d4ecb07890678c749378b49798fa45eea92b
|
|
4
|
+
data.tar.gz: db8ed663094783d77a821394738845cc02d7726ec95fa1eaadadaaede7cd62ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3bb891186c07997815d98ddef30112aa00c3ec8233a228f18adfdfc86cc87557011ebcf540914673587e7fae73eecc94192ae7dcec97af664b1cbabc2a8cc7d
|
|
7
|
+
data.tar.gz: 3a35673417b24364098359e05ee0e580aba2f1ed1714261d41cbee2d42103e21f64fc597224fbabc017f1d57593757b36af57ddbf9573f034072ca8a261d0f85
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2 (2026-10-18)
|
|
4
|
+
|
|
5
|
+
- Works with Herb 0.10 (`herb >= 0.10`, was `>= 0.11`), so adding rubocop-minify doesn't upgrade Herb under gems that need 0.10, such as reactionview 0.3.
|
|
6
|
+
|
|
7
|
+
## 0.1.1 (2026-10-18)
|
|
8
|
+
|
|
9
|
+
- Names activerecord-minimizer's keep list still generates (`config/ar_minimizer_keep.txt`, `KeepList`) are left alone, by the cop and by `minify-erb`: a bare `name` everywhere, `Model#name` once every model with that attribute is listed. With the rewrites done and the rest in the keep list, both report nothing, so they can run as checks.
|
|
10
|
+
|
|
3
11
|
## 0.1.0 (2026-10-18)
|
|
4
12
|
|
|
5
13
|
First release.
|
data/README.md
CHANGED
|
@@ -51,11 +51,18 @@ RuboCop doesn't read ERB, so `minify-erb` does the same rewrite on the Ruby
|
|
|
51
51
|
inside each tag (parsed with Herb). Without `--fix` it lists the calls; it
|
|
52
52
|
exits non-zero while any are left, for CI.
|
|
53
53
|
|
|
54
|
+
Once the calls are rewritten and the rest are in the keep list, both report
|
|
55
|
+
nothing: keep the cop in `.rubocop.yml` and `minify-erb app` in CI, and new
|
|
56
|
+
code that calls a removed method is caught before it runs.
|
|
57
|
+
|
|
54
58
|
## What it won't rewrite
|
|
55
59
|
|
|
60
|
+
Names in activerecord-minimizer's keep list (`config/ar_minimizer_keep.txt`)
|
|
61
|
+
are still generated, so their calls are left alone: a bare `name` everywhere,
|
|
62
|
+
`Model#name` once every model with that attribute is listed.
|
|
63
|
+
|
|
56
64
|
Receivers aren't typed, so the cop only rewrites what can't mean something
|
|
57
|
-
else, and reports the rest for you to fix by hand or add to the keep list
|
|
58
|
-
(`config/ar_minimizer_keep.txt`):
|
|
65
|
+
else, and reports the rest for you to fix by hand or add to the keep list:
|
|
59
66
|
|
|
60
67
|
* Names the app also defines (`def featured?` in a presenter, `delegate`,
|
|
61
68
|
`attr_reader`, `alias_method`, ...), scanned from `app/` and `lib/`
|
|
@@ -79,11 +86,12 @@ Minify/AttributeMethods:
|
|
|
79
86
|
DefinitionPaths:
|
|
80
87
|
- "app/**/*.rb"
|
|
81
88
|
- "lib/**/*.rb"
|
|
89
|
+
KeepList: config/ar_minimizer_keep.txt
|
|
82
90
|
```
|
|
83
91
|
|
|
84
|
-
## On
|
|
92
|
+
## On Japan Voyage
|
|
85
93
|
|
|
86
94
|
191 models: 130 calls in Ruby (app, lib, test, db) and 21 templates rewritten
|
|
87
95
|
automatically; 11 names left for the keep list, all of them names some other
|
|
88
|
-
class defines too.
|
|
89
|
-
|
|
96
|
+
class defines too. After that the cop and `minify-erb` report nothing, and
|
|
97
|
+
the test suite gives the same results in strict mode.
|
data/config/default.yml
CHANGED
|
@@ -22,7 +22,8 @@ module RuboCop
|
|
|
22
22
|
def on_new_investigation
|
|
23
23
|
rewrite = RubocopMinify.rewrite_for(config.base_dir_for_path_parameters,
|
|
24
24
|
manifest: cop_config.fetch("Manifest", "config/ar_minimizer.json"),
|
|
25
|
-
definition_paths: Array(cop_config.fetch("DefinitionPaths", ["app/**/*.rb", "lib/**/*.rb"]))
|
|
25
|
+
definition_paths: Array(cop_config.fetch("DefinitionPaths", ["app/**/*.rb", "lib/**/*.rb"])),
|
|
26
|
+
keep_list: cop_config.fetch("KeepList", "config/ar_minimizer_keep.txt"))
|
|
26
27
|
return unless rewrite
|
|
27
28
|
|
|
28
29
|
source = processed_source.raw_source
|
|
@@ -30,10 +30,12 @@ module RubocopMinify
|
|
|
30
30
|
|
|
31
31
|
# defined: { method name => "path:line" } of hand-written methods.
|
|
32
32
|
# views: the source is template code (self is a view, never a record).
|
|
33
|
-
|
|
33
|
+
# kept: names the keep list still generates (see RubocopMinify.kept_names).
|
|
34
|
+
def initialize(index, defined: {}, views: false, kept: Set.new)
|
|
34
35
|
@index = index
|
|
35
36
|
@defined = defined
|
|
36
37
|
@views = views
|
|
38
|
+
@kept = kept
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def edits(source)
|
|
@@ -112,7 +114,7 @@ module RubocopMinify
|
|
|
112
114
|
def call_edit(node, cond)
|
|
113
115
|
name = node.name.to_s
|
|
114
116
|
entry = @index[name] or return
|
|
115
|
-
return if node.block || core?(name)
|
|
117
|
+
return if @kept.include?(name) || node.block || core?(name)
|
|
116
118
|
return if node.arguments && !entry.args # the generated method takes none: something else
|
|
117
119
|
|
|
118
120
|
receiver = node.receiver
|
|
@@ -182,6 +184,7 @@ module RubocopMinify
|
|
|
182
184
|
def callback_edit(sym)
|
|
183
185
|
name = sym.unescaped
|
|
184
186
|
entry = @index[name] or return
|
|
187
|
+
return if @kept.include?(name)
|
|
185
188
|
case self_coverage(entry)
|
|
186
189
|
when :all then nil
|
|
187
190
|
when :some then return report_symbol(sym, "#{name} is removed by strict mode from #{models(entry)}, but not every class this code runs in has it")
|
|
@@ -200,7 +203,7 @@ module RubocopMinify
|
|
|
200
203
|
end
|
|
201
204
|
|
|
202
205
|
def report_symbol(sym, message)
|
|
203
|
-
@edits << edit(sym, nil, message) if @index[sym.unescaped] && !core?(sym.unescaped)
|
|
206
|
+
@edits << edit(sym, nil, message) if @index[sym.unescaped] && !core?(sym.unescaped) && !@kept.include?(sym.unescaped)
|
|
204
207
|
end
|
|
205
208
|
|
|
206
209
|
# On every record too (readonly?, frozen?, ...) when ActiveRecord is loaded.
|
data/lib/rubocop_minify.rb
CHANGED
|
@@ -9,17 +9,35 @@ module RubocopMinify
|
|
|
9
9
|
|
|
10
10
|
# One Rewrite per app root and settings: reading the manifest and scanning
|
|
11
11
|
# the app for definitions happens once per process.
|
|
12
|
-
def self.rewrite_for(root, manifest:, definition_paths:, views: false)
|
|
12
|
+
def self.rewrite_for(root, manifest:, definition_paths:, views: false, keep_list: "config/ar_minimizer_keep.txt")
|
|
13
13
|
@rewrites ||= {}
|
|
14
|
-
@rewrites[[root, manifest, definition_paths, views]] ||= begin
|
|
14
|
+
@rewrites[[root, manifest, definition_paths, views, keep_list]] ||= begin
|
|
15
15
|
path = File.expand_path(manifest, root)
|
|
16
16
|
if File.exist?(path)
|
|
17
17
|
require "ar_minimizer"
|
|
18
|
-
|
|
18
|
+
index = ArMinimizer::Manifest.load(path)
|
|
19
|
+
Rewrite.new(index, defined: definitions(root, definition_paths), views: views,
|
|
20
|
+
kept: kept_names(index, File.expand_path(keep_list, root)))
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
# Names strict mode still generates on every model that has them, from
|
|
26
|
+
# activerecord-minimizer's keep list: a bare "name" keeps it everywhere,
|
|
27
|
+
# "Model#name" only there (the name counts once every model with that
|
|
28
|
+
# attribute is listed). Calls of those names are left alone.
|
|
29
|
+
def self.kept_names(index, path)
|
|
30
|
+
return Set.new unless File.exist?(path)
|
|
31
|
+
|
|
32
|
+
bare, scoped = ArMinimizer::Slim.parse_keep_file(File.read(path)).partition { !it.include?("#") }
|
|
33
|
+
kept = Set.new(bare)
|
|
34
|
+
scoped.map { it.split("#", 2) }.group_by(&:last).each do |name, pairs|
|
|
35
|
+
entry = index[name]
|
|
36
|
+
kept << name if entry && (entry.classes - pairs.map(&:first)).empty?
|
|
37
|
+
end
|
|
38
|
+
kept
|
|
39
|
+
end
|
|
40
|
+
|
|
23
41
|
def self.definitions(root, paths)
|
|
24
42
|
@definitions ||= {}
|
|
25
43
|
@definitions[[root, paths]] ||= Definitions.scan(root, paths)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-minify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sampo Kuokkanen
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0.
|
|
32
|
+
version: '0.10'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0.
|
|
39
|
+
version: '0.10'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: lint_roller
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|