Sha256: ceb16f032aeeb12545e5139601a3bb1c73e863f186369b8b1028ec1d1895b7a5

Contents?: true

Size: 764 Bytes

Versions: 2

Compression:

Stored size: 764 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 =~ 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

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.19.0 lib/rubocop/cop/style/file_name.rb