fasterer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fasterer/analyzer.rb +0 -1
- data/lib/fasterer/file_traverser.rb +56 -4
- data/lib/fasterer/method_call.rb +2 -4
- data/lib/fasterer/method_definition.rb +5 -7
- data/lib/fasterer/offense_collector.rb +1 -1
- data/lib/fasterer/rescue_call.rb +1 -4
- data/lib/fasterer/scanners/method_call_scanner.rb +2 -4
- data/lib/fasterer/scanners/method_definition_scanner.rb +5 -7
- data/lib/fasterer/scanners/offensive.rb +6 -8
- data/lib/fasterer/version.rb +1 -1
- data/spec/lib/fasterer/analyzer/01_parallel_assignment_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/02_rescue_vs_respond_to_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/03_module_eval_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/06_shuffle_first_vs_sample_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/08_for_loop_vs_each_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/09_each_with_index_vs_while_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/10_map_flatten_vs_flat_map_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/11_reverse_each_vs_reverse_each_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/12_select_first_vs_detect_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/13_sort_vs_sort_by_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/14_fetch_with_argument_vs_block_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/15_keys_each_vs_each_key_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/16_hash_merge_bang_vs_hash_brackets_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/18_block_vs_symbol_to_proc_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/19_proc_call_vs_yield_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/24_gsub_vs_tr_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/26_getter_vs_attr_reader_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/27_setter_vs_attr_writer_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/29_include_vs_cover_on_range_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/98_misc_spec.rb +0 -1
- data/spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb +0 -1
- data/spec/lib/fasterer/cli_spec.rb +3 -3
- data/spec/lib/fasterer/file_traverser_spec.rb +1 -1
- data/spec/lib/fasterer/method_call_spec.rb +0 -56
- data/spec/lib/fasterer/method_definition_spec.rb +0 -16
- data/spec/lib/fasterer/rescue_call_spec.rb +0 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4705338687a1a2cff20a0834e7ab76740f1ba62a
|
4
|
+
data.tar.gz: 0355a36451b7635e70b3f670d95b0a76b12bd036
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e54c755f4cb43d47d05a9a64a50fb95b592770c7b91d2e442b331a445e0a8089eda864ac604e34e7100f72e6385d6b2a16b46a9c35d32844220e3cb7b11250e
|
7
|
+
data.tar.gz: 32d38035fdeb87eac46f8b54e1fa398f69e37c819eb703cbf94050fe4520f3e0990a69bb7dc76c42455e605cab7678a2af67d603772c0606ff9e8974ead68962
|
data/lib/fasterer/analyzer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'colorize'
|
3
|
+
require 'English'
|
3
4
|
|
4
5
|
require_relative 'analyzer'
|
5
6
|
require_relative 'config'
|
@@ -12,11 +13,13 @@ module Fasterer
|
|
12
13
|
|
13
14
|
attr_reader :config
|
14
15
|
attr_reader :parse_error_paths
|
16
|
+
attr_accessor :offenses_total_count
|
15
17
|
|
16
18
|
def initialize(path)
|
17
19
|
@path = Pathname(path)
|
18
20
|
@parse_error_paths = []
|
19
21
|
@config = Config.new
|
22
|
+
@offenses_total_count = 0
|
20
23
|
end
|
21
24
|
|
22
25
|
def traverse
|
@@ -26,6 +29,7 @@ module Fasterer
|
|
26
29
|
scan_file(@path)
|
27
30
|
end
|
28
31
|
output_parse_errors if parse_error_paths.any?
|
32
|
+
output_statistics
|
29
33
|
end
|
30
34
|
|
31
35
|
def config_file
|
@@ -36,6 +40,10 @@ module Fasterer
|
|
36
40
|
!!offenses_found
|
37
41
|
end
|
38
42
|
|
43
|
+
def scannable_files
|
44
|
+
all_files - ignored_files
|
45
|
+
end
|
46
|
+
|
39
47
|
private
|
40
48
|
|
41
49
|
attr_accessor :offenses_found
|
@@ -49,13 +57,10 @@ module Fasterer
|
|
49
57
|
if offenses_grouped_by_type(analyzer).any?
|
50
58
|
output(analyzer)
|
51
59
|
self.offenses_found = true
|
60
|
+
self.offenses_total_count += analyzer.errors.count
|
52
61
|
end
|
53
62
|
end
|
54
63
|
|
55
|
-
def scannable_files
|
56
|
-
all_files - ignored_files
|
57
|
-
end
|
58
|
-
|
59
64
|
def all_files
|
60
65
|
Dir["#{@path}/**/*.rb"].map do |ruby_file_path|
|
61
66
|
Pathname(ruby_file_path).relative_path_from(@path).to_s
|
@@ -85,6 +90,11 @@ module Fasterer
|
|
85
90
|
puts 'has timed out. Unprocessable files were:'
|
86
91
|
puts '-----------------------------------------------------'
|
87
92
|
puts parse_error_paths
|
93
|
+
puts
|
94
|
+
end
|
95
|
+
|
96
|
+
def output_statistics
|
97
|
+
puts Statistics.new(self)
|
88
98
|
end
|
89
99
|
|
90
100
|
def ignored_speedups
|
@@ -105,4 +115,46 @@ module Fasterer
|
|
105
115
|
"#{file_path} - #{error_class} - #{error_message}"
|
106
116
|
end
|
107
117
|
end
|
118
|
+
|
119
|
+
class Statistics
|
120
|
+
def initialize(traverser)
|
121
|
+
@files_inspected_count = traverser.scannable_files.count
|
122
|
+
@offenses_found_count = traverser.offenses_total_count
|
123
|
+
@unparsable_files_count = traverser.parse_error_paths.count
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_s
|
127
|
+
[
|
128
|
+
inspected_files_output,
|
129
|
+
offenses_found_output,
|
130
|
+
unparsable_files_output
|
131
|
+
].compact.join(', ')
|
132
|
+
end
|
133
|
+
|
134
|
+
def inspected_files_output
|
135
|
+
"#{@files_inspected_count} #{pluralize(@files_inspected_count, 'file')} inspected"
|
136
|
+
.colorize(:green)
|
137
|
+
end
|
138
|
+
|
139
|
+
def offenses_found_output
|
140
|
+
"#{@offenses_found_count} #{pluralize(@offenses_found_count, 'offense')} detected"
|
141
|
+
.colorize(:red)
|
142
|
+
end
|
143
|
+
|
144
|
+
def unparsable_files_output
|
145
|
+
return if @unparsable_files_count.zero?
|
146
|
+
"#{@unparsable_files_count} unparsable #{pluralize(@unparsable_files_count, 'file')} found"
|
147
|
+
.colorize(:red)
|
148
|
+
end
|
149
|
+
|
150
|
+
def pluralize(n, singular, plural = nil)
|
151
|
+
if n == 1
|
152
|
+
"#{singular}"
|
153
|
+
elsif plural
|
154
|
+
"#{plural}"
|
155
|
+
else
|
156
|
+
"#{singular}s"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
108
160
|
end
|
data/lib/fasterer/method_call.rb
CHANGED
@@ -64,14 +64,12 @@ module Fasterer
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def set_block_body
|
67
|
-
if has_block?
|
68
|
-
@block_body = element[3]
|
69
|
-
end
|
67
|
+
@block_body = element[3] if has_block?
|
70
68
|
end
|
71
69
|
|
72
70
|
# TODO: write specs for lambdas and procs
|
73
71
|
def set_block_argument_names
|
74
|
-
@block_argument_names = if has_block? && element[2].is_a?(Sexp) #
|
72
|
+
@block_argument_names = if has_block? && element[2].is_a?(Sexp) # HACK: for lambdas
|
75
73
|
element[2].drop(1).map { |argument| argument }
|
76
74
|
end || []
|
77
75
|
end
|
@@ -56,7 +56,6 @@ module Fasterer
|
|
56
56
|
end
|
57
57
|
|
58
58
|
class MethodDefinitionArgument
|
59
|
-
|
60
59
|
attr_reader :element, :name, :type
|
61
60
|
|
62
61
|
def initialize(element)
|
@@ -85,13 +84,12 @@ module Fasterer
|
|
85
84
|
|
86
85
|
def set_argument_type
|
87
86
|
@type = if element.is_a?(Symbol)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
:regular_argument
|
88
|
+
elsif element.is_a?(Sexp) && element.sexp_type == :lasgn
|
89
|
+
:default_argument
|
90
|
+
elsif element.is_a?(Sexp) && element.sexp_type == :kwarg
|
91
|
+
:keyword_argument
|
93
92
|
end
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
95
|
end
|
data/lib/fasterer/rescue_call.rb
CHANGED
@@ -15,11 +15,8 @@ module Fasterer
|
|
15
15
|
return if element[1].sexp_type != :array
|
16
16
|
|
17
17
|
@rescue_classes = element[1].drop(1).map do |rescue_reference|
|
18
|
-
if rescue_reference.sexp_type == :const
|
19
|
-
rescue_reference[1]
|
20
|
-
end
|
18
|
+
rescue_reference[1] if rescue_reference.sexp_type == :const
|
21
19
|
end.compact
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
22
|
end
|
@@ -50,9 +50,7 @@ module Fasterer
|
|
50
50
|
first_argument = method_call.arguments.first
|
51
51
|
return unless first_argument && first_argument.value.is_a?(String)
|
52
52
|
|
53
|
-
if first_argument.value.include?(
|
54
|
-
add_offense(:module_eval)
|
55
|
-
end
|
53
|
+
add_offense(:module_eval) if first_argument.value.include?('def')
|
56
54
|
end
|
57
55
|
|
58
56
|
def check_gsub_offense
|
@@ -62,7 +60,7 @@ module Fasterer
|
|
62
60
|
return if first_argument.nil? || second_argument.nil?
|
63
61
|
|
64
62
|
if first_argument.value.is_a?(String) && first_argument.value.size == 1 &&
|
65
|
-
|
63
|
+
second_argument.value.is_a?(String) && second_argument.value.size == 1
|
66
64
|
|
67
65
|
add_offense(:gsub_vs_tr)
|
68
66
|
end
|
@@ -31,8 +31,8 @@ module Fasterer
|
|
31
31
|
method_call = MethodCall.new(element)
|
32
32
|
|
33
33
|
if method_call.receiver.is_a?(Fasterer::VariableReference) &&
|
34
|
-
|
35
|
-
|
34
|
+
method_call.receiver.name == method_definition.block_argument_name &&
|
35
|
+
method_call.method_name == :call
|
36
36
|
|
37
37
|
add_offense(:proc_call_vs_yield) && return
|
38
38
|
end
|
@@ -63,8 +63,8 @@ module Fasterer
|
|
63
63
|
return if first_argument.type != :regular_argument
|
64
64
|
|
65
65
|
if method_definition.body.first.sexp_type == :iasgn &&
|
66
|
-
|
67
|
-
|
66
|
+
method_definition.body.first[1].to_s == "@#{method_definition.name.to_s[0..-2]}" &&
|
67
|
+
method_definition.body.first[2][1] == first_argument.name
|
68
68
|
|
69
69
|
add_offense(:setter_vs_attr_writer)
|
70
70
|
end
|
@@ -75,12 +75,10 @@ module Fasterer
|
|
75
75
|
return if method_definition.body.size != 1
|
76
76
|
|
77
77
|
if method_definition.body.first.sexp_type == :ivar &&
|
78
|
-
|
78
|
+
method_definition.body.first[1].to_s == "@#{method_definition.name}"
|
79
79
|
|
80
80
|
add_offense(:getter_vs_attr_reader)
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
84
83
|
end
|
85
|
-
|
86
84
|
end
|
@@ -2,7 +2,6 @@ require 'fasterer/offense'
|
|
2
2
|
|
3
3
|
module Fasterer
|
4
4
|
module Offensive
|
5
|
-
|
6
5
|
attr_accessor :offense
|
7
6
|
|
8
7
|
def offensive?
|
@@ -13,13 +12,12 @@ module Fasterer
|
|
13
12
|
|
14
13
|
private
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def check_offense
|
21
|
-
raise NotImplementedError
|
22
|
-
end
|
15
|
+
def add_offense(offense_name, element_line_number = element.line)
|
16
|
+
self.offense = Fasterer::Offense.new(offense_name, element_line_number)
|
17
|
+
end
|
23
18
|
|
19
|
+
def check_offense
|
20
|
+
fail NotImplementedError
|
21
|
+
end
|
24
22
|
end
|
25
23
|
end
|
data/lib/fasterer/version.rb
CHANGED
@@ -8,13 +8,13 @@ describe Fasterer::FileTraverser do
|
|
8
8
|
context 'success' do
|
9
9
|
it 'when no files exist' do
|
10
10
|
`#{fasterer_bin}`
|
11
|
-
expect(
|
11
|
+
expect($CHILD_STATUS.exitstatus).to eq(0)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'when no files with offenses exist' do
|
15
15
|
create_file('user.rb', '[].sample')
|
16
16
|
`#{fasterer_bin}`
|
17
|
-
expect(
|
17
|
+
expect($CHILD_STATUS.exitstatus).to eq(0)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,7 +22,7 @@ describe Fasterer::FileTraverser do
|
|
22
22
|
it 'when file with offenses exists' do
|
23
23
|
create_file('user.rb', '[].shuffle.first')
|
24
24
|
`#{fasterer_bin}`
|
25
|
-
expect(
|
25
|
+
expect($CHILD_STATUS.exitstatus).to eq(1)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fasterer::MethodCall do
|
4
|
-
|
5
4
|
let(:ripper) do
|
6
5
|
Fasterer::Parser.parse(code)
|
7
6
|
end
|
@@ -13,7 +12,6 @@ describe Fasterer::MethodCall do
|
|
13
12
|
describe 'with explicit receiver' do
|
14
13
|
describe 'without arguments, without block, called with parentheses' do
|
15
14
|
describe 'method call on a constant' do
|
16
|
-
|
17
15
|
let(:code) { 'User.hello()' }
|
18
16
|
|
19
17
|
# This is where the :call token will be recognized.
|
@@ -23,11 +21,9 @@ describe Fasterer::MethodCall do
|
|
23
21
|
expect(method_call.method_name).to eq(:hello)
|
24
22
|
expect(method_call.arguments).to be_empty
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
28
25
|
|
29
26
|
describe 'method call on a integer' do
|
30
|
-
|
31
27
|
let(:code) { '1.hello()' }
|
32
28
|
|
33
29
|
# This is where the :call token will be recognized.
|
@@ -37,11 +33,9 @@ describe Fasterer::MethodCall do
|
|
37
33
|
expect(method_call.method_name).to eq(:hello)
|
38
34
|
expect(method_call.arguments).to be_empty
|
39
35
|
end
|
40
|
-
|
41
36
|
end
|
42
37
|
|
43
38
|
describe 'method call on a string' do
|
44
|
-
|
45
39
|
let(:code) { "'hello'.hello()" }
|
46
40
|
|
47
41
|
let(:call_element) { ripper }
|
@@ -50,11 +44,9 @@ describe Fasterer::MethodCall do
|
|
50
44
|
expect(method_call.method_name).to eq(:hello)
|
51
45
|
expect(method_call.arguments).to be_empty
|
52
46
|
end
|
53
|
-
|
54
47
|
end
|
55
48
|
|
56
49
|
describe 'method call on a variable' do
|
57
|
-
|
58
50
|
let(:code) do
|
59
51
|
"number_one = 1\n"\
|
60
52
|
'number_one.hello()'
|
@@ -68,11 +60,9 @@ describe Fasterer::MethodCall do
|
|
68
60
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
69
61
|
expect(method_call.receiver.name).to eq(:number_one)
|
70
62
|
end
|
71
|
-
|
72
63
|
end
|
73
64
|
|
74
65
|
describe 'method call on a method' do
|
75
|
-
|
76
66
|
let(:code) { '1.hi(2).hello()' }
|
77
67
|
|
78
68
|
let(:call_element) { ripper }
|
@@ -83,13 +73,11 @@ describe Fasterer::MethodCall do
|
|
83
73
|
expect(method_call.receiver.name).to eq(:hi)
|
84
74
|
expect(method_call.arguments).to be_empty
|
85
75
|
end
|
86
|
-
|
87
76
|
end
|
88
77
|
end
|
89
78
|
|
90
79
|
describe 'without arguments, without block, called without parentheses' do
|
91
80
|
describe 'method call on a constant' do
|
92
|
-
|
93
81
|
let(:code) { 'User.hello' }
|
94
82
|
|
95
83
|
let(:call_element) { ripper }
|
@@ -98,11 +86,9 @@ describe Fasterer::MethodCall do
|
|
98
86
|
expect(method_call.method_name).to eq(:hello)
|
99
87
|
expect(method_call.arguments).to be_empty
|
100
88
|
end
|
101
|
-
|
102
89
|
end
|
103
90
|
|
104
91
|
describe 'method call on a integer' do
|
105
|
-
|
106
92
|
let(:code) { '1.hello' }
|
107
93
|
|
108
94
|
# This is where the :call token will be recognized.
|
@@ -112,11 +98,9 @@ describe Fasterer::MethodCall do
|
|
112
98
|
expect(method_call.method_name).to eq(:hello)
|
113
99
|
expect(method_call.arguments).to be_empty
|
114
100
|
end
|
115
|
-
|
116
101
|
end
|
117
102
|
|
118
103
|
describe 'method call on a string' do
|
119
|
-
|
120
104
|
let(:code) { "'hello'.hello" }
|
121
105
|
|
122
106
|
let(:call_element) { ripper }
|
@@ -125,11 +109,9 @@ describe Fasterer::MethodCall do
|
|
125
109
|
expect(method_call.method_name).to eq(:hello)
|
126
110
|
expect(method_call.arguments).to be_empty
|
127
111
|
end
|
128
|
-
|
129
112
|
end
|
130
113
|
|
131
114
|
describe 'method call on a variable' do
|
132
|
-
|
133
115
|
let(:code) do
|
134
116
|
"number_one = 1\n"\
|
135
117
|
'number_one.hello'
|
@@ -143,11 +125,9 @@ describe Fasterer::MethodCall do
|
|
143
125
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
144
126
|
expect(method_call.receiver.name).to eq(:number_one)
|
145
127
|
end
|
146
|
-
|
147
128
|
end
|
148
129
|
|
149
130
|
describe 'method call on a method' do
|
150
|
-
|
151
131
|
let(:code) { '1.hi(2).hello' }
|
152
132
|
|
153
133
|
let(:call_element) { ripper }
|
@@ -158,14 +138,11 @@ describe Fasterer::MethodCall do
|
|
158
138
|
expect(method_call.receiver.name).to eq(:hi)
|
159
139
|
expect(method_call.arguments).to be_empty
|
160
140
|
end
|
161
|
-
|
162
141
|
end
|
163
142
|
end
|
164
143
|
|
165
144
|
describe 'with do end block' do
|
166
|
-
|
167
145
|
describe 'and no arguments, without block parameter' do
|
168
|
-
|
169
146
|
let(:code) do
|
170
147
|
<<-code
|
171
148
|
number_one.fetch do
|
@@ -184,11 +161,9 @@ describe Fasterer::MethodCall do
|
|
184
161
|
expect(method_call.block_argument_names.count).to be(0)
|
185
162
|
expect(method_call.receiver).to be_a(Fasterer::MethodCall)
|
186
163
|
end
|
187
|
-
|
188
164
|
end
|
189
165
|
|
190
166
|
describe 'and no arguments, with block parameter' do
|
191
|
-
|
192
167
|
let(:code) do
|
193
168
|
<<-code
|
194
169
|
number_one.fetch do |el|
|
@@ -208,11 +183,9 @@ describe Fasterer::MethodCall do
|
|
208
183
|
expect(method_call.block_argument_names.first).to be(:el)
|
209
184
|
expect(method_call.receiver).to be_a(Fasterer::MethodCall)
|
210
185
|
end
|
211
|
-
|
212
186
|
end
|
213
187
|
|
214
188
|
describe 'and no arguments, with block parameter' do
|
215
|
-
|
216
189
|
let(:code) do
|
217
190
|
<<-code
|
218
191
|
number_one.fetch do |el, tip|
|
@@ -233,11 +206,9 @@ describe Fasterer::MethodCall do
|
|
233
206
|
expect(method_call.block_argument_names.last).to be(:tip)
|
234
207
|
expect(method_call.receiver).to be_a(Fasterer::MethodCall)
|
235
208
|
end
|
236
|
-
|
237
209
|
end
|
238
210
|
|
239
211
|
describe 'and one argument within parentheses' do
|
240
|
-
|
241
212
|
let(:code) do
|
242
213
|
<<-code
|
243
214
|
number_one = 1
|
@@ -256,13 +227,11 @@ describe Fasterer::MethodCall do
|
|
256
227
|
expect(method_call.has_block?).to be
|
257
228
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
258
229
|
end
|
259
|
-
|
260
230
|
end
|
261
231
|
end
|
262
232
|
|
263
233
|
describe 'with curly block' do
|
264
234
|
describe 'in one line' do
|
265
|
-
|
266
235
|
let(:code) do
|
267
236
|
<<-code
|
268
237
|
number_one = 1
|
@@ -278,11 +247,9 @@ describe Fasterer::MethodCall do
|
|
278
247
|
expect(method_call.has_block?).to be
|
279
248
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
280
249
|
end
|
281
|
-
|
282
250
|
end
|
283
251
|
|
284
252
|
describe 'multi lined' do
|
285
|
-
|
286
253
|
let(:code) do
|
287
254
|
<<-code
|
288
255
|
number_one = 1
|
@@ -301,14 +268,11 @@ describe Fasterer::MethodCall do
|
|
301
268
|
expect(method_call.has_block?).to be
|
302
269
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
303
270
|
end
|
304
|
-
|
305
271
|
end
|
306
272
|
end
|
307
273
|
|
308
274
|
describe 'with arguments, without block, called with parentheses' do
|
309
|
-
|
310
275
|
describe 'method call with an argument' do
|
311
|
-
|
312
276
|
let(:code) { '{}.fetch(:writing)' }
|
313
277
|
|
314
278
|
let(:call_element) { ripper }
|
@@ -318,13 +282,11 @@ describe Fasterer::MethodCall do
|
|
318
282
|
expect(method_call.arguments.count).to eq(1)
|
319
283
|
expect(method_call.arguments.first.type).to eq(:lit)
|
320
284
|
end
|
321
|
-
|
322
285
|
end
|
323
286
|
end
|
324
287
|
|
325
288
|
describe 'arguments without parenthesis' do
|
326
289
|
describe 'method call with an argument' do
|
327
|
-
|
328
290
|
let(:code) { '{}.fetch :writing, :listening' }
|
329
291
|
|
330
292
|
let(:call_element) { ripper }
|
@@ -335,7 +297,6 @@ describe Fasterer::MethodCall do
|
|
335
297
|
expect(method_call.arguments[0].type).to eq(:lit)
|
336
298
|
expect(method_call.arguments[1].type).to eq(:lit)
|
337
299
|
end
|
338
|
-
|
339
300
|
end
|
340
301
|
end
|
341
302
|
end
|
@@ -344,7 +305,6 @@ describe Fasterer::MethodCall do
|
|
344
305
|
end
|
345
306
|
|
346
307
|
describe 'method call with an argument and a block' do
|
347
|
-
|
348
308
|
let(:code) do
|
349
309
|
<<-code
|
350
310
|
number_one = 1
|
@@ -361,11 +321,9 @@ describe Fasterer::MethodCall do
|
|
361
321
|
expect(method_call.has_block?).to be
|
362
322
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
363
323
|
end
|
364
|
-
|
365
324
|
end
|
366
325
|
|
367
326
|
describe 'method call without an explicit receiver' do
|
368
|
-
|
369
327
|
let(:code) { 'fetch(:writing, :listening)' }
|
370
328
|
|
371
329
|
let(:call_element) { ripper }
|
@@ -377,11 +335,9 @@ describe Fasterer::MethodCall do
|
|
377
335
|
expect(method_call.arguments[1].type).to eq(:lit)
|
378
336
|
expect(method_call.receiver).to be_nil
|
379
337
|
end
|
380
|
-
|
381
338
|
end
|
382
339
|
|
383
340
|
describe 'method call without an explicit receiver and without brackets' do
|
384
|
-
|
385
341
|
let(:code) { 'fetch :writing, :listening' }
|
386
342
|
|
387
343
|
let(:call_element) { ripper }
|
@@ -393,11 +349,9 @@ describe Fasterer::MethodCall do
|
|
393
349
|
expect(method_call.arguments[1].type).to eq(:lit)
|
394
350
|
expect(method_call.receiver).to be_nil
|
395
351
|
end
|
396
|
-
|
397
352
|
end
|
398
353
|
|
399
354
|
describe 'method call without an explicit receiver and without brackets and do end' do
|
400
|
-
|
401
355
|
let(:code) do
|
402
356
|
<<-code
|
403
357
|
"fetch :writing do\n"\
|
@@ -414,11 +368,9 @@ describe Fasterer::MethodCall do
|
|
414
368
|
# expect(method_call.arguments[1].type).to eq(:symbol_literal)
|
415
369
|
# expect(method_call.receiver).to be_nil
|
416
370
|
end
|
417
|
-
|
418
371
|
end
|
419
372
|
|
420
373
|
describe 'method call with two arguments' do
|
421
|
-
|
422
374
|
let(:code) do
|
423
375
|
"number_one = 1\n"\
|
424
376
|
'number_one.fetch(:writing, :zumba)'
|
@@ -433,11 +385,9 @@ describe Fasterer::MethodCall do
|
|
433
385
|
expect(method_call.arguments[1].type).to eq(:lit)
|
434
386
|
expect(method_call.receiver).to be_a(Fasterer::VariableReference)
|
435
387
|
end
|
436
|
-
|
437
388
|
end
|
438
389
|
|
439
390
|
describe 'method call with a regex argument' do
|
440
|
-
|
441
391
|
let(:code) { '{}.fetch(/.*/)' }
|
442
392
|
|
443
393
|
let(:call_element) { ripper }
|
@@ -448,11 +398,9 @@ describe Fasterer::MethodCall do
|
|
448
398
|
expect(method_call.arguments[0].type).to eq(:lit)
|
449
399
|
expect(method_call.arguments[0].value).to be_a(Regexp)
|
450
400
|
end
|
451
|
-
|
452
401
|
end
|
453
402
|
|
454
403
|
describe 'method call with a integer argument' do
|
455
|
-
|
456
404
|
let(:code) { '[].flatten(1)' }
|
457
405
|
|
458
406
|
let(:call_element) { ripper }
|
@@ -463,7 +411,6 @@ describe Fasterer::MethodCall do
|
|
463
411
|
expect(method_call.arguments[0].type).to eq(:lit)
|
464
412
|
expect(method_call.arguments[0].value).to eq(1)
|
465
413
|
end
|
466
|
-
|
467
414
|
end
|
468
415
|
|
469
416
|
describe 'method call with symbol to proc argument' do
|
@@ -480,7 +427,6 @@ describe Fasterer::MethodCall do
|
|
480
427
|
end
|
481
428
|
|
482
429
|
describe 'method call with equals operator' do
|
483
|
-
|
484
430
|
let(:code) { 'method_call_with_equals.rb' }
|
485
431
|
|
486
432
|
let(:call_element) { ripper.drop(1).first.first[1] }
|
@@ -490,7 +436,5 @@ describe Fasterer::MethodCall do
|
|
490
436
|
# expect(method_call.receiver).to be_a(Fasterer::MethodCall)
|
491
437
|
# expect(method_call.receiver.name).to eq('hi')
|
492
438
|
end
|
493
|
-
|
494
439
|
end
|
495
|
-
|
496
440
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fasterer::MethodDefinition do
|
4
|
-
|
5
4
|
let(:def_element) do
|
6
5
|
Fasterer::Parser.parse(File.read(RSpec.root.join('support', 'method_definition', file_name)))
|
7
6
|
end
|
@@ -11,40 +10,33 @@ describe Fasterer::MethodDefinition do
|
|
11
10
|
end
|
12
11
|
|
13
12
|
describe 'method with no arguments' do
|
14
|
-
|
15
13
|
let(:file_name) { 'simple_method.rb' }
|
16
14
|
|
17
15
|
it 'should not detect block' do
|
18
16
|
expect(method_definition.method_name).to eq(:hello)
|
19
17
|
expect(method_definition.has_block?).to eq(false)
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
|
24
21
|
describe 'method with no arguments and omitted parenthesis' do
|
25
|
-
|
26
22
|
let(:file_name) { 'simple_method_omitted_parenthesis.rb' }
|
27
23
|
|
28
24
|
it 'should not detect block' do
|
29
25
|
expect(method_definition.method_name).to eq(:hello)
|
30
26
|
expect(method_definition.has_block?).to eq(false)
|
31
27
|
end
|
32
|
-
|
33
28
|
end
|
34
29
|
|
35
30
|
describe 'method with one argument' do
|
36
|
-
|
37
31
|
let(:file_name) { 'simple_method_with_argument.rb' }
|
38
32
|
|
39
33
|
it 'should not detect block' do
|
40
34
|
expect(method_definition.method_name).to eq(:hello)
|
41
35
|
expect(method_definition.has_block?).to eq(false)
|
42
36
|
end
|
43
|
-
|
44
37
|
end
|
45
38
|
|
46
39
|
describe 'method with a block' do
|
47
|
-
|
48
40
|
let(:file_name) { 'method_with_block.rb' }
|
49
41
|
|
50
42
|
it 'should detect block' do
|
@@ -52,11 +44,9 @@ describe Fasterer::MethodDefinition do
|
|
52
44
|
expect(method_definition.has_block?).to eq(true)
|
53
45
|
expect(method_definition.block_argument_name).to eq(:block)
|
54
46
|
end
|
55
|
-
|
56
47
|
end
|
57
48
|
|
58
49
|
describe 'method with an argument and a block' do
|
59
|
-
|
60
50
|
let(:file_name) { 'method_with_argument_and_block.rb' }
|
61
51
|
|
62
52
|
it 'should detect block' do
|
@@ -64,11 +54,9 @@ describe Fasterer::MethodDefinition do
|
|
64
54
|
expect(method_definition.has_block?).to eq(true)
|
65
55
|
expect(method_definition.block_argument_name).to eq(:block)
|
66
56
|
end
|
67
|
-
|
68
57
|
end
|
69
58
|
|
70
59
|
describe 'method with an splat argument and a block' do
|
71
|
-
|
72
60
|
let(:file_name) { 'method_with_splat_and_block.rb' }
|
73
61
|
|
74
62
|
it 'should detect block' do
|
@@ -76,18 +64,14 @@ describe Fasterer::MethodDefinition do
|
|
76
64
|
expect(method_definition.has_block?).to eq(true)
|
77
65
|
expect(method_definition.block_argument_name).to eq(:block)
|
78
66
|
end
|
79
|
-
|
80
67
|
end
|
81
68
|
|
82
69
|
describe 'method with an default argument' do
|
83
|
-
|
84
70
|
let(:file_name) { 'method_with_default_argument.rb' }
|
85
71
|
|
86
72
|
it 'should not detect block' do
|
87
73
|
expect(method_definition.method_name).to eq(:hello)
|
88
74
|
expect(method_definition.has_block?).to eq(false)
|
89
75
|
end
|
90
|
-
|
91
76
|
end
|
92
|
-
|
93
77
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fasterer::RescueCall do
|
4
|
-
|
5
4
|
let(:file_path) { RSpec.root.join('support', 'rescue_call', file_name) }
|
6
5
|
|
7
6
|
let(:rescue_element) do
|
@@ -14,63 +13,50 @@ describe Fasterer::RescueCall do
|
|
14
13
|
end
|
15
14
|
|
16
15
|
describe 'plain rescue call' do
|
17
|
-
|
18
16
|
let(:file_name) { 'plain_rescue.rb' }
|
19
17
|
|
20
18
|
it 'should detect constant' do
|
21
19
|
expect(rescue_call.rescue_classes).to eq([])
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
22
|
|
26
23
|
describe 'rescue call with class' do
|
27
|
-
|
28
24
|
let(:file_name) { 'rescue_with_class.rb' }
|
29
25
|
|
30
26
|
it 'should detect integer' do
|
31
27
|
expect(rescue_call.rescue_classes).to eq([:NoMethodError])
|
32
28
|
end
|
33
|
-
|
34
29
|
end
|
35
30
|
|
36
31
|
describe 'rescue call with class and variable' do
|
37
|
-
|
38
32
|
let(:file_name) { 'rescue_with_class_and_variable.rb' }
|
39
33
|
|
40
34
|
it 'should detect string' do
|
41
35
|
expect(rescue_call.rescue_classes).to eq([:NoMethodError])
|
42
36
|
end
|
43
|
-
|
44
37
|
end
|
45
38
|
|
46
39
|
describe 'rescue call with variable' do
|
47
|
-
|
48
40
|
let(:file_name) { 'rescue_with_variable.rb' }
|
49
41
|
|
50
42
|
it 'should detect variable' do
|
51
43
|
expect(rescue_call.rescue_classes).to eq([])
|
52
44
|
end
|
53
|
-
|
54
45
|
end
|
55
46
|
|
56
47
|
describe 'rescue call with multiple classes' do
|
57
|
-
|
58
48
|
let(:file_name) { 'rescue_with_multiple_classes.rb' }
|
59
49
|
|
60
50
|
it 'should detect method' do
|
61
51
|
expect(rescue_call.rescue_classes).to eq([:NoMethodError, :StandardError])
|
62
52
|
end
|
63
|
-
|
64
53
|
end
|
65
54
|
|
66
55
|
describe 'rescue call with multiple classes and variable' do
|
67
|
-
|
68
56
|
let(:file_name) { 'rescue_with_multiple_classes_and_variable.rb' }
|
69
57
|
|
70
58
|
it 'should detect method' do
|
71
59
|
expect(rescue_call.rescue_classes).to eq([:NoMethodError, :StandardError])
|
72
60
|
end
|
73
|
-
|
74
61
|
end
|
75
|
-
|
76
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fasterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damir Svrtan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|