ruby_cop 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +44 -0
- data/Rakefile +3 -0
- data/lib/ruby_cop/gray_list.rb +26 -0
- data/lib/ruby_cop/node_builder.rb +521 -0
- data/lib/ruby_cop/policy.rb +354 -0
- data/lib/ruby_cop/ruby/args.rb +26 -0
- data/lib/ruby_cop/ruby/array.rb +13 -0
- data/lib/ruby_cop/ruby/assignment.rb +43 -0
- data/lib/ruby_cop/ruby/assoc.rb +13 -0
- data/lib/ruby_cop/ruby/blocks.rb +21 -0
- data/lib/ruby_cop/ruby/call.rb +31 -0
- data/lib/ruby_cop/ruby/case.rb +22 -0
- data/lib/ruby_cop/ruby/constants.rb +47 -0
- data/lib/ruby_cop/ruby/definitions.rb +25 -0
- data/lib/ruby_cop/ruby/for.rb +15 -0
- data/lib/ruby_cop/ruby/hash.rb +11 -0
- data/lib/ruby_cop/ruby/if.rb +31 -0
- data/lib/ruby_cop/ruby/list.rb +15 -0
- data/lib/ruby_cop/ruby/node.rb +9 -0
- data/lib/ruby_cop/ruby/operators.rb +52 -0
- data/lib/ruby_cop/ruby/params.rb +21 -0
- data/lib/ruby_cop/ruby/position.rb +13 -0
- data/lib/ruby_cop/ruby/range.rb +15 -0
- data/lib/ruby_cop/ruby/statements.rb +32 -0
- data/lib/ruby_cop/ruby/string.rb +24 -0
- data/lib/ruby_cop/ruby/tokens.rb +44 -0
- data/lib/ruby_cop/ruby/variables.rb +24 -0
- data/lib/ruby_cop/ruby/version.rb +3 -0
- data/lib/ruby_cop/ruby/while.rb +27 -0
- data/lib/ruby_cop/ruby.rb +23 -0
- data/lib/ruby_cop/version.rb +3 -0
- data/lib/ruby_cop.rb +10 -0
- data/ruby_cop.gemspec +25 -0
- data/spec/analyzer/node_builder_spec.rb +374 -0
- data/spec/analyzer/policy_spec.rb +406 -0
- data/spec/spec_helper.rb +13 -0
- data/tasks/rspec.rake +8 -0
- data/tasks/yard.rake +2 -0
- 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,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,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'
|
data/lib/ruby_cop.rb
ADDED
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
|