Просмотр исходного кода

Maintenance: Update copyright information and add a new rubocop cop to watch over it.

Martin Gruner 3 лет назад
Родитель
Сommit
5df98684da

+ 75 - 0
.rubocop/cop/zammad/update_copyright.rb

@@ -0,0 +1,75 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
+module RuboCop
+  module Cop
+    module Zammad
+      # This cop updates the copyright information or inserts it if needed.
+      class UpdateCopyright < Base
+        include RangeHelp
+        extend AutoCorrector
+
+        MSG = 'Copyright update required (use auto-correct to rectify this).'.freeze
+        COPYRIGHT = "# Copyright (C) 2012-#{Date.today.year} Zammad Foundation, http://zammad-foundation.org/".freeze # rubocop:disable Rails/Date
+
+        def on_new_investigation
+          if processed_source.raw_source.include? '# Copyright (C) 2012-'
+            update_copyright
+          else
+            insert_copyright
+          end
+        end
+
+        def insert_copyright
+          if processed_source.raw_source.start_with? '#!'
+            # Keep shebang line, obviously.
+            comment = processed_source.comments.first
+            add_offense(comment) do |corrector|
+              corrector.insert_after(
+                comment,
+                "\n#{COPYRIGHT}\n"
+              )
+            end
+          else
+            # Insert at the top if there is no shebang.
+            file_start = range_between(0, 0)
+            add_offense(file_start) do |corrector|
+              corrector.insert_before(file_start, "#{COPYRIGHT}\n\n")
+            end
+          end
+        end
+
+        def update_copyright
+          processed_source.comments.each do |comment|
+            break if correct_copyright?(comment)
+            next if !comment.text.include?('# Copyright (C) 2012-') # rubocop:disable Rails/NegateInclude
+
+            add_offense(comment) do |corrector|
+              corrector.replace(
+                comment,
+                replace_with(comment)
+              )
+            end
+
+            break
+          end
+        end
+
+        def correct_copyright?(comment)
+          return false if !comment.text.eql? COPYRIGHT
+
+          newline_after_copyright?(comment)
+        end
+
+        def newline_after_copyright?(comment)
+          processed_source[comment.location.last_line].blank?
+        end
+
+        def replace_with(comment)
+          return COPYRIGHT if newline_after_copyright?(comment)
+
+          "#{COPYRIGHT}\n"
+        end
+      end
+    end
+  end
+end

+ 3 - 0
.rubocop/rubocop_zammad.rb

@@ -1,6 +1,9 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 require_relative 'cop/zammad/exists_condition'
 require_relative 'cop/zammad/exists_condition'
 require_relative 'cop/zammad/exists_date_time_precision'
 require_relative 'cop/zammad/exists_date_time_precision'
 require_relative 'cop/zammad/exists_reset_column_information'
 require_relative 'cop/zammad/exists_reset_column_information'
 require_relative 'cop/zammad/have_no_over_not_to'
 require_relative 'cop/zammad/have_no_over_not_to'
 require_relative 'cop/zammad/no_to_sym_on_string'
 require_relative 'cop/zammad/no_to_sym_on_string'
 require_relative 'cop/zammad/prefer_negated_if_over_unless'
 require_relative 'cop/zammad/prefer_negated_if_over_unless'
+require_relative 'cop/zammad/update_copyright'

+ 2 - 0
Gemfile

@@ -1,3 +1,5 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 source 'https://rubygems.org'
 source 'https://rubygems.org'
 
 
 # core - base
 # core - base

+ 2 - 0
Guardfile

@@ -1,3 +1,5 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 # A sample Guardfile
 # A sample Guardfile
 # More info at https://github.com/guard/guard#readme
 # More info at https://github.com/guard/guard#readme
 
 

+ 2 - 0
Rakefile

@@ -1,4 +1,6 @@
 #!/usr/bin/env rake
 #!/usr/bin/env rake
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 # Add your own tasks in files placed in lib/tasks ending in .rake,
 # Add your own tasks in files placed in lib/tasks ending in .rake,
 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
 
 

+ 1 - 1
app/controllers/activity_stream_controller.rb

@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
 
 
 class ActivityStreamController < ApplicationController
 class ActivityStreamController < ApplicationController
   prepend_before_action :authentication_check
   prepend_before_action :authentication_check

+ 2 - 1
app/controllers/application_controller.rb

@@ -1,4 +1,5 @@
-# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 class ApplicationController < ActionController::Base
 class ApplicationController < ActionController::Base
   include ApplicationController::HandlesErrors
   include ApplicationController::HandlesErrors
   include ApplicationController::HandlesDevices
   include ApplicationController::HandlesDevices

+ 2 - 0
app/controllers/application_controller/authenticates.rb

@@ -1,3 +1,5 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 module ApplicationController::Authenticates
 module ApplicationController::Authenticates
   extend ActiveSupport::Concern
   extend ActiveSupport::Concern
 
 

+ 2 - 0
app/controllers/application_controller/authorizes.rb

@@ -1,3 +1,5 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 module ApplicationController::Authorizes
 module ApplicationController::Authorizes
   extend ActiveSupport::Concern
   extend ActiveSupport::Concern
   include Pundit
   include Pundit

+ 2 - 0
app/controllers/application_controller/checks_maintenance.rb

@@ -1,3 +1,5 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
 module ApplicationController::ChecksMaintenance
 module ApplicationController::ChecksMaintenance
   extend ActiveSupport::Concern
   extend ActiveSupport::Concern
 
 

Некоторые файлы не были показаны из-за большого количества измененных файлов