rubocop-turn_yourself_in 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/turn_yourself_in +5 -0
- data/lib/rubocop/turn_yourself_in.rb +10 -0
- data/lib/rubocop/turn_yourself_in/cli.rb +113 -0
- data/lib/rubocop/turn_yourself_in/version.rb +9 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a599ac7f8311af164e916f21f707d0909a4cab156690482cd20d897b6207e877
|
4
|
+
data.tar.gz: f0bf85eb42b4c6491267385f2633d48240551162d7c19c599352fc16d064899a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8521fa322f3d4304e3704a31f1e87bede41fe5cb054064ca6c18c04b8e70f9469bc5d74319658ae4e522880d3669f82cb34d2ac5b4fc26c21646fb89da74456
|
7
|
+
data.tar.gz: 7c83978ceabbef93f010a653c4ec0a68df425c2b0697ac7a86b4715f0b8a79e2c756c770ec1ad10f265bed1dfca2da231328ebb0110e4feb34192c04ab64e4e8
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'English'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module TurnYourselfIn
|
7
|
+
class CLI
|
8
|
+
E_USAGE = 1
|
9
|
+
E_TODO_FILE_NOT_FOUND = 2
|
10
|
+
E_TODO_FILE_PARSE_FAIL = 3
|
11
|
+
E_GIT_ADD_FAIL = 4
|
12
|
+
E_GIT_COMMIT_FAIL = 5
|
13
|
+
E_RUBOCOP_AUTOCORRECT_FAIL = 6
|
14
|
+
E_DIRTY_WORKING_COPY = 7
|
15
|
+
TODO_FILENAME = '.rubocop_todo.yml'
|
16
|
+
|
17
|
+
def initialize(argv)
|
18
|
+
@options = {
|
19
|
+
dry_run: false,
|
20
|
+
prompt: true
|
21
|
+
}
|
22
|
+
args = argv.dup
|
23
|
+
until args.empty?
|
24
|
+
arg = args.shift
|
25
|
+
if arg == '--dry-run'
|
26
|
+
@options[:dry_run] = true
|
27
|
+
elsif arg == '--no-prompt'
|
28
|
+
@options[:prompt] = false
|
29
|
+
else
|
30
|
+
exit_with_usage
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
assert_clean_working_copy
|
37
|
+
remove_comments
|
38
|
+
loop do
|
39
|
+
todos = parse_todos
|
40
|
+
break if todos.empty?
|
41
|
+
cop = todos.keys.first
|
42
|
+
if @options[:prompt]
|
43
|
+
print format('Auto-correct %s? (y/n/q) ', cop)
|
44
|
+
choice = $stdin.gets.strip
|
45
|
+
else
|
46
|
+
choice = 'y'
|
47
|
+
end
|
48
|
+
if choice == 'y'
|
49
|
+
write_todos(todos.except(cop))
|
50
|
+
command('bin/rubocop -A', E_RUBOCOP_AUTOCORRECT_FAIL)
|
51
|
+
commit(cop)
|
52
|
+
elsif choice == 'q'
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def exit_with_usage
|
61
|
+
warn "Usage: turn_yourself_in --dry-run --no-prompt"
|
62
|
+
exit E_USAGE
|
63
|
+
end
|
64
|
+
|
65
|
+
def command(cmd, exit_code)
|
66
|
+
puts cmd
|
67
|
+
return if @dry_run
|
68
|
+
unless system(cmd)
|
69
|
+
warn format('Command failed: exited with %s', $CHILD_STATUS.to_s)
|
70
|
+
exit exit_code
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def commit(message)
|
75
|
+
command('git add .', E_GIT_ADD_FAIL)
|
76
|
+
command(format('git commit -m "Lint: TYI: %s"', message), E_GIT_COMMIT_FAIL)
|
77
|
+
end
|
78
|
+
|
79
|
+
def clean?
|
80
|
+
return true if @dry_run
|
81
|
+
`git status --porcelain`.strip.empty?
|
82
|
+
end
|
83
|
+
|
84
|
+
# First commit removes comments. We're not going to be able to keep them
|
85
|
+
# because the parser discards them.
|
86
|
+
def remove_comments
|
87
|
+
todos = parse_todos
|
88
|
+
write_todos(todos)
|
89
|
+
commit('Remove comments') unless clean?
|
90
|
+
end
|
91
|
+
|
92
|
+
def parse_todos
|
93
|
+
YAML.load(File.read(TODO_FILENAME))
|
94
|
+
rescue Psych::SyntaxError => e
|
95
|
+
warn e
|
96
|
+
exit E_TODO_FILE_PARSE_FAIL
|
97
|
+
rescue Errno::ENOENT => e
|
98
|
+
warn format('File not found: %s: %s', TODO_FILENAME, e)
|
99
|
+
exit E_TODO_FILE_NOT_FOUND
|
100
|
+
end
|
101
|
+
|
102
|
+
def assert_clean_working_copy
|
103
|
+
return if clean?
|
104
|
+
warn 'This script makes git commits but your working copy is not clean.'
|
105
|
+
exit E_DIRTY_WORKING_COPY
|
106
|
+
end
|
107
|
+
|
108
|
+
def write_todos(todos)
|
109
|
+
File.write(TODO_FILENAME, YAML.dump(todos))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-turn_yourself_in
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Beck
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.1'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- jared@jaredbeck.com
|
30
|
+
executables:
|
31
|
+
- turn_yourself_in
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/turn_yourself_in
|
36
|
+
- lib/rubocop/turn_yourself_in.rb
|
37
|
+
- lib/rubocop/turn_yourself_in/cli.rb
|
38
|
+
- lib/rubocop/turn_yourself_in/version.rb
|
39
|
+
homepage:
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2.6'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.1.4
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Fix RuboCop to-dos, with one git commit per cop
|
61
|
+
test_files: []
|