More lint stuff

This commit is contained in:
Sven Weidauer 2022-05-25 19:54:22 +02:00
parent 83b6b8f61a
commit 47a691a8e9
5 changed files with 36 additions and 5 deletions

5
.rubocop.yml Normal file
View file

@ -0,0 +1,5 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.7
Exclude:
- "vendor/**/*"

View file

@ -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

View file

@ -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

View file

@ -2,7 +2,15 @@
class FormatStaged
class Entry
PATTERN = /^:(?<src_mode>\d+) (?<dst_mode>\d+) (?<src_hash>[a-f0-9]+) (?<dst_hash>[a-f0-9]+) (?<status>[A-Z])(?<score>\d+)?\t(?<src_path>[^\t]+)(?:\t(?<dst_path>[^\t]+))?$/.freeze
PATTERN = /^
:(?<src_mode>\d+)\s
(?<dst_mode>\d+)\s
(?<src_hash>[a-f0-9]+)\s
(?<dst_hash>[a-f0-9]+)\s
(?<status>[A-Z])(?<score>\d+)?\t
(?<src_path>[^\t]+)
(?:\t(?<dst_path>[^\t]+))?
$/x.freeze
attr_reader :src_mode, :dst_mode, :src_hash, :dst_hash, :status, :score, :src_path, :dst_path, :path, :root