diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-20 18:09:31 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-20 18:09:31 +0000 |
commit | ae4ef81757bdd2c984777d8f0b2c275bbcb4b17d (patch) | |
tree | 1ac23c80190bafb47a1f5a6f1aae9da91d35d9dc /rubocop | |
parent | 194b499aa8e26df26ff70a1e1ce0396587bd5243 (diff) | |
download | gitlab-ce-ae4ef81757bdd2c984777d8f0b2c275bbcb4b17d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/filename_length.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/rubocop/cop/filename_length.rb b/rubocop/cop/filename_length.rb new file mode 100644 index 00000000000..815db7de3f5 --- /dev/null +++ b/rubocop/cop/filename_length.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + class FilenameLength < Cop + 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 investigate(processed_source) + file_path = processed_source.file_path + return if config.file_to_exclude?(file_path) + + if file_path.bytesize > FILEPATH_MAX_BYTES + add_offense(nil, location: source_range(processed_source.buffer, 1, 0, 1), message: MSG_FILEPATH_LEN) + elsif File.basename(file_path).bytesize > FILENAME_MAX_BYTES + add_offense(nil, location: source_range(processed_source.buffer, 1, 0, 1), message: MSG_FILENAME_LEN) + end + end + end + end +end |