Sha256: 692f98ba5496ef375baed526e3e86530fb4f50182c5d8ed61cd258878b638ec5

Contents?: true

Size: 872 Bytes

Versions: 34

Compression:

Stored size: 872 Bytes

Contents

# encoding: utf-8
require 'pre-commit/checks/plugin'

module PreCommit
  module Checks
    class NbSpace < Plugin

      def call(staged_files)
        nb_space = " "
        raise "you messed that up" unless nb_space.bytes.to_a == [194, 160]

        staged_files.reject! { |f| f =~ /^vendor\// || !File.read(f, encoding: 'utf-8').include?(nb_space) }

        bad = staged_files.map do |file|
          content = File.read(file).lines.to_a
          line_no = content.index { |l| l.include?(nb_space) }
          char_no = content[line_no].index(nb_space)
          [file, line_no, char_no]
        end

        return if bad.empty?
        "Detected non-breaking space in #{bad.map { |f,l,c| "#{f}:#{l+1} character:#{c+1}" }.join(" and")}, remove it!"
      end

      def self.description
        "Detected non-breaking spaces 194, 160."
      end

    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
pre-commit-0.40.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.39.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.38.1 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.38.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.37.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.36.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.35.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.34.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.33.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.32.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.31.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.30.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.29.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.28.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.27.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.26.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.25.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.24.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.23.0 lib/plugins/pre_commit/checks/nb_space.rb
pre-commit-0.22.1 lib/plugins/pre_commit/checks/nb_space.rb