diff --git a/CHANGELOG.md b/CHANGELOG.md index 850b765..2ae1da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ Changelog master --- +2.2.0 +--- + +- also inspect `.rake` files +- readme format changes 2.1.0 --- diff --git a/Gemfile b/Gemfile index 851fabc..5f10ba8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,4 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/LICENSE b/LICENSE index 1a3a66e..9597938 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 runtastic GmbH +Copyright (c) 2019 runtastic GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Rakefile b/Rakefile index 9735cf2..ec64a26 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' begin diff --git a/bin/console b/bin/console index 0836186..02903bd 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'rubocop_runner' diff --git a/lib/rubocop_runner.rb b/lib/rubocop_runner.rb index 0fd1af9..e7fcf7f 100644 --- a/lib/rubocop_runner.rb +++ b/lib/rubocop_runner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubocop_runner/version' require 'rubocop' @@ -7,6 +9,7 @@ module RubocopRunner # from https://github.com/djberg96/ptools/blob/master/lib/ptools.rb#L90 def binary?(file) return true if File.ftype(file) != 'file' + s = (File.read(file, File.stat(file).blksize) || '').split(//) ((s.size - s.grep(' '..'~').size) / s.size.to_f) > 0.30 end @@ -42,8 +45,8 @@ def files end end - RUBY_PATTERN = /\.(rb|gemspec|rake)$/ - RUBY_NAMES = %w(Guardfile Gemfile Rakefile config.ru).freeze + RUBY_PATTERN = /\.(rb|gemspec|rake)$/.freeze + RUBY_NAMES = %w[Guardfile Gemfile Rakefile config.ru].freeze def ruby_file?(filename) RUBY_NAMES.include?(filename) || !(filename =~ RUBY_PATTERN).nil? @@ -55,12 +58,13 @@ def staged_ruby_files end end - DEFAULT_ARGS = %w(--auto-correct + DEFAULT_ARGS = %w[--auto-correct --format fuubar --force-exclusion - --fail-level autocorrect).freeze + --fail-level autocorrect].freeze def run return 0 if staged_ruby_files.empty? + ::RuboCop::CLI.new.run(DEFAULT_ARGS + staged_ruby_files) end @@ -73,6 +77,7 @@ def root def create_backup(pre_commit_path) return unless File.exist?(pre_commit_path) + FileUtils.mv(pre_commit_path, pre_commit_path.join('.bkp'), force: true) @@ -82,6 +87,7 @@ def install(root = '.') require 'fileutils' git_root = Pathname.new "#{root}/.git" return false unless File.exist?(git_root) + pre_commit_path = git_root.join('hooks', 'pre-commit') create_backup(pre_commit_path) diff --git a/lib/rubocop_runner/version.rb b/lib/rubocop_runner/version.rb index 73cace5..619c9b3 100644 --- a/lib/rubocop_runner/version.rb +++ b/lib/rubocop_runner/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RubocopRunner - VERSION = '2.1.0'.freeze + VERSION = '2.2.0' end diff --git a/lib/template/pre-commit b/lib/template/pre-commit old mode 100644 new mode 100755 index bab8508..2afa20e --- a/lib/template/pre-commit +++ b/lib/template/pre-commit @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true begin require 'bundler/setup' diff --git a/rubocop_runner.gemspec b/rubocop_runner.gemspec index aa62ad3..e684ecd 100644 --- a/rubocop_runner.gemspec +++ b/rubocop_runner.gemspec @@ -1,5 +1,6 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'rubocop_runner/version' @@ -22,9 +23,9 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.10' + spec.add_development_dependency 'bundler', '> 1.10', '<3' spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rubocop' spec.add_development_dependency 'pry' + spec.add_development_dependency 'rubocop' end