ruby-lint 0.0.1a → 0.0.1a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.yardopts +1 -1
  2. data/MANIFEST +65 -62
  3. data/README.md +114 -13
  4. data/bin/ruby-lint +6 -0
  5. data/lib/ruby-lint.rb +36 -0
  6. data/lib/{rlint → ruby-lint}/analyze/coding_style.rb +32 -32
  7. data/lib/{rlint → ruby-lint}/analyze/definitions.rb +13 -13
  8. data/lib/{rlint → ruby-lint}/analyze/method_validation.rb +5 -5
  9. data/lib/{rlint → ruby-lint}/analyze/shadowing_variables.rb +5 -5
  10. data/lib/{rlint → ruby-lint}/analyze/undefined_variables.rb +7 -7
  11. data/lib/{rlint → ruby-lint}/analyze/unused_variables.rb +6 -6
  12. data/lib/{rlint → ruby-lint}/callback.rb +11 -11
  13. data/lib/{rlint → ruby-lint}/cli.rb +17 -17
  14. data/lib/{rlint → ruby-lint}/constant_importer.rb +18 -8
  15. data/lib/{rlint → ruby-lint}/definition.rb +10 -10
  16. data/lib/{rlint → ruby-lint}/formatter/text.rb +6 -6
  17. data/lib/{rlint → ruby-lint}/helper/definition_resolver.rb +11 -11
  18. data/lib/{rlint → ruby-lint}/helper/scoping.rb +14 -14
  19. data/lib/{rlint → ruby-lint}/iterator.rb +22 -22
  20. data/lib/{rlint → ruby-lint}/options.rb +9 -9
  21. data/lib/{rlint → ruby-lint}/parser.rb +111 -111
  22. data/lib/{rlint → ruby-lint}/parser_error.rb +3 -3
  23. data/lib/{rlint → ruby-lint}/report.rb +8 -8
  24. data/lib/{rlint → ruby-lint}/token/assignment_token.rb +4 -4
  25. data/lib/{rlint → ruby-lint}/token/begin_rescue_token.rb +7 -7
  26. data/lib/{rlint → ruby-lint}/token/block_token.rb +12 -3
  27. data/lib/{rlint → ruby-lint}/token/case_token.rb +5 -5
  28. data/lib/{rlint → ruby-lint}/token/class_token.rb +3 -3
  29. data/lib/{rlint → ruby-lint}/token/method_definition_token.rb +8 -8
  30. data/lib/{rlint → ruby-lint}/token/method_token.rb +9 -7
  31. data/lib/{rlint → ruby-lint}/token/parameters_token.rb +6 -6
  32. data/lib/{rlint → ruby-lint}/token/regexp_token.rb +2 -2
  33. data/lib/{rlint → ruby-lint}/token/statement_token.rb +6 -6
  34. data/lib/{rlint → ruby-lint}/token/token.rb +8 -6
  35. data/lib/{rlint → ruby-lint}/token/variable_token.rb +3 -3
  36. data/lib/ruby-lint/version.rb +3 -0
  37. data/ruby-lint.gemspec +5 -5
  38. data/spec/benchmarks/memory.rb +7 -7
  39. data/spec/benchmarks/parse_parser.rb +5 -5
  40. data/spec/fixtures/stdlib/un.rb +348 -0
  41. data/spec/helper.rb +3 -1
  42. data/spec/{rlint → ruby-lint}/analyze/coding_style.rb +30 -30
  43. data/spec/ruby-lint/analyze/complex/un.rb +29 -0
  44. data/spec/{rlint → ruby-lint}/analyze/definitions/classes.rb +25 -25
  45. data/spec/{rlint → ruby-lint}/analyze/definitions/methods.rb +22 -22
  46. data/spec/{rlint → ruby-lint}/analyze/definitions/modules.rb +42 -42
  47. data/spec/{rlint → ruby-lint}/analyze/definitions/variables.rb +27 -27
  48. data/spec/{rlint → ruby-lint}/analyze/method_validation.rb +31 -31
  49. data/spec/{rlint → ruby-lint}/analyze/shadowing_variables.rb +6 -6
  50. data/spec/{rlint → ruby-lint}/analyze/undefined_variables.rb +37 -37
  51. data/spec/{rlint → ruby-lint}/analyze/unused_variables.rb +21 -21
  52. data/spec/{rlint → ruby-lint}/callback.rb +7 -7
  53. data/spec/{rlint → ruby-lint}/constant_importer.rb +6 -6
  54. data/spec/{rlint → ruby-lint}/definition.rb +25 -25
  55. data/spec/{rlint → ruby-lint}/formatter/text.rb +4 -4
  56. data/spec/{rlint → ruby-lint}/iterator.rb +38 -38
  57. data/spec/{rlint → ruby-lint}/parser/arrays.rb +28 -28
  58. data/spec/{rlint → ruby-lint}/parser/classes.rb +23 -23
  59. data/spec/{rlint → ruby-lint}/parser/errors.rb +4 -4
  60. data/spec/{rlint → ruby-lint}/parser/hashes.rb +24 -24
  61. data/spec/{rlint → ruby-lint}/parser/methods.rb +50 -50
  62. data/spec/{rlint → ruby-lint}/parser/modules.rb +8 -8
  63. data/spec/{rlint → ruby-lint}/parser/objects.rb +8 -8
  64. data/spec/{rlint → ruby-lint}/parser/operators.rb +14 -14
  65. data/spec/{rlint → ruby-lint}/parser/procs.rb +26 -26
  66. data/spec/{rlint → ruby-lint}/parser/ranges.rb +9 -9
  67. data/spec/{rlint → ruby-lint}/parser/regexp.rb +5 -5
  68. data/spec/{rlint → ruby-lint}/parser/scalars.rb +17 -17
  69. data/spec/{rlint → ruby-lint}/parser/statements.rb +94 -94
  70. data/spec/{rlint → ruby-lint}/parser/variables.rb +37 -37
  71. data/spec/{rlint → ruby-lint}/report.rb +4 -4
  72. data/task/manifest.rake +8 -0
  73. data/task/test.rake +1 -1
  74. metadata +69 -66
  75. data/bin/rlint +0 -6
  76. data/lib/rlint.rb +0 -36
  77. data/lib/rlint/version.rb +0 -3
@@ -1,15 +1,15 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Analyze
3
3
  ##
4
- # {Rlint::Analyze::Definitions} is a callback class that is used for
4
+ # {RubyLint::Analyze::Definitions} is a callback class that is used for
5
5
  # building a list of all the definitions (variables, methods, etc) of a
6
6
  # block of Ruby code.
7
7
  #
8
- # The resulting instance of {Rlint::Definition} is stored in the `@storage`
8
+ # The resulting instance of {RubyLint::Definition} is stored in the `@storage`
9
9
  # instance variable under the key `:scope`. This makes it possible for
10
10
  # other callback classes to access this data easily.
11
11
  #
12
- class Definitions < Rlint::Callback
12
+ class Definitions < RubyLint::Callback
13
13
  include Helper::Scoping
14
14
 
15
15
  ##
@@ -47,7 +47,7 @@ module Rlint
47
47
  ##
48
48
  # Called when a value is assigned to a variable.
49
49
  #
50
- # @param [Rlint::Token::AssignmentToken] token
50
+ # @param [RubyLint::Token::AssignmentToken] token
51
51
  #
52
52
  def on_assignment(token)
53
53
  if token.type == :global_variable
@@ -89,7 +89,7 @@ module Rlint
89
89
  ##
90
90
  # Called when a new method is defined.
91
91
  #
92
- # @param [Rlint::Token::MethodDefinitionToken] token
92
+ # @param [RubyLint::Token::MethodDefinitionToken] token
93
93
  #
94
94
  def on_method_definition(token)
95
95
  type = :instance_method
@@ -123,7 +123,7 @@ module Rlint
123
123
  ##
124
124
  # Called after a method definition has been processed.
125
125
  #
126
- # @see Rlint::Analyze::Definitions#on_method_definition
126
+ # @see RubyLint::Analyze::Definitions#on_method_definition
127
127
  #
128
128
  def after_method_definition(token)
129
129
  # TODO: exporting these variables should only be done if the method is
@@ -140,7 +140,7 @@ module Rlint
140
140
  ##
141
141
  # Called when a class definition is found.
142
142
  #
143
- # @param [Rlint::Token::ClassToken] token
143
+ # @param [RubyLint::Token::ClassToken] token
144
144
  #
145
145
  def on_class(token)
146
146
  name = token.name.join('::')
@@ -167,7 +167,7 @@ module Rlint
167
167
  ##
168
168
  # Called after a class definition was found and processed.
169
169
  #
170
- # @see Rlint::Analyze::Definitions#on_class
170
+ # @see RubyLint::Analyze::Definitions#on_class
171
171
  #
172
172
  def after_class(token)
173
173
  @scopes.pop
@@ -177,7 +177,7 @@ module Rlint
177
177
  ##
178
178
  # Called when a module is defined.
179
179
  #
180
- # @param [Rlint::Token::Token] token
180
+ # @param [RubyLint::Token::Token] token
181
181
  #
182
182
  def on_module(token)
183
183
  name = token.name.join('::')
@@ -203,7 +203,7 @@ module Rlint
203
203
  ##
204
204
  # Called after a module definition has been processed.
205
205
  #
206
- # @see Rlint::Analyze::Definitions#on_module
206
+ # @see RubyLint::Analyze::Definitions#on_module
207
207
  #
208
208
  def after_module(token)
209
209
  @scopes.pop
@@ -214,7 +214,7 @@ module Rlint
214
214
  # Called when a method call is found. This callback is used to extend
215
215
  # classes using modules.
216
216
  #
217
- # @param [Rlint::Token::MethodToken] token
217
+ # @param [RubyLint::Token::MethodToken] token
218
218
  #
219
219
  def on_method(token)
220
220
  if INCLUDE_SYMBOLS.key?(token.name)
@@ -241,4 +241,4 @@ module Rlint
241
241
  end
242
242
  end # Definitions
243
243
  end # Analyze
244
- end # Rlint
244
+ end # RubyLint
@@ -1,11 +1,11 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Analyze
3
3
  ##
4
- # {Rlint::Analyze::MethodValidation} is used to validate method calls.
4
+ # {RubyLint::Analyze::MethodValidation} is used to validate method calls.
5
5
  # Errors are added for calling undefined methods, calling methods with
6
6
  # invalid parameters and so on.
7
7
  #
8
- class MethodValidation < Rlint::Callback
8
+ class MethodValidation < RubyLint::Callback
9
9
  include Helper::DefinitionResolver
10
10
 
11
11
  ##
@@ -37,7 +37,7 @@ module Rlint
37
37
  ##
38
38
  # Called when a method call is found.
39
39
  #
40
- # @param [Rlint::Token::MethodToken] token
40
+ # @param [RubyLint::Token::MethodToken] token
41
41
  #
42
42
  def on_method(token)
43
43
  # Method called on a receiver (e.g. `String.new`).
@@ -101,4 +101,4 @@ module Rlint
101
101
  end
102
102
  end # MethodValidation
103
103
  end # Analyze
104
- end # Rlint
104
+ end # RubyLint
@@ -1,10 +1,10 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Analyze
3
3
  ##
4
- # {Rlint::Analyze::ShadowingVariables} is used to add warnings when block
4
+ # {RubyLint::Analyze::ShadowingVariables} is used to add warnings when block
5
5
  # parameters shadow outer local variables.
6
6
  #
7
- class ShadowingVariables < Rlint::Callback
7
+ class ShadowingVariables < RubyLint::Callback
8
8
  include Helper::DefinitionResolver
9
9
 
10
10
  ##
@@ -19,7 +19,7 @@ module Rlint
19
19
  # parameters of the block shadow existing local variables defined in the
20
20
  # outer scope.
21
21
  #
22
- # @param [Rlint::Token::BlockToken] token The token of the block.
22
+ # @param [RubyLint::Token::BlockToken] token The token of the block.
23
23
  #
24
24
  def on_block(token)
25
25
  token.parameters.each do |param|
@@ -34,4 +34,4 @@ module Rlint
34
34
  end
35
35
  end # ShadowingVariables
36
36
  end # Analyze
37
- end # Rlint
37
+ end # RubyLint
@@ -1,10 +1,10 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Analyze
3
3
  ##
4
- # {Rlint::Analyze::UndefinedVariables} is used to add errors for the use of
4
+ # {RubyLint::Analyze::UndefinedVariables} is used to add errors for the use of
5
5
  # undefined variables.
6
6
  #
7
- class UndefinedVariables < Rlint::Callback
7
+ class UndefinedVariables < RubyLint::Callback
8
8
  include Helper::DefinitionResolver
9
9
 
10
10
  ##
@@ -37,7 +37,7 @@ module Rlint
37
37
  # Called when a variable assignment is found. Used to validate constant
38
38
  # paths before assigning data to them.
39
39
  #
40
- # @param [Rlint::Token::AssignmentToken] token
40
+ # @param [RubyLint::Token::AssignmentToken] token
41
41
  #
42
42
  def on_assignment(token)
43
43
  on_constant_path(token) if token.name.is_a?(Array)
@@ -46,7 +46,7 @@ module Rlint
46
46
  ##
47
47
  # Called when a constant path is found.
48
48
  #
49
- # @param [Rlint::Token::VariableToken] token
49
+ # @param [RubyLint::Token::VariableToken] token
50
50
  #
51
51
  def on_constant_path(token)
52
52
  current = scope
@@ -73,7 +73,7 @@ module Rlint
73
73
  ##
74
74
  # Called when a method call is found.
75
75
  #
76
- # @param [Rlint::Token::MethodToken] token
76
+ # @param [RubyLint::Token::MethodToken] token
77
77
  #
78
78
  def on_method(token)
79
79
  kernel_method = false
@@ -96,4 +96,4 @@ module Rlint
96
96
  end
97
97
  end # UndefinedVariables
98
98
  end # Analyze
99
- end # Rlint
99
+ end # RubyLint
@@ -1,10 +1,10 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Analyze
3
3
  ##
4
- # {Rlint::Analyze::UnusedVariables} is used to check for unused local,
4
+ # {RubyLint::Analyze::UnusedVariables} is used to check for unused local,
5
5
  # instance, class and global variables.
6
6
  #
7
- class UnusedVariables < Rlint::Callback
7
+ class UnusedVariables < RubyLint::Callback
8
8
  include Helper::DefinitionResolver
9
9
 
10
10
  ##
@@ -45,7 +45,7 @@ module Rlint
45
45
  end
46
46
 
47
47
  ##
48
- # @see Rlint::Callback#initialize
48
+ # @see RubyLint::Callback#initialize
49
49
  #
50
50
  def initialize(*args)
51
51
  super
@@ -81,7 +81,7 @@ module Rlint
81
81
  ##
82
82
  # Called when a variable is assigned.
83
83
  #
84
- # @param [Rlint::Token::AssignmentToken] token
84
+ # @param [RubyLint::Token::AssignmentToken] token
85
85
  #
86
86
  def on_assignment(token)
87
87
  unused_variables[token.name] = token
@@ -100,4 +100,4 @@ module Rlint
100
100
  end
101
101
  end # UnusedVariables
102
102
  end # Analyze
103
- end # Rlint
103
+ end # RubyLint
@@ -1,30 +1,30 @@
1
- module Rlint
1
+ module RubyLint
2
2
  ##
3
- # {Rlint::Callback} is a class that can be used (but you're not required to)
3
+ # {RubyLint::Callback} is a class that can be used (but you're not required to)
4
4
  # to remove some common boilerplate code from custom callback classes.
5
5
  #
6
6
  # Using this class can be done by simply extending it:
7
7
  #
8
- # class MyCallback < Rlint::Callback
8
+ # class MyCallback < RubyLint::Callback
9
9
  #
10
10
  # end
11
11
  #
12
12
  # Once extended the following helper methods are provided:
13
13
  #
14
- # * {Rlint::Callback#error}
15
- # * {Rlint::Callback#warning}
16
- # * {Rlint::Callback#info}
14
+ # * {RubyLint::Callback#error}
15
+ # * {RubyLint::Callback#warning}
16
+ # * {RubyLint::Callback#info}
17
17
  #
18
18
  # These 3 methods can be used to add data to a report. If no report is set
19
19
  # the methods will not execute any code. This means your own code does not
20
- # have to check for a valid instance of {Rlint::Report} in the `@report`
20
+ # have to check for a valid instance of {RubyLint::Report} in the `@report`
21
21
  # instance variable every time you want to add data to it.
22
22
  #
23
23
  class Callback
24
24
  ##
25
25
  # Creates a new instance of the class and stores the report.
26
26
  #
27
- # @param [Rlint::Report|NilClass] report The report instance to use.
27
+ # @param [RubyLint::Report|NilClass] report The report instance to use.
28
28
  # @param [Hash] options A hash containing custom options to set for the
29
29
  # callback.
30
30
  #
@@ -49,7 +49,7 @@ module Rlint
49
49
  ##
50
50
  # Adds a warning message to the report.
51
51
  #
52
- # @see Rlint::Callback#error
52
+ # @see RubyLint::Callback#error
53
53
  #
54
54
  def warning(message, line, column)
55
55
  @report.add(:warning, message, line, column) if @report
@@ -58,10 +58,10 @@ module Rlint
58
58
  ##
59
59
  # Adds a regular informational message to the report.
60
60
  #
61
- # @see Rlint::Callback#error
61
+ # @see RubyLint::Callback#error
62
62
  #
63
63
  def info(message, line, column)
64
64
  @report.add(:info, message, line, column) if @report
65
65
  end
66
66
  end # Callback
67
- end # Rlint
67
+ end # RubyLint
@@ -1,26 +1,26 @@
1
1
  require 'optparse'
2
2
 
3
- module Rlint
3
+ module RubyLint
4
4
  ##
5
- # {Rlint::CLI} is the commandline interface to Rlint.
5
+ # {RubyLint::CLI} is the commandline interface to RubyLint.
6
6
  #
7
7
  class CLI
8
8
  ##
9
9
  # Creates a new instance of the class and configures OptionParser.
10
10
  #
11
11
  def initialize
12
- @formatters = constant_short_names(Rlint::Formatter)
13
- @analyzers = constant_short_names(Rlint::Analyze)
12
+ @formatters = constant_short_names(RubyLint::Formatter)
13
+ @analyzers = constant_short_names(RubyLint::Analyze)
14
14
 
15
15
  @option_parser = OptionParser.new do |opts|
16
16
  opts.banner = 'A static code analysis tool and linter for Ruby'
17
- opts.program_name = 'rlint'
18
- opts.version = Rlint::VERSION
17
+ opts.program_name = 'ruby-lint'
18
+ opts.version = RubyLint::VERSION
19
19
  opts.summary_indent = ' '
20
20
 
21
21
  opts.separator ''
22
22
  opts.separator 'Usage:'
23
- opts.separator ' $ rlint [FILES] [OPTIONS]'
23
+ opts.separator ' $ ruby-ling [FILES] [OPTIONS]'
24
24
 
25
25
  opts.separator ''
26
26
  opts.separator 'Analyzers:'
@@ -44,7 +44,7 @@ module Rlint
44
44
  String
45
45
  ) do |formatter|
46
46
  if @formatters.key?(formatter)
47
- Rlint.options.formatter = @formatters[formatter]
47
+ RubyLint.options.formatter = @formatters[formatter]
48
48
  end
49
49
  end
50
50
 
@@ -54,7 +54,7 @@ module Rlint
54
54
  'The reporting levels to enable',
55
55
  Array
56
56
  ) do |levels|
57
- Rlint.options.levels = levels.map { |level| level.to_sym }
57
+ RubyLint.options.levels = levels.map { |level| level.to_sym }
58
58
  end
59
59
 
60
60
  opts.on(
@@ -73,7 +73,7 @@ module Rlint
73
73
  end
74
74
  end
75
75
 
76
- Rlint.options.analyzers = analyzers
76
+ RubyLint.options.analyzers = analyzers
77
77
  end
78
78
 
79
79
  opts.on('-h', '--help', 'Shows this help message') do
@@ -88,7 +88,7 @@ module Rlint
88
88
  end
89
89
 
90
90
  ##
91
- # Runs Rlint.
91
+ # Runs RubyLint.
92
92
  #
93
93
  # @param [Array] argv Array of commandline parameters.
94
94
  #
@@ -102,11 +102,11 @@ module Rlint
102
102
 
103
103
  code = File.read(file, File.size(file))
104
104
  tokens = Parser.new(code, file).parse
105
- report = Report.new(file, Rlint.options.levels)
105
+ report = Report.new(file, RubyLint.options.levels)
106
106
  iterator = Iterator.new(report)
107
- formatter = Rlint.options.formatter.new
107
+ formatter = RubyLint.options.formatter.new
108
108
 
109
- Rlint.options.analyzers.each { |const| iterator.bind(const) }
109
+ RubyLint.options.analyzers.each { |const| iterator.bind(const) }
110
110
 
111
111
  iterator.run(tokens)
112
112
 
@@ -117,10 +117,10 @@ module Rlint
117
117
  end
118
118
 
119
119
  ##
120
- # Shows the current version of Rlint.
120
+ # Shows the current version of RubyLint.
121
121
  #
122
122
  def version
123
- puts "Rlint version #{Rlint::VERSION} running on #{RUBY_DESCRIPTION}"
123
+ puts "RubyLint version #{RubyLint::VERSION} running on #{RUBY_DESCRIPTION}"
124
124
  exit
125
125
  end
126
126
 
@@ -164,4 +164,4 @@ module Rlint
164
164
  return list.join("\n")
165
165
  end
166
166
  end # CLI
167
- end # Rlint
167
+ end # RubyLint
@@ -1,7 +1,7 @@
1
- module Rlint
1
+ module RubyLint
2
2
  ##
3
- # {Rlint::ConstantImporter} is a module that can be used to create a list of
4
- # method definitions (using {Rlint::Token::MethodDefinitionToken} for a
3
+ # {RubyLint::ConstantImporter} is a module that can be used to create a list of
4
+ # method definitions (using {RubyLint::Token::MethodDefinitionToken} for a
5
5
  # supplied list of constant names.
6
6
  #
7
7
  module ConstantImporter
@@ -28,7 +28,7 @@ module Rlint
28
28
  ##
29
29
  # Hash containing the parameter types as returned by `Method#parameters`
30
30
  # and the attributes they should be stored in in an instance of
31
- # {Rlint::Token::ParametersToken}.
31
+ # {RubyLint::Token::ParametersToken}.
32
32
  #
33
33
  # @return [Hash]
34
34
  #
@@ -41,7 +41,7 @@ module Rlint
41
41
 
42
42
  ##
43
43
  # Imports the methods of a given list of constant names and returns a Hash
44
- # containing instances of {Rlint::Definition} for each imported constant.
44
+ # containing instances of {RubyLint::Definition} for each imported constant.
45
45
  #
46
46
  # @param [Array] constants An array of constant to import.
47
47
  # @param [Mixed] source_constant The source constant to use for the
@@ -58,8 +58,18 @@ module Rlint
58
58
 
59
59
  next unless const
60
60
 
61
- name = name.to_s
62
- scope = Definition.new(nil, :lazy => true, :constant => const)
61
+ name = name.to_s
62
+ const_token = Token::VariableToken.new(
63
+ :type => :constant,
64
+ :name => name
65
+ )
66
+
67
+ scope = Definition.new(
68
+ nil,
69
+ :lazy => true,
70
+ :constant => const,
71
+ :token => const_token
72
+ )
63
73
 
64
74
  METHOD_KEYS.each do |source, target|
65
75
  next unless const.respond_to?(source)
@@ -99,4 +109,4 @@ module Rlint
99
109
  return imported
100
110
  end
101
111
  end # ConstantImporter
102
- end # Rlint
112
+ end # RubyLint