Welcome to mirror list, hosted at ThFree Co, Russian Federation.

filename_length.rb « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 948f69cc88cbc1148e7b073c083c6de8075f59cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module RuboCop
  module Cop
    class FilenameLength < RuboCop::Cop::Base
      include RangeHelp

      FILEPATH_MAX_BYTES = 256
      FILENAME_MAX_BYTES = 100
      MSG_FILEPATH_LEN = "This file path is too long. It should be #{FILEPATH_MAX_BYTES} or less"
      MSG_FILENAME_LEN = "This file name is too long. It should be #{FILENAME_MAX_BYTES} or less"

      def on_new_investigation
        file_path = processed_source.file_path
        return if config.file_to_exclude?(file_path)

        if file_path.bytesize > FILEPATH_MAX_BYTES
          add_offense(source_range(processed_source.buffer, 1, 0), message: MSG_FILEPATH_LEN)
        elsif File.basename(file_path).bytesize > FILENAME_MAX_BYTES
          add_offense(source_range(processed_source.buffer, 1, 0), message: MSG_FILENAME_LEN)
        end
      end
    end
  end
end