Sha256: f5a7d383b54ccc57a05c61b7386ef94a8b101ff3d8a9902955c55fba6bf54d53

Contents?: true

Size: 903 Bytes

Versions: 7

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Analyzers
      class CommitSubjectPrefix < Abstract
        def self.defaults
          {
            enabled: true,
            severity: :error,
            includes: %w[Fixed Added Updated Removed Refactored]
          }
        end

        def valid?
          return true if fixup_or_squash?
          return true if filter_list.empty?

          commit.subject.match?(/\A#{Regexp.union filter_list.to_regexp}/)
        end

        def issue
          return {} if valid?

          {hint: %(Use: #{filter_list.to_hint}.)}
        end

        protected

        def load_filter_list
          Kit::FilterList.new settings.fetch(:includes)
        end

        private

        def fixup_or_squash?
          commit.is_a?(Git::Lint::Commits::Unsaved) && (commit.fixup? || commit.squash?)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
git-lint-1.4.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-1.3.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-1.2.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-1.1.1 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-1.1.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-1.0.1 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-1.0.0 lib/git/lint/analyzers/commit_subject_prefix.rb