ruby_cop 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +4 -0
  3. data/README.md +44 -0
  4. data/Rakefile +3 -0
  5. data/lib/ruby_cop/gray_list.rb +26 -0
  6. data/lib/ruby_cop/node_builder.rb +521 -0
  7. data/lib/ruby_cop/policy.rb +354 -0
  8. data/lib/ruby_cop/ruby/args.rb +26 -0
  9. data/lib/ruby_cop/ruby/array.rb +13 -0
  10. data/lib/ruby_cop/ruby/assignment.rb +43 -0
  11. data/lib/ruby_cop/ruby/assoc.rb +13 -0
  12. data/lib/ruby_cop/ruby/blocks.rb +21 -0
  13. data/lib/ruby_cop/ruby/call.rb +31 -0
  14. data/lib/ruby_cop/ruby/case.rb +22 -0
  15. data/lib/ruby_cop/ruby/constants.rb +47 -0
  16. data/lib/ruby_cop/ruby/definitions.rb +25 -0
  17. data/lib/ruby_cop/ruby/for.rb +15 -0
  18. data/lib/ruby_cop/ruby/hash.rb +11 -0
  19. data/lib/ruby_cop/ruby/if.rb +31 -0
  20. data/lib/ruby_cop/ruby/list.rb +15 -0
  21. data/lib/ruby_cop/ruby/node.rb +9 -0
  22. data/lib/ruby_cop/ruby/operators.rb +52 -0
  23. data/lib/ruby_cop/ruby/params.rb +21 -0
  24. data/lib/ruby_cop/ruby/position.rb +13 -0
  25. data/lib/ruby_cop/ruby/range.rb +15 -0
  26. data/lib/ruby_cop/ruby/statements.rb +32 -0
  27. data/lib/ruby_cop/ruby/string.rb +24 -0
  28. data/lib/ruby_cop/ruby/tokens.rb +44 -0
  29. data/lib/ruby_cop/ruby/variables.rb +24 -0
  30. data/lib/ruby_cop/ruby/version.rb +3 -0
  31. data/lib/ruby_cop/ruby/while.rb +27 -0
  32. data/lib/ruby_cop/ruby.rb +23 -0
  33. data/lib/ruby_cop/version.rb +3 -0
  34. data/lib/ruby_cop.rb +10 -0
  35. data/ruby_cop.gemspec +25 -0
  36. data/spec/analyzer/node_builder_spec.rb +374 -0
  37. data/spec/analyzer/policy_spec.rb +406 -0
  38. data/spec/spec_helper.rb +13 -0
  39. data/tasks/rspec.rake +8 -0
  40. data/tasks/yard.rake +2 -0
  41. metadata +123 -0
@@ -0,0 +1,52 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Operator < Node
4
+ end
5
+
6
+ class Unary < Operator
7
+ def initialize(operator, operand)
8
+ @operator = operator
9
+ @operand = operand
10
+ end
11
+
12
+ attr_reader :operator
13
+ attr_reader :operand
14
+
15
+ # def inspect
16
+ # "#{@operator}(#{@operand.inspect})"
17
+ # end
18
+ end
19
+
20
+ class Binary < Operator
21
+ def initialize(lvalue, rvalue, operator)
22
+ @lvalue = lvalue
23
+ @rvalue = rvalue
24
+ @operator = operator
25
+ end
26
+
27
+ attr_reader :lvalue
28
+ attr_reader :rvalue
29
+ attr_reader :operator
30
+
31
+ # def inspect
32
+ # "#{@lvalue.inspect} #{@operator} #{@rvalue.inspect}"
33
+ # end
34
+ end
35
+
36
+ class IfOp < Operator
37
+ def initialize(condition, then_part, else_part)
38
+ @condition = condition
39
+ @then_part = then_part
40
+ @else_part = else_part
41
+ end
42
+
43
+ attr_reader :condition
44
+ attr_reader :then_part
45
+ attr_reader :else_part
46
+
47
+ # def inspect
48
+ # "#{@condition.inspect} ? #{@then_part.inspect} : #{@else_part.inspect}"
49
+ # end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,21 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Params < List
4
+ def initialize(params, optionals, rest, block)
5
+ super((Array(params) + Array(optionals) << rest << block).flatten.compact)
6
+ end
7
+ end
8
+
9
+ class RescueParams < List
10
+ def initialize(types, var)
11
+ if types
12
+ errors = Ruby::Array.new(types)
13
+ errors = Ruby::Assoc.new(errors, var) if var
14
+ super(errors)
15
+ else
16
+ super()
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Position
4
+ def initialize(lineno, column)
5
+ @lineno = lineno
6
+ @column = column
7
+ end
8
+
9
+ attr_reader :lineno
10
+ attr_reader :column
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Range < Node
4
+ def initialize(min, max, exclude_end)
5
+ @min = min
6
+ @max = max
7
+ @exclude_end = exclude_end
8
+ end
9
+
10
+ attr_reader :min
11
+ attr_reader :max
12
+ attr_reader :exclude_end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Statements < List
4
+ # def inspect
5
+ # @elements.collect { |e| e.inspect }.join
6
+ # end
7
+
8
+ def to_block(params)
9
+ Block.new(@elements, params)
10
+ end
11
+
12
+ def to_chained_block(blocks=nil, params=nil)
13
+ ChainedBlock.new(blocks, @elements, params)
14
+ end
15
+
16
+ def to_program(src, filename)
17
+ Program.new(src, filename, @elements)
18
+ end
19
+ end
20
+
21
+ class Program < Statements
22
+ def initialize(src, filename, statements)
23
+ @src = src
24
+ @filename = filename
25
+ super(statements)
26
+ end
27
+
28
+ attr_reader :src
29
+ attr_reader :filename
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class StringConcat < List
4
+ end
5
+
6
+ class String < List
7
+ # def inspect
8
+ # @elements.join.inspect
9
+ # end
10
+ end
11
+
12
+ class DynaSymbol < String
13
+ end
14
+
15
+ class ExecutableString < String
16
+ def to_dyna_symbol
17
+ DynaSymbol.new(@elements)
18
+ end
19
+ end
20
+
21
+ class Regexp < String
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Token < Node
4
+ def initialize(token, position)
5
+ @token = token
6
+ @position = position
7
+ end
8
+
9
+ attr_reader :token
10
+ attr_reader :position
11
+
12
+ # def inspect
13
+ # "#{@token}<t>"
14
+ # end
15
+ end
16
+
17
+ class Integer < Token
18
+ end
19
+
20
+ class Float < Token
21
+ end
22
+
23
+ class Char < Token
24
+ end
25
+
26
+ class Label < Token
27
+ end
28
+
29
+ class Symbol < Token
30
+ # def inspect
31
+ # ":#{@token.inspect}"
32
+ # end
33
+ end
34
+
35
+ class Keyword < Token
36
+ end
37
+
38
+ class Identifier < Token
39
+ def assignment(rvalue, operator)
40
+ LocalVariableAssignment.new(self, rvalue, operator)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class Variable < Identifier
4
+ end
5
+
6
+ class ClassVariable < Variable
7
+ def assignment(rvalue, operator)
8
+ ClassVariableAssignment.new(self, rvalue, operator)
9
+ end
10
+ end
11
+
12
+ class GlobalVariable < Variable
13
+ def assignment(rvalue, operator)
14
+ GlobalVariableAssignment.new(self, rvalue, operator)
15
+ end
16
+ end
17
+
18
+ class InstanceVariable < Variable
19
+ def assignment(rvalue, operator)
20
+ InstanceVariableAssignment.new(self, rvalue, operator)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module RubyCop
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ module RubyCop
2
+ module Ruby
3
+ class While < Block
4
+ def initialize(expression, statements)
5
+ @expression = expression
6
+ super(statements)
7
+ end
8
+
9
+ attr_reader :expression
10
+ end
11
+
12
+ class WhileMod < Block
13
+ def initialize(expression, statements)
14
+ @expression = expression
15
+ super(statements)
16
+ end
17
+
18
+ attr_reader :expression
19
+ end
20
+
21
+ class Until < While
22
+ end
23
+
24
+ class UntilMod < WhileMod
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'ruby_cop/ruby/node'
2
+ require 'ruby_cop/ruby/list'
3
+ require 'ruby_cop/ruby/array'
4
+ require 'ruby_cop/ruby/args'
5
+ require 'ruby_cop/ruby/assignment'
6
+ require 'ruby_cop/ruby/assoc'
7
+ require 'ruby_cop/ruby/statements'
8
+ require 'ruby_cop/ruby/blocks'
9
+ require 'ruby_cop/ruby/call'
10
+ require 'ruby_cop/ruby/case'
11
+ require 'ruby_cop/ruby/tokens'
12
+ require 'ruby_cop/ruby/constants'
13
+ require 'ruby_cop/ruby/definitions'
14
+ require 'ruby_cop/ruby/for'
15
+ require 'ruby_cop/ruby/hash'
16
+ require 'ruby_cop/ruby/if'
17
+ require 'ruby_cop/ruby/operators'
18
+ require 'ruby_cop/ruby/params'
19
+ require 'ruby_cop/ruby/position'
20
+ require 'ruby_cop/ruby/range'
21
+ require 'ruby_cop/ruby/string'
22
+ require 'ruby_cop/ruby/variables'
23
+ require 'ruby_cop/ruby/while'
@@ -0,0 +1,3 @@
1
+ module RubyCop
2
+ VERSION = '1.0.1'
3
+ end
data/lib/ruby_cop.rb ADDED
@@ -0,0 +1,10 @@
1
+ module RubyCop
2
+ # Your code goes here...
3
+ end
4
+
5
+ require 'ripper'
6
+
7
+ require 'ruby_cop/ruby'
8
+ require 'ruby_cop/node_builder'
9
+ require 'ruby_cop/gray_list'
10
+ require 'ruby_cop/policy'
data/ruby_cop.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby_cop/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby_cop"
7
+ s.version = RubyCop::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Dray Lacy", "Eric Allam"]
10
+ s.email = ["dray@envylabs.com", "eric@envylabs.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Statically analyze Ruby and neutralize nefarious code}
13
+ s.description = %q{Statically analyze Ruby and neutralize nefarious code}
14
+
15
+ s.rubyforge_project = "ruby_cop"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'geminabox'
23
+ s.add_development_dependency 'rspec', '~> 2.3.0'
24
+ s.add_development_dependency 'yard'
25
+ end