rails_unused 0.1.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 +7 -0
- data/README.md +72 -0
- data/ROADMAP.md +28 -0
- data/exe/rails_unused +6 -0
- data/lib/rails/unused/version.rb +7 -0
- data/lib/rails_unused.rb +95 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e7471361c7872a42ee5c85d7e417b080c98f2e9a1fafe57f6d5fc3c65481c49
|
4
|
+
data.tar.gz: d61d3a87a5bbf6c8be7e9f25df9787c9e567d51f649a6bd987b8529df125e860
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9774815714183783f365857e9b0808f9405c3ccb33557d4c3a333606ec640ec68878d018f84c9e0ef5834f3018bc2651f0c1e14eecb6af265e6cb3d272345a8d
|
7
|
+
data.tar.gz: c8ce453bafbf6999ed46823ffd0d88792f9a366e671c8b9ed89f5aa23da0504a5a50c827676a9936a7fafc94fa2ceb6bd6cb0425e36b4456156b220ab79e1186
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# rails_unused
|
2
|
+
|
3
|
+
Dead code analyzer for Ruby on Rails projects.
|
4
|
+
Simple CLI tool that finds unused controllers, models, and services in your Rails app.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add to your Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rails_unused'
|
12
|
+
```
|
13
|
+
|
14
|
+
Then execute:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install directly:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
gem install rails_unused
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Inside your Rails project:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
bundle exec rails_unused
|
32
|
+
```
|
33
|
+
|
34
|
+
Example output:
|
35
|
+
|
36
|
+
```
|
37
|
+
Possible unused controllers:
|
38
|
+
- Admin::LegacyController
|
39
|
+
|
40
|
+
Possible unused models:
|
41
|
+
- OldCustomer
|
42
|
+
|
43
|
+
Possible unused services:
|
44
|
+
- User::CleanupService
|
45
|
+
```
|
46
|
+
|
47
|
+
## How it works
|
48
|
+
|
49
|
+
| Type | Search logic |
|
50
|
+
|-------------|----------------------------------------------------|
|
51
|
+
| Controllers | Checks if class name appears in `config/routes.rb` |
|
52
|
+
| Models | Checks if class name is referenced anywhere |
|
53
|
+
| Services | Checks if class name is referenced anywhere |
|
54
|
+
|
55
|
+
## Limitations
|
56
|
+
|
57
|
+
Simple static analysis.
|
58
|
+
|
59
|
+
False positives may happen if:
|
60
|
+
- Using metaprogramming
|
61
|
+
- Dynamic class loading
|
62
|
+
- External references
|
63
|
+
|
64
|
+
Always review before deleting.
|
65
|
+
|
66
|
+
## Roadmap
|
67
|
+
|
68
|
+
See [ROADMAP.md](ROADMAP.md) for future improvements.
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Pull requests are welcome!
|
data/ROADMAP.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Roadmap - rails_unused
|
2
|
+
|
3
|
+
## Short term
|
4
|
+
|
5
|
+
- Analyze views (partials not rendered anywhere)
|
6
|
+
- Detect mailers not being called
|
7
|
+
- Check helpers not used in views
|
8
|
+
- Support Rails jobs not enqueued
|
9
|
+
- Detect unused rake tasks
|
10
|
+
|
11
|
+
## Mid term
|
12
|
+
|
13
|
+
- Detect unused routes in config/routes.rb
|
14
|
+
- Output as JSON or YAML (optional)
|
15
|
+
- CI integration to fail build if dead code exists
|
16
|
+
- CLI output with colors
|
17
|
+
|
18
|
+
## Long term ideas
|
19
|
+
|
20
|
+
- Detect unused assets (JS/CSS)
|
21
|
+
- Analyze by environment (dev/test/prod)
|
22
|
+
- Generate HTML report
|
23
|
+
- VSCode Extension
|
24
|
+
- Web UI for browsing reports
|
25
|
+
|
26
|
+
## Contributions welcome!
|
27
|
+
|
28
|
+
Feel free to open issues or send pull requests.
|
data/exe/rails_unused
ADDED
data/lib/rails_unused.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require_relative 'rails/unused/version'
|
2
|
+
|
3
|
+
module RailsUnused
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
def self.run
|
7
|
+
unused_controllers = find_unused_controllers
|
8
|
+
unused_models = find_unused_models
|
9
|
+
unused_services = find_unused_services
|
10
|
+
|
11
|
+
puts 'Possíveis controllers não utilizados:'
|
12
|
+
if unused_controllers.empty?
|
13
|
+
puts ' (nenhum controller parece estar sem uso)'
|
14
|
+
else
|
15
|
+
unused_controllers.each { |ctr| puts " - #{ctr}" }
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "\nPossíveis models não utilizados:"
|
19
|
+
if unused_models.empty?
|
20
|
+
puts ' (nenhum model parece estar sem uso)'
|
21
|
+
else
|
22
|
+
unused_models.each { |mdl| puts " - #{mdl}" }
|
23
|
+
end
|
24
|
+
|
25
|
+
puts "\nPossíveis services não utilizados:"
|
26
|
+
if unused_services.empty?
|
27
|
+
puts ' (nenhum service parece estar sem uso)'
|
28
|
+
else
|
29
|
+
unused_services.each { |svc| puts " - #{svc}" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.find_unused_controllers
|
34
|
+
unused = []
|
35
|
+
Dir.glob('app/controllers/**/*_controller.rb').each do |file|
|
36
|
+
content = File.read(file)
|
37
|
+
next unless content =~ /class\s+([A-Za-z0-9_:+]+)/
|
38
|
+
|
39
|
+
controller_class = ::Regexp.last_match(1)
|
40
|
+
|
41
|
+
routes_text = File.exist?('config/routes.rb') ? File.read('config/routes.rb') : ''
|
42
|
+
base_name = controller_class.gsub(/Controller$/, '')
|
43
|
+
unused << controller_class unless routes_text.include?("#{base_name.downcase}#")
|
44
|
+
end
|
45
|
+
unused
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.find_unused_models
|
49
|
+
unused = []
|
50
|
+
all_files = Dir.glob('{app,config,lib}/**/*.rb')
|
51
|
+
Dir.glob('app/models/**/*.rb').each do |file|
|
52
|
+
content = File.read(file)
|
53
|
+
next unless content =~ /class\s+([A-Za-z0-9_:+]+)/
|
54
|
+
|
55
|
+
model_class = ::Regexp.last_match(1).split('<').first.strip
|
56
|
+
|
57
|
+
reference_found = false
|
58
|
+
all_files.each do |f|
|
59
|
+
next if f == file
|
60
|
+
|
61
|
+
text = File.read(f)
|
62
|
+
if text.include?(model_class)
|
63
|
+
reference_found = true
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
unused << model_class unless reference_found
|
68
|
+
end
|
69
|
+
unused
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.find_unused_services
|
73
|
+
unused = []
|
74
|
+
all_files = Dir.glob('{app,config,lib}/**/*.rb')
|
75
|
+
Dir.glob('app/services/**/*.rb').each do |file|
|
76
|
+
content = File.read(file)
|
77
|
+
next unless content =~ /class\s+([A-Za-z0-9_:+]+)/
|
78
|
+
|
79
|
+
service_class = ::Regexp.last_match(1).split('<').first.strip
|
80
|
+
|
81
|
+
reference_found = false
|
82
|
+
all_files.each do |f|
|
83
|
+
next if f == file
|
84
|
+
|
85
|
+
text = File.read(f)
|
86
|
+
if text.include?(service_class)
|
87
|
+
reference_found = true
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
unused << service_class unless reference_found
|
92
|
+
end
|
93
|
+
unused
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_unused
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Grassi
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: bundler
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.0'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '2.0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '13.0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '13.0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rspec
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
description: rails_unused é uma ferramenta CLI que analisa um projeto Ruby on Rails
|
55
|
+
e lista controllers, models e services potencialmente não utilizados no código.
|
56
|
+
email:
|
57
|
+
- grassiricardorg@gmail.com
|
58
|
+
executables:
|
59
|
+
- rails_unused
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- ROADMAP.md
|
65
|
+
- exe/rails_unused
|
66
|
+
- lib/rails/unused/version.rb
|
67
|
+
- lib/rails_unused.rb
|
68
|
+
homepage: https://github.com/grassiricardo/rails_unused
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '2.6'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.6.8
|
87
|
+
specification_version: 4
|
88
|
+
summary: Detector de código morto para aplicações Rails
|
89
|
+
test_files: []
|