diff --git a/.rubocop/cop/zammad/correct_migration_timestamp.rb b/.rubocop/cop/zammad/correct_migration_timestamp.rb new file mode 100644 index 000000000..9b90c60ac --- /dev/null +++ b/.rubocop/cop/zammad/correct_migration_timestamp.rb @@ -0,0 +1,35 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +module RuboCop + module Cop + module Zammad + # This cop checks if migration file name begins with a valid timestamp + # https://github.com/zammad/zammad/issues/3702 + class CorrectMigrationTimestamp < Base + MSG = 'Migration filename must begin with a valid timestamp'.freeze + + def on_new_investigation + file_path = processed_source.file_path + + return if !migration?(file_path) + return if config.file_to_exclude?(file_path) || config.allowed_camel_case_file?(file_path) + return if filename_good?(file_path) + + add_global_offense(MSG) + end + + private + + def migration?(file_path) + match_path? %r{(?