Sha256: 047b73a8f71d692b47725bf78a364b25bf7536935517217d9bf195dd664aae96

Contents?: true

Size: 804 Bytes

Versions: 3

Compression:

Stored size: 804 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop makes sure that Ruby source files have snake_case names.
      class FileName < Cop
        MSG = 'Use snake_case for source file names.'

        SNAKE_CASE = /^[\da-z_]+$/

        def investigate(processed_source)
          file_path = processed_source.buffer.name

          return if config.file_to_include?(file_path)

          basename = File.basename(file_path).sub(/\.[^\.]+$/, '')

          unless basename.split('.').all? { |fragment| fragment =~ SNAKE_CASE }
            add_offense(nil,
                        source_range(processed_source.buffer,
                                     processed_source[0..0],
                                     0, 1))
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.21.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.20.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.20.0 lib/rubocop/cop/style/file_name.rb