fasterer 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/CHANGELOG.md +11 -0
- data/fasterer.gemspec +0 -1
- data/lib/fasterer/file_traverser.rb +7 -9
- data/lib/fasterer/painter.rb +20 -0
- data/lib/fasterer/scanners/method_call_scanner.rb +4 -1
- data/lib/fasterer/version.rb +1 -1
- data/spec/lib/fasterer/file_traverser_spec.rb +1 -1
- data/spec/lib/fasterer/statistics_spec.rb +20 -0
- data/spec/support/analyzer/12_select_first_vs_detect.rb +2 -0
- data/spec/support/analyzer/15_keys_each_vs_each_key.rb +4 -0
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 411b46cc87653ad7048d611491cfd10eb2662ce06e35ae4e78b0b12400ba1386
|
4
|
+
data.tar.gz: c036629c9e46b9be35bd77df0a1169b79922bbd70f0f4b17229817273ef3b0ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18a1ec6deb132ce4e88b705f56139a3910f0d8a35beece353db71b219f3c51c3af17639cf1ba3788373058bb9eca0f7538a2270d300419a1970465941de2b1c0
|
7
|
+
data.tar.gz: 64a1197fedf11ca6c1205c43d8e13cdea940459b67d43be86a60353c458d7df8dc0e6e595f76c2e2859b3994676d79fe21ed607763736a570aded9782eb79b0f
|
data/.github/workflows/ruby.yml
CHANGED
@@ -19,10 +19,10 @@ jobs:
|
|
19
19
|
runs-on: ubuntu-latest
|
20
20
|
strategy:
|
21
21
|
matrix:
|
22
|
-
ruby-version: ['2.
|
22
|
+
ruby-version: ['2.5.0','2.6.0','2.7.0','3.0.0','3.1.0','3.2.0']
|
23
23
|
|
24
24
|
steps:
|
25
|
-
- uses: actions/checkout@
|
25
|
+
- uses: actions/checkout@v3
|
26
26
|
- name: Set up Ruby
|
27
27
|
uses: ruby/setup-ruby@v1
|
28
28
|
with:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.11.0
|
4
|
+
|
5
|
+
- There have been multiple issues filed with the colorize gem, such as licencing, gem versions etc. Due to the easy implementation, fasterer will now leverage an internal implementation of this so we don't need to get issues tracked bc of colorize. There might be other issues that arise (perhaps somebody leveraging Windows might have issues), but that's okay, we'll solve it.
|
6
|
+
|
7
|
+
- There has been a [bug report #102](https://github.com/DamirSvrtan/fasterer/issues/102) that the Redis `#keys` method shouldn't trigger `Hash#each_key` recommendation. It's not possible to detect that what is the receiver of the keys method call, but the keys method called on the Hash doesn't accept arguments while the redis one does. So not an ideal solution, but should fix any issues for now.
|
8
|
+
|
9
|
+
|
10
|
+
## 0.10.1
|
11
|
+
|
12
|
+
- There has been a [bug report #99](https://github.com/DamirSvrtan/fasterer/issues/99) that the `select_first_vs_detect` reports false positives when first gets an argument passed in. If there is an argument passed in, the detect method is not suitable, since it always returns the first element matching (can't return multiple items).
|
13
|
+
|
3
14
|
## 0.10.0
|
4
15
|
|
5
16
|
- Due to issues while setting up builds with Github Actions, I have dropped Ruby 2.2 support. It's EOL date was 2018-03-31, and I don't have the bandwidth to support deprecated Ruby versions. The only reason at this point why Ruby versions 2.3, 2.4 and 2.5 are supported is because they still work with other dependencies, so it's no effort currently to support them. Once they become issues, they'll probably be dropped.
|
data/fasterer.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require 'colorize'
|
3
2
|
require 'English'
|
4
3
|
|
5
4
|
require_relative 'analyzer'
|
6
5
|
require_relative 'config'
|
6
|
+
require_relative 'painter'
|
7
7
|
|
8
8
|
module Fasterer
|
9
9
|
class FileTraverser
|
@@ -83,7 +83,7 @@ module Fasterer
|
|
83
83
|
offenses_grouped_by_type(analyzer).each do |error_group_name, error_occurences|
|
84
84
|
error_occurences.map(&:line_number).each do |line|
|
85
85
|
file_and_line = "#{analyzer.file_path}:#{line}"
|
86
|
-
print "#{
|
86
|
+
print "#{Painter.paint(file_and_line, :red)} #{Fasterer::Offense::EXPLANATIONS[error_group_name]}.\n"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -112,7 +112,7 @@ module Fasterer
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def output_unable_to_find_file(path)
|
115
|
-
puts "No such file or directory - #{path}"
|
115
|
+
puts Painter.paint("No such file or directory - #{path}", :red)
|
116
116
|
end
|
117
117
|
|
118
118
|
def ignored_speedups
|
@@ -150,21 +150,19 @@ module Fasterer
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def inspected_files_output
|
153
|
-
"#{@files_inspected_count} #{pluralize(@files_inspected_count, 'file')} inspected"
|
154
|
-
.colorize(:green)
|
153
|
+
Painter.paint("#{@files_inspected_count} #{pluralize(@files_inspected_count, 'file')} inspected", :green)
|
155
154
|
end
|
156
155
|
|
157
156
|
def offenses_found_output
|
158
157
|
color = @offenses_found_count.zero? ? :green : :red
|
159
|
-
|
160
|
-
|
158
|
+
|
159
|
+
Painter.paint("#{@offenses_found_count} #{pluralize(@offenses_found_count, 'offense')} detected", color)
|
161
160
|
end
|
162
161
|
|
163
162
|
def unparsable_files_output
|
164
163
|
return if @unparsable_files_count.zero?
|
165
164
|
|
166
|
-
"#{@unparsable_files_count} unparsable #{pluralize(@unparsable_files_count, 'file')} found"
|
167
|
-
.colorize(:red)
|
165
|
+
Painter.paint("#{@unparsable_files_count} unparsable #{pluralize(@unparsable_files_count, 'file')} found", :red)
|
168
166
|
end
|
169
167
|
|
170
168
|
def pluralize(n, singular, plural = nil)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Fasterer
|
2
|
+
module Painter
|
3
|
+
COLOR_CODES = {
|
4
|
+
red: 31,
|
5
|
+
green: 32,
|
6
|
+
}
|
7
|
+
|
8
|
+
def self.paint(string, color)
|
9
|
+
color_code = COLOR_CODES[color.to_sym]
|
10
|
+
if color_code.nil?
|
11
|
+
raise ArgumentError, "Color #{color} is not supported. Allowed colors are #{COLOR_CODES.keys.join(', ')}"
|
12
|
+
end
|
13
|
+
paint_with_code(string, color_code)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.paint_with_code(string, color_code)
|
17
|
+
"\e[#{color_code}m#{string}\e[0m"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -86,6 +86,7 @@ module Fasterer
|
|
86
86
|
add_offense(:shuffle_first_vs_sample)
|
87
87
|
when :select
|
88
88
|
return unless method_call.receiver.has_block?
|
89
|
+
return if method_call.arguments.count > 0
|
89
90
|
|
90
91
|
add_offense(:select_first_vs_detect)
|
91
92
|
end
|
@@ -98,7 +99,9 @@ module Fasterer
|
|
98
99
|
when :reverse
|
99
100
|
add_offense(:reverse_each_vs_reverse_each)
|
100
101
|
when :keys
|
101
|
-
|
102
|
+
if method_call.receiver.arguments.count.zero?
|
103
|
+
add_offense(:keys_each_vs_each_key)
|
104
|
+
end
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
data/lib/fasterer/version.rb
CHANGED
@@ -348,7 +348,7 @@ describe Fasterer::FileTraverser do
|
|
348
348
|
let(:explanation) { Fasterer::Offense::EXPLANATIONS[:for_loop_vs_each] }
|
349
349
|
|
350
350
|
it 'should print offense' do
|
351
|
-
match = "\e[
|
351
|
+
match = "\e[31m#{test_file_path}:1\e[0m #{explanation}.\n\n"
|
352
352
|
|
353
353
|
expect { file_traverser.send(:output, analyzer) }.to output(match).to_stdout
|
354
354
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fasterer::Statistics do
|
4
|
+
let(:traverser_mock) do
|
5
|
+
traverser = OpenStruct.new
|
6
|
+
traverser.scannable_files = []
|
7
|
+
traverser.offenses_total_count = 0
|
8
|
+
traverser.parse_error_paths = []
|
9
|
+
traverser
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:statistics) { Fasterer::Statistics.new(traverser_mock) }
|
13
|
+
|
14
|
+
describe 'inspected_files_output' do
|
15
|
+
it 'should be green' do
|
16
|
+
expect(statistics.inspected_files_output)
|
17
|
+
.to eq("\e[32m0 files inspected\e[0m")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fasterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damir Svrtan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: colorize
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.7'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.7'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: ruby_parser
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +123,7 @@ files:
|
|
137
123
|
- lib/fasterer/method_definition.rb
|
138
124
|
- lib/fasterer/offense.rb
|
139
125
|
- lib/fasterer/offense_collector.rb
|
126
|
+
- lib/fasterer/painter.rb
|
140
127
|
- lib/fasterer/parser.rb
|
141
128
|
- lib/fasterer/rescue_call.rb
|
142
129
|
- lib/fasterer/scanners/method_call_scanner.rb
|
@@ -172,6 +159,7 @@ files:
|
|
172
159
|
- spec/lib/fasterer/method_call_spec.rb
|
173
160
|
- spec/lib/fasterer/method_definition_spec.rb
|
174
161
|
- spec/lib/fasterer/rescue_call_spec.rb
|
162
|
+
- spec/lib/fasterer/statistics_spec.rb
|
175
163
|
- spec/spec_helper.rb
|
176
164
|
- spec/support/analyzer/02_rescue_vs_respond_to.rb
|
177
165
|
- spec/support/analyzer/03_module_eval.rb
|
@@ -279,6 +267,7 @@ test_files:
|
|
279
267
|
- spec/lib/fasterer/method_call_spec.rb
|
280
268
|
- spec/lib/fasterer/method_definition_spec.rb
|
281
269
|
- spec/lib/fasterer/rescue_call_spec.rb
|
270
|
+
- spec/lib/fasterer/statistics_spec.rb
|
282
271
|
- spec/spec_helper.rb
|
283
272
|
- spec/support/analyzer/02_rescue_vs_respond_to.rb
|
284
273
|
- spec/support/analyzer/03_module_eval.rb
|