diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..888e1b6 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,5 @@ +AllCops: + NewCops: enable + TargetRubyVersion: 2.7 + Exclude: + - "vendor/**/*" diff --git a/bin/git-format-staged b/bin/git-format-staged index d1ac2e7..6e20263 100755 --- a/bin/git-format-staged +++ b/bin/git-format-staged @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'format-staged' +require 'format_staged' require 'optparse' parameters = { @@ -14,17 +14,31 @@ parser = OptionParser.new do |opt| opt.banner = "Usage: #{opt.program_name} [options] [patterns]" opt.separator '' opt.on('-f', '--formatter COMMAND', - 'Shell command to format files, will run once per file. Occurrences of the placeholder `{}` will be replaced with a path to the file being formatted. (Example: "prettier --stdin-filepath \'{}\'")') do |o| + <<~DOC + Shell command to format files, will run once per file. Occurrences of the placeholder `{}` will \ + be replaced with a path to the file being formatted. \ + (Example: "prettier --stdin-filepath \'{}\'") + DOC + ) do |o| parameters[:formatter] = o end opt.on('--[no-]update-working-tree', - 'By default formatting changes made to staged file content will also be applied to working tree files via a patch. This option disables that behavior, leaving working tree files untouched.') do |value| + <<~DOC + By default formatting changes made to staged file content will also be applied to working tree \ + files via a patch. This option disables that behavior, leaving working tree files untouched.#{' '} + DOC + ) do |value| parameters[:update] = value end opt.on('--[no-]write', - "Prevents #{opt.program_name} from modifying staged or working tree files. You can use this option to check staged changes with a linter instead of formatting. With this option stdout from the formatter command is ignored.") do |value| + <<~DOC + "Prevents #{opt.program_name} from modifying staged or working tree files. You can use this option \ + to check staged changes with a linter instead of formatting. With this option stdout from the \ + formatter command is ignored." + DOC + ) do |value| parameters[:write] = value end diff --git a/format-staged.gemspec b/format-staged.gemspec index ecdc19d..ff70c99 100644 --- a/format-staged.gemspec +++ b/format-staged.gemspec @@ -18,4 +18,8 @@ Gem::Specification.new do |s| s.required_ruby_version = '2.7' s.add_development_dependency 'rubocop', '~> 1.29' + + s.metadata = { + 'rubygems_mfa_required' => 'true' + } end diff --git a/lib/format-staged/entry.rb b/lib/format-staged/entry.rb index 82c171f..3684b7d 100644 --- a/lib/format-staged/entry.rb +++ b/lib/format-staged/entry.rb @@ -2,7 +2,15 @@ class FormatStaged class Entry - PATTERN = /^:(?\d+) (?\d+) (?[a-f0-9]+) (?[a-f0-9]+) (?[A-Z])(?\d+)?\t(?[^\t]+)(?:\t(?[^\t]+))?$/.freeze + PATTERN = /^ + :(?\d+)\s + (?\d+)\s + (?[a-f0-9]+)\s + (?[a-f0-9]+)\s + (?[A-Z])(?\d+)?\t + (?[^\t]+) + (?:\t(?[^\t]+))? + $/x.freeze attr_reader :src_mode, :dst_mode, :src_hash, :dst_hash, :status, :score, :src_path, :dst_path, :path, :root diff --git a/lib/format-staged.rb b/lib/format_staged.rb similarity index 100% rename from lib/format-staged.rb rename to lib/format_staged.rb