Sha256: 1c5e9aa5199b344e36bee3fdca23afe34843aff9f367ba437153418a72af8521

Contents?: true

Size: 788 Bytes

Versions: 23

Compression:

Stored size: 788 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(/\.[^\.]+$/, '')
          return if snake_case?(basename)

          range = source_range(processed_source.buffer, 1, 0)
          add_offense(nil, range)
        end

        private

        def snake_case?(basename)
          basename.split('.').all? { |fragment| fragment =~ SNAKE_CASE }
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/file_name.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/file_name.rb
rubocop-0.35.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.35.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.34.2 lib/rubocop/cop/style/file_name.rb
rubocop-0.34.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.34.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.33.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.32.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.32.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.31.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.30.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.30.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.29.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.29.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.28.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.27.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.27.0 lib/rubocop/cop/style/file_name.rb
rubocop-0.26.1 lib/rubocop/cop/style/file_name.rb
rubocop-0.26.0 lib/rubocop/cop/style/file_name.rb