<commit_before># frozen_string_literal: true

require 'logger'

module Commentators
  class Console
    RUBY_SNIPPET = /```ruby\n(?<code>.+)\n```/m
    def initialize(config, violation)
      @config = config
      @violation = violation
    end

    def call
      logger.info(message)
    end

    private

    def message
      [
        [cyan(@violation.filename), @violation.line.patch_position].join(':'),
        ' -- ',
        brown(@violation.linter),
        "\n",
        format_code(@violation.message)
      ].join
    end

    def logger
      @logger ||= Logger.new(STDOUT).tap do |logger|
        logger.formatter = proc do |_severity, _datetime, _progname, msg|
          "#{msg}\n"
        end
      end
    end

    def format_code(message)
      match_data = message.match(RUBY_SNIPPET)
      return message unless match_data
      message.sub(RUBY_SNIPPET, bold(match_data[:code]))
    end

    def bold(text)
      "\e[1m#{text}\e[22m"
    end

    def brown(text)
      "\e[33m#{text}\e[0m"
    end
<commit_msg>Change console logger to provide anchors<commit_after># frozen_string_literal: true

require 'logger'

module Commentators
  class Console
    DOCUMENTATION_PATH = 'https://github.com/ignat-zakrevsky/ducalis/blob/master/DOCUMENTATION.md'

    def initialize(config, violation)
      @config = config
      @violation = violation
    end

    def call
      logger.info(message)
    end

    private

    def message
      [
        [cyan(@violation.filename), @violation.line.patch_position].join(':'),
        brown(@violation.linter),
        bold(ancor)
      ].join(' ')
    end

    def logger
      @logger ||= Logger.new(STDOUT).tap do |logger|
        logger.formatter = proc do |_severity, _datetime, _progname, msg|
          "#{msg}\n"
        end
      end
    end

    def ancor
      [
        DOCUMENTATION_PATH,
        '#',
        @violation.linter.downcase.gsub(/[^[:alpha:]]/, '')
      ].join
    end

    def bold(text)
      "\e[1m#{text}\e[22m"
    end

    def brown(text)
      "\e[33m#{text}\e[0m"
    end

{'fraction_non_alphanumeric': 0.1286266924564797, 'fraction_numerical': 0.005802707930367505, 'mean_word_length': 2.2127329192546585, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4198395', 'n_tokens_mistral': 718, 'n_tokens_neox': 680, 'n_words': 137}