kevinrutherford-reek 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/reek/code_parser.rb +0 -24
- data/lib/reek/name.rb +1 -1
- data/lib/reek/object_source.rb +45 -0
- data/lib/reek/source.rb +5 -18
- data/lib/reek/spec.rb +0 -6
- data/lib/reek.rb +1 -1
- data/reek.gemspec +7 -8
- metadata +6 -6
- data/spec/reek/sexp_formatter_spec.rb +0 -32
data/History.txt
CHANGED
data/lib/reek/code_parser.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'parse_tree'
|
3
2
|
require 'sexp_processor'
|
4
3
|
require 'reek/block_context'
|
5
4
|
require 'reek/class_context'
|
@@ -22,10 +21,6 @@ module Reek
|
|
22
21
|
return unifier.process(sexp[0])
|
23
22
|
end
|
24
23
|
|
25
|
-
def self.parse_tree_for(code) # :nodoc:
|
26
|
-
unify(ParseTree.new.parse_tree_for_string(code))
|
27
|
-
end
|
28
|
-
|
29
24
|
# Creates a new Ruby code checker. Any smells discovered by
|
30
25
|
# +check_source+ or +check_object+ will be stored in +report+.
|
31
26
|
def initialize(report, smells, ctx = StopContext.new)
|
@@ -38,21 +33,6 @@ module Reek
|
|
38
33
|
@require_empty = @warn_on_default = false
|
39
34
|
end
|
40
35
|
|
41
|
-
# Analyses the given Ruby source +code+ looking for smells.
|
42
|
-
# Any smells found are saved in the +Report+ object that
|
43
|
-
# was passed to this object's constructor.
|
44
|
-
def check_source(code)
|
45
|
-
check_parse_tree(CodeParser.parse_tree_for(code))
|
46
|
-
end
|
47
|
-
|
48
|
-
# Analyses the given Ruby object +obj+ looking for smells.
|
49
|
-
# Any smells found are saved in the +Report+ object that
|
50
|
-
# was passed to this object's constructor.
|
51
|
-
def check_object(obj)
|
52
|
-
sexp = CodeParser.unify(ParseTree.new.parse_tree(obj))
|
53
|
-
check_parse_tree(sexp)
|
54
|
-
end
|
55
|
-
|
56
36
|
def process_default(exp)
|
57
37
|
exp[0..-1].each { |sub| process(sub) if Array === sub }
|
58
38
|
s(exp)
|
@@ -211,9 +191,5 @@ module Reek
|
|
211
191
|
@element = @element.outer
|
212
192
|
s(exp)
|
213
193
|
end
|
214
|
-
|
215
|
-
def check_parse_tree(sexp) # :nodoc:
|
216
|
-
process(sexp)
|
217
|
-
end
|
218
194
|
end
|
219
195
|
end
|
data/lib/reek/name.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Reek
|
2
|
+
class Source
|
3
|
+
#
|
4
|
+
# Factory method: creates a +Source+ from obj.
|
5
|
+
# The code is not parsed until +report+ is called.
|
6
|
+
# (This feature is only enabled if you have the ParseTree gem installed.)
|
7
|
+
#
|
8
|
+
def self.from_object(obj)
|
9
|
+
return ObjectSource.new(obj, obj.to_s)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class ObjectSource < Source # :nodoc:
|
14
|
+
def can_parse_objects?
|
15
|
+
return true if Object.const_defined?(:ParseTree)
|
16
|
+
begin
|
17
|
+
require 'parse_tree'
|
18
|
+
true
|
19
|
+
rescue LoadError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def check(parser) # :nodoc:
|
25
|
+
if can_parse_objects?
|
26
|
+
sexp = CodeParser.unify(ParseTree.new.parse_tree(@source))
|
27
|
+
parser.process(sexp)
|
28
|
+
else
|
29
|
+
throw ArgumentError.new('You must install the ParseTree gem to use this feature')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Object
|
36
|
+
#
|
37
|
+
# Constructs a Source representing this object; the source can then be used
|
38
|
+
# to generate an abstract syntax tree for the object, which can in turn then
|
39
|
+
# be examined for code smells.
|
40
|
+
# (This feature is only enabled if you have the ParseTree gem installed.)
|
41
|
+
#
|
42
|
+
def to_source
|
43
|
+
Reek::Source.from_object(self)
|
44
|
+
end
|
45
|
+
end
|
data/lib/reek/source.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'reek/code_parser'
|
2
2
|
require 'reek/report'
|
3
3
|
require 'reek/smells/smells'
|
4
|
+
require 'ruby_parser'
|
4
5
|
|
5
6
|
module Reek
|
6
7
|
|
@@ -12,14 +13,6 @@ module Reek
|
|
12
13
|
#
|
13
14
|
class Source
|
14
15
|
|
15
|
-
#
|
16
|
-
# Factory method: creates a +Source+ from obj.
|
17
|
-
# The code is not parsed until +report+ is called.
|
18
|
-
#
|
19
|
-
def self.from_object(obj)
|
20
|
-
return ObjectSource.new(obj, obj.to_s)
|
21
|
-
end
|
22
|
-
|
23
16
|
#
|
24
17
|
# Factory method: creates a +Source+ object by reading Ruby code from
|
25
18
|
# the +IO+ stream. The stream is consumed upto end-of-file, but the
|
@@ -73,7 +66,8 @@ module Reek
|
|
73
66
|
end
|
74
67
|
|
75
68
|
def check(parser) # :nodoc:
|
76
|
-
|
69
|
+
sexp = RubyParser.new.parse(@source, @desc)
|
70
|
+
parser.process(sexp)
|
77
71
|
end
|
78
72
|
|
79
73
|
#
|
@@ -128,13 +122,6 @@ module Reek
|
|
128
122
|
ReportList.new(@sources)
|
129
123
|
end
|
130
124
|
end
|
131
|
-
|
132
|
-
#
|
133
|
-
# Represents an in-memory object that will be checked for smells.
|
134
|
-
#
|
135
|
-
class ObjectSource < Source
|
136
|
-
def check(parser) # :nodoc:
|
137
|
-
parser.check_object(@source)
|
138
|
-
end
|
139
|
-
end
|
140
125
|
end
|
126
|
+
|
127
|
+
require 'reek/object_source'
|
data/lib/reek/spec.rb
CHANGED
data/lib/reek.rb
CHANGED
data/reek.gemspec
CHANGED
@@ -2,18 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{reek}
|
5
|
-
s.version = "1.1.
|
5
|
+
s.version = "1.1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Kevin Rutherford"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-18}
|
10
10
|
s.default_executable = %q{reek}
|
11
11
|
s.description = %q{Code smell detector for Ruby}
|
12
12
|
s.email = ["kevin@rutherford-software.com"]
|
13
13
|
s.executables = ["reek"]
|
14
14
|
s.extra_rdoc_files = ["History.txt", "README.txt"]
|
15
|
-
s.files = ["History.txt", "README.txt", "Rakefile", "bin/reek", "config/defaults.reek", "lib/reek.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/exceptions.reek", "lib/reek/if_context.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/options.rb", "lib/reek/rake_task.rb", "lib/reek/report.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/smells.rb", "lib/reek/smells/uncommunicative_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/source.rb", "lib/reek/spec.rb", "lib/reek/stop_context.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/block_context_spec.rb", "spec/reek/class_context_spec.rb", "spec/reek/code_context_spec.rb", "spec/reek/code_parser_spec.rb", "spec/reek/config_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/method_context_spec.rb", "spec/reek/module_context_spec.rb", "spec/reek/name_spec.rb", "spec/reek/object_refs_spec.rb", "spec/reek/options_spec.rb", "spec/reek/report_spec.rb", "spec/reek/
|
16
|
-
s.has_rdoc = true
|
15
|
+
s.files = ["History.txt", "README.txt", "Rakefile", "bin/reek", "config/defaults.reek", "lib/reek.rb", "lib/reek/block_context.rb", "lib/reek/class_context.rb", "lib/reek/code_context.rb", "lib/reek/code_parser.rb", "lib/reek/exceptions.reek", "lib/reek/if_context.rb", "lib/reek/method_context.rb", "lib/reek/module_context.rb", "lib/reek/name.rb", "lib/reek/object_refs.rb", "lib/reek/object_source.rb", "lib/reek/options.rb", "lib/reek/rake_task.rb", "lib/reek/report.rb", "lib/reek/sexp_formatter.rb", "lib/reek/singleton_method_context.rb", "lib/reek/smell_warning.rb", "lib/reek/smells/control_couple.rb", "lib/reek/smells/duplication.rb", "lib/reek/smells/feature_envy.rb", "lib/reek/smells/large_class.rb", "lib/reek/smells/long_method.rb", "lib/reek/smells/long_parameter_list.rb", "lib/reek/smells/long_yield_list.rb", "lib/reek/smells/nested_iterators.rb", "lib/reek/smells/smell_detector.rb", "lib/reek/smells/smells.rb", "lib/reek/smells/uncommunicative_name.rb", "lib/reek/smells/utility_function.rb", "lib/reek/source.rb", "lib/reek/spec.rb", "lib/reek/stop_context.rb", "lib/reek/yield_call_context.rb", "reek.gemspec", "spec/reek/block_context_spec.rb", "spec/reek/class_context_spec.rb", "spec/reek/code_context_spec.rb", "spec/reek/code_parser_spec.rb", "spec/reek/config_spec.rb", "spec/reek/if_context_spec.rb", "spec/reek/method_context_spec.rb", "spec/reek/module_context_spec.rb", "spec/reek/name_spec.rb", "spec/reek/object_refs_spec.rb", "spec/reek/options_spec.rb", "spec/reek/report_spec.rb", "spec/reek/singleton_method_context_spec.rb", "spec/reek/smells/control_couple_spec.rb", "spec/reek/smells/duplication_spec.rb", "spec/reek/smells/feature_envy_spec.rb", "spec/reek/smells/large_class_spec.rb", "spec/reek/smells/long_method_spec.rb", "spec/reek/smells/long_parameter_list_spec.rb", "spec/reek/smells/nested_iterators_spec.rb", "spec/reek/smells/smell_spec.rb", "spec/reek/smells/uncommunicative_name_spec.rb", "spec/reek/smells/utility_function_spec.rb", "spec/slow/inline_spec.rb", "spec/slow/optparse_spec.rb", "spec/slow/redcloth_spec.rb", "spec/slow/reek_source_spec.rb", "spec/slow/samples/inline.rb", "spec/slow/samples/optparse.rb", "spec/slow/samples/redcloth.rb", "spec/slow/script_spec.rb", "spec/slow/source_list_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/reek.rake", "tasks/rspec.rake"]
|
17
16
|
s.homepage = %q{http://wiki.github.com/kevinrutherford/reek}
|
18
17
|
s.post_install_message = %q{
|
19
18
|
For more information on reek, see http://wiki.github.com/kevinrutherford/reek
|
@@ -21,7 +20,7 @@ For more information on reek, see http://wiki.github.com/kevinrutherford/reek
|
|
21
20
|
s.rdoc_options = ["--main", "README.txt"]
|
22
21
|
s.require_paths = ["lib"]
|
23
22
|
s.rubyforge_project = %q{reek}
|
24
|
-
s.rubygems_version = %q{1.3.
|
23
|
+
s.rubygems_version = %q{1.3.3}
|
25
24
|
s.summary = %q{Code smell detector for Ruby}
|
26
25
|
|
27
26
|
if s.respond_to? :specification_version then
|
@@ -29,16 +28,16 @@ For more information on reek, see http://wiki.github.com/kevinrutherford/reek
|
|
29
28
|
s.specification_version = 3
|
30
29
|
|
31
30
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
32
|
-
s.add_runtime_dependency(%q<
|
31
|
+
s.add_runtime_dependency(%q<ruby_parser>, ["~> 2.0"])
|
33
32
|
s.add_runtime_dependency(%q<ruby2ruby>, ["~> 1.2"])
|
34
33
|
s.add_runtime_dependency(%q<sexp_processor>, ["~> 3.0"])
|
35
34
|
else
|
36
|
-
s.add_dependency(%q<
|
35
|
+
s.add_dependency(%q<ruby_parser>, ["~> 2.0"])
|
37
36
|
s.add_dependency(%q<ruby2ruby>, ["~> 1.2"])
|
38
37
|
s.add_dependency(%q<sexp_processor>, ["~> 3.0"])
|
39
38
|
end
|
40
39
|
else
|
41
|
-
s.add_dependency(%q<
|
40
|
+
s.add_dependency(%q<ruby_parser>, ["~> 2.0"])
|
42
41
|
s.add_dependency(%q<ruby2ruby>, ["~> 1.2"])
|
43
42
|
s.add_dependency(%q<sexp_processor>, ["~> 3.0"])
|
44
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kevinrutherford-reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
@@ -9,18 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-18 00:00:00 -07:00
|
13
13
|
default_executable: reek
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: ruby_parser
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: "
|
23
|
+
version: "2.0"
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby2ruby
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/reek/module_context.rb
|
70
70
|
- lib/reek/name.rb
|
71
71
|
- lib/reek/object_refs.rb
|
72
|
+
- lib/reek/object_source.rb
|
72
73
|
- lib/reek/options.rb
|
73
74
|
- lib/reek/rake_task.rb
|
74
75
|
- lib/reek/report.rb
|
@@ -104,7 +105,6 @@ files:
|
|
104
105
|
- spec/reek/object_refs_spec.rb
|
105
106
|
- spec/reek/options_spec.rb
|
106
107
|
- spec/reek/report_spec.rb
|
107
|
-
- spec/reek/sexp_formatter_spec.rb
|
108
108
|
- spec/reek/singleton_method_context_spec.rb
|
109
109
|
- spec/reek/smells/control_couple_spec.rb
|
110
110
|
- spec/reek/smells/duplication_spec.rb
|
@@ -129,7 +129,7 @@ files:
|
|
129
129
|
- spec/spec_helper.rb
|
130
130
|
- tasks/reek.rake
|
131
131
|
- tasks/rspec.rake
|
132
|
-
has_rdoc:
|
132
|
+
has_rdoc: false
|
133
133
|
homepage: http://wiki.github.com/kevinrutherford/reek
|
134
134
|
post_install_message: |
|
135
135
|
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/code_parser'
|
4
|
-
require 'reek/sexp_formatter'
|
5
|
-
|
6
|
-
include Reek
|
7
|
-
|
8
|
-
def should_print(example)
|
9
|
-
it "should format #{example} correctly" do
|
10
|
-
sexp = CodeParser.parse_tree_for(example)
|
11
|
-
SexpFormatter.format(sexp).should == example
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe SexpFormatter do
|
16
|
-
should_print 'self'
|
17
|
-
should_print 'Alpha'
|
18
|
-
should_print 'Alpha::Beta'
|
19
|
-
should_print '@@fred'
|
20
|
-
should_print '`ls`'
|
21
|
-
should_print 'array[0]'
|
22
|
-
should_print 'array[0, 1, 2]'
|
23
|
-
should_print 'obj.method(arg1, arg2)'
|
24
|
-
should_print 'obj.method'
|
25
|
-
should_print '$1'
|
26
|
-
should_print 'o = q.downcase'
|
27
|
-
should_print 'true'
|
28
|
-
should_print '"-#{q}xxx#{z.size}"'
|
29
|
-
should_print '(0..5)'
|
30
|
-
should_print '(0..temp)'
|
31
|
-
should_print 'result[opt] = false'
|
32
|
-
end
|