Class: RubyLint::Analysis::Pedantics

Inherits:
Base show all
Defined in:
lib/ruby-lint/analysis/pedantics.rb

Overview

This class adds (pedantic) warnings for various features that aren’t really that useful or needed. This serves mostly as a simple example on how to write an analysis class.

Currently warnings are added for the following:

  • BEGIN/END blocks
  • Statements that use then or do when it’s not needed

For example:

BEGIN { puts 'foo' }

This would result in the warning “BEGIN/END is useless” being added.

Constant Summary

Constants inherited from Base

Base::SCOPES

Instance Attribute Summary

Attributes inherited from Base

#config, #report, #vm

Attributes inherited from Iterator

#arity_cache, #arity_cache Hash containing the amount of arguments for

Instance Method Summary collapse

Methods inherited from Base

#add_message, #after_initialize, analyze?, #current_scope, #error, #info, #previous_scope, register, #set_current_scope, #set_previous_scope, #warning

Methods included from MethodEvaluation

#unpack_block

Methods inherited from Iterator

#execute_callback, #initialize, #iterate, #skip_child_nodes!

Constructor Details

This class inherits a constructor from RubyLint::Iterator

Instance Method Details

#check_begin_token(node) ⇒ Object (private)

Checks if a node’s begin token matches “then” or “do” and if so adds a warning for it.

Parameters:



44
45
46
47
48
# File 'lib/ruby-lint/analysis/pedantics.rb', line 44

def check_begin_token(node)
  if node.location.begin.is?('then') or node.location.begin.is?('do')
    info('the use of then/do is not needed here', node)
  end
end