pronto-rubocop-autocorrect 0.9.1
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/LICENSE +21 -0
- data/README.md +13 -0
- data/lib/pronto/rubocop-autocorrect.rb +96 -0
- data/lib/pronto/rubocop-autocorrect/version.rb +5 -0
- data/pronto-rubocop-autocorrect.gemspec +40 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92bd45e8ea8ce1ad0789a76e6db9f3c42fd7ce31
|
4
|
+
data.tar.gz: 04eaccb87a3e47dd26cd86fa8a8088b874d5c749
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: adff45c419d8037cfdb2850ca03177ec3f82d04286b7f5c2267a92cfa11280b41a4794ee758977bd82410e45344f005ea09ed85eb01d70099ad9fce93b0f00be
|
7
|
+
data.tar.gz: 85ae62718664ad26c93a3abd476b26abc5060baec4f61e3340d68e5fc1a7e60a13981569ae6ccb3e59aa20de2a5130a7a566b52607a168679e6b762fe2304eee
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Mindaugas Mozūras
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Pronto runner for Rubocop
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/mmozuras/pronto-rubocop)
|
4
|
+
[](https://travis-ci.org/mmozuras/pronto-rubocop)
|
5
|
+
[](http://badge.fury.io/rb/pronto-rubocop)
|
6
|
+
[](https://gemnasium.com/mmozuras/pronto-rubocop)
|
7
|
+
|
8
|
+
Pronto runner for [Rubocop](https://github.com/bbatsov/rubocop), ruby code analyzer. [What is Pronto?](https://github.com/mmozuras/pronto)
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
Configuring Rubocop via .rubocop.yml will work just fine with pronto-rubocop.
|
13
|
+
You can also specify a custom `.rubocop.yml` location with the environment variable `RUBOCOP_CONFIG`
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'pronto'
|
2
|
+
require 'rubocop'
|
3
|
+
|
4
|
+
module Pronto
|
5
|
+
class RubocopAutocorrect < Runner
|
6
|
+
def initialize(_, _ = nil)
|
7
|
+
super
|
8
|
+
@auto_correct = true
|
9
|
+
@config_store = ::RuboCop::ConfigStore.new
|
10
|
+
if ENV['RUBOCOP_CONFIG']
|
11
|
+
@config_store.options_config = ENV['RUBOCOP_CONFIG']
|
12
|
+
end
|
13
|
+
|
14
|
+
options = { auto_correct: @auto_correct }
|
15
|
+
@inspector = ::RuboCop::Runner.new(options, @config_store)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
return [] unless @patches
|
20
|
+
|
21
|
+
messages = @patches.select { |patch| valid_patch?(patch) }
|
22
|
+
.map { |patch| process(patch) }
|
23
|
+
.flatten.compact
|
24
|
+
|
25
|
+
_add_corrected_message_total(messages) if @auto_correct
|
26
|
+
messages
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_patch?(patch)
|
30
|
+
return false if patch.additions < 1
|
31
|
+
|
32
|
+
config_store = config_store_for(patch)
|
33
|
+
path = patch.new_file_full_path
|
34
|
+
|
35
|
+
return false if config_store.file_to_exclude?(path.to_s)
|
36
|
+
return true if config_store.file_to_include?(path.to_s)
|
37
|
+
|
38
|
+
ruby_file?(path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def process(patch)
|
42
|
+
processed_source = processed_source_for(patch)
|
43
|
+
file = patch.delta.new_file[:path]
|
44
|
+
offences = @inspector.send(:do_inspection_loop, file, processed_source)[1]
|
45
|
+
_messages_for_offences(offences, patch)
|
46
|
+
end
|
47
|
+
|
48
|
+
def new_message(offence, line)
|
49
|
+
path = line.patch.delta.new_file[:path]
|
50
|
+
level = level(offence.severity.name)
|
51
|
+
message = offence.message
|
52
|
+
if offence.corrected?
|
53
|
+
message = "[Corrected] #{message}"
|
54
|
+
level = :info
|
55
|
+
end
|
56
|
+
|
57
|
+
Message.new(path, line, level, message, nil, self.class)
|
58
|
+
end
|
59
|
+
|
60
|
+
def config_store_for(patch)
|
61
|
+
path = patch.new_file_full_path.to_s
|
62
|
+
@config_store.for(path)
|
63
|
+
end
|
64
|
+
|
65
|
+
def processed_source_for(patch)
|
66
|
+
path = patch.new_file_full_path.to_s
|
67
|
+
::RuboCop::ProcessedSource.from_file(path, RUBY_VERSION[0..2].to_f)
|
68
|
+
end
|
69
|
+
|
70
|
+
def level(severity)
|
71
|
+
case severity
|
72
|
+
when :refactor, :convention
|
73
|
+
:warning
|
74
|
+
when :warning, :error, :fatal
|
75
|
+
severity
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def _add_corrected_message_total(messages)
|
82
|
+
corrected_messages = messages.select { |m| m.msg =~ /\[Corrected\]/ }
|
83
|
+
total = "Total offenses: #{messages.size} " \
|
84
|
+
" Corrected: #{corrected_messages.size}"
|
85
|
+
messages << Message.new(nil, nil, :info, total, nil, self.class)
|
86
|
+
end
|
87
|
+
|
88
|
+
def _messages_for_offences(offences, patch)
|
89
|
+
offences.sort.reject(&:disabled?).map do |offence|
|
90
|
+
patch.added_lines
|
91
|
+
.select { |line| line.new_lineno == offence.line }
|
92
|
+
.map { |line| new_message(offence, line) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
4
|
+
require 'pronto/rubocop-autocorrect/version'
|
5
|
+
require 'English'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'pronto-rubocop-autocorrect'
|
9
|
+
s.version = Pronto::RubocopAutocorrectVersion::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.author = 'Mindaugas Mozūras'
|
12
|
+
s.email = 'mindaugas.mozuras@gmail.com'
|
13
|
+
s.homepage = 'http://github.com/mmozuras/pronto-rubocop'
|
14
|
+
s.summary = 'Pronto runner for Rubocop, ruby code analyzer'
|
15
|
+
|
16
|
+
s.licenses = ['MIT']
|
17
|
+
s.required_ruby_version = '>= 2.0.0'
|
18
|
+
s.rubygems_version = '1.8.23'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split($RS).reject do |file|
|
21
|
+
file =~ %r{^(?:
|
22
|
+
spec/.*
|
23
|
+
|Gemfile
|
24
|
+
|Rakefile
|
25
|
+
|\.rspec
|
26
|
+
|\.gitignore
|
27
|
+
|\.rubocop.yml
|
28
|
+
|\.travis.yml
|
29
|
+
)$}x
|
30
|
+
end
|
31
|
+
s.test_files = []
|
32
|
+
s.extra_rdoc_files = ['LICENSE', 'README.md']
|
33
|
+
s.require_paths = ['lib']
|
34
|
+
|
35
|
+
s.add_runtime_dependency('rubocop', '~> 0.50', '>= 0.49.1')
|
36
|
+
s.add_runtime_dependency('pronto', '~> 0.9.0')
|
37
|
+
s.add_development_dependency('rake', '~> 12.0')
|
38
|
+
s.add_development_dependency('rspec', '~> 3.4')
|
39
|
+
s.add_development_dependency('rspec-its', '~> 1.2')
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-rubocop-autocorrect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mindaugas Mozūras
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.50'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.49.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.50'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.49.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: pronto
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.9.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '12.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '12.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.4'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.4'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec-its
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.2'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.2'
|
89
|
+
description:
|
90
|
+
email: mindaugas.mozuras@gmail.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files:
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
files:
|
97
|
+
- LICENSE
|
98
|
+
- README.md
|
99
|
+
- lib/pronto/rubocop-autocorrect.rb
|
100
|
+
- lib/pronto/rubocop-autocorrect/version.rb
|
101
|
+
- pronto-rubocop-autocorrect.gemspec
|
102
|
+
homepage: http://github.com/mmozuras/pronto-rubocop
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 2.0.0
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Pronto runner for Rubocop, ruby code analyzer
|
126
|
+
test_files: []
|