Class: RailsBestPractices::Lexicals::LongLineCheck
- Inherits:
-
Core::Check
- Object
- CodeAnalyzer::Checker
- Core::Check
- RailsBestPractices::Lexicals::LongLineCheck
- Defined in:
- lib/rails_best_practices/lexicals/long_line_check.rb
Overview
Keep lines fewer than 80 characters.
Constant Summary
Constants inherited from Core::Check
Core::Check::ALL_FILES, Core::Check::CAPFILE, Core::Check::CONFIG_FILES, Core::Check::CONTROLLER_FILES, Core::Check::DEPLOY_FILES, Core::Check::GEMFILE_LOCK, Core::Check::HELPER_FILES, Core::Check::INITIALIZER_FILES, Core::Check::MAILER_FILES, Core::Check::MIGRATION_FILES, Core::Check::MODEL_FILES, Core::Check::PARTIAL_VIEW_FILES, Core::Check::ROUTE_FILES, Core::Check::SCHEMA_FILE, Core::Check::SKIP_FILES, Core::Check::VIEW_FILES
Instance Method Summary collapse
-
#check(filename, content) ⇒ Object
check if a line is over 80 characters.
-
#initialize(options = {}) ⇒ LongLineCheck
constructor
A new instance of LongLineCheck.
Methods inherited from Core::Check
#add_error, debug, debug?, #errors, #is_ignored?, #is_interesting_file?, #method_missing, #parse_file?, #regex_ignored_files, #url, url
Constructor Details
#initialize(options = {}) ⇒ LongLineCheck
Returns a new instance of LongLineCheck.
9 10 11 12 |
# File 'lib/rails_best_practices/lexicals/long_line_check.rb', line 9 def initialize( = {}) super() @max_line_length = ['max_line_length'] || 80 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsBestPractices::Core::Check
Instance Method Details
#check(filename, content) ⇒ Object
check if a line is over 80 characters
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rails_best_practices/lexicals/long_line_check.rb', line 18 def check(filename, content) # Only check ruby files if /\.rb$/ =~ filename line_no = 0 content.each_line do |line| line_no += 1 actual_line_length = line.sub(/\s+$/, '').length next unless actual_line_length > @max_line_length add_error( "line is longer than #{@max_line_length} characters (#{actual_line_length} characters)", filename, line_no ) end end end |