debian-mirror-gitlab/rubocop/cop/filename_length.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
869 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module RuboCop
module Cop
2022-10-11 01:57:18 +05:30
class FilenameLength < RuboCop::Cop::Base
2020-04-22 19:07:51 +05:30
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"
2022-10-11 01:57:18 +05:30
def on_new_investigation
2020-04-22 19:07:51 +05:30
file_path = processed_source.file_path
return if config.file_to_exclude?(file_path)
if file_path.bytesize > FILEPATH_MAX_BYTES
2022-10-11 01:57:18 +05:30
add_offense(source_range(processed_source.buffer, 1, 0), message: MSG_FILEPATH_LEN)
2020-04-22 19:07:51 +05:30
elsif File.basename(file_path).bytesize > FILENAME_MAX_BYTES
2022-10-11 01:57:18 +05:30
add_offense(source_range(processed_source.buffer, 1, 0), message: MSG_FILENAME_LEN)
2020-04-22 19:07:51 +05:30
end
end
end
end
end