guard-rubocop 1.0.1 → 1.4.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 +5 -5
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +33 -4
- data/.rubocop_todo.yml +12 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +3 -3
- data/Guardfile +13 -9
- data/README.md +50 -7
- data/Rakefile +4 -17
- data/guard-rubocop.gemspec +16 -13
- data/lib/guard/rubocop.rb +10 -8
- data/lib/guard/rubocop/runner.rb +30 -14
- data/lib/guard/rubocop/templates/Guardfile +1 -1
- data/lib/guard/rubocop/version.rb +10 -12
- data/spec/guard/rubocop/runner_spec.rb +169 -79
- data/spec/guard/rubocop_spec.rb +29 -28
- data/spec/spec_helper.rb +21 -19
- data/spec/support/silence_output.rb +20 -7
- data/spec/support/simplecov.rb +19 -0
- metadata +43 -37
- data/.travis.yml +0 -8
- data/spec/.rubocop.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e66ec8cc26e03e6fc402a04e57ba01155e2811f53e2bbc07537ce83657240ee4
|
4
|
+
data.tar.gz: 98c66cd08f8ac9bbf37b259c11250bb24b2e123005c8306c066e0111f6cac935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09bf72978e4a18615a30494e8422c7f66cac1fd0f01ede788966ab47f2ea41541b08fe81e6dae2200e09407973cefc821deabe7577e8983b52788e9d005324fa'
|
7
|
+
data.tar.gz: '0490a4d82a4fc9385c8e01ffe6cf7bec665d67d494a830b5bd8063b281c8a2b501210f46ea93c2c03d11cfa5f8ae2d883cd4e3db267efb8103f426192a850420'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
rspec:
|
5
|
+
name: RSpec
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby: [2.4, 2.5, 2.6, 2.7]
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: ${{ matrix.ruby }}
|
15
|
+
- run: bundle install
|
16
|
+
- run: bundle exec rspec
|
17
|
+
- uses: coverallsapp/github-action@master
|
18
|
+
with:
|
19
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
20
|
+
rubocop:
|
21
|
+
name: RuboCop
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: 2.7
|
28
|
+
- run: bundle install
|
29
|
+
- run: bundle exec rubocop
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,36 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Layout/FirstArrayElementIndentation:
|
4
|
+
EnforcedStyle: consistent
|
5
|
+
|
6
|
+
Layout/LineLength:
|
3
7
|
Max: 100
|
4
8
|
|
5
|
-
|
6
|
-
|
9
|
+
Lint/MissingSuper:
|
10
|
+
Exclude:
|
11
|
+
- spec/support/silence_output.rb
|
12
|
+
|
13
|
+
Metrics/BlockLength:
|
14
|
+
Exclude:
|
15
|
+
- 'spec/**/*.rb'
|
16
|
+
|
17
|
+
Metrics/MethodLength:
|
7
18
|
Max: 15
|
19
|
+
|
20
|
+
Naming/HeredocDelimiterNaming:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Naming/RescuedExceptionsVariableName:
|
24
|
+
PreferredName: error
|
25
|
+
|
26
|
+
Style/EmptyMethod:
|
27
|
+
EnforcedStyle: expanded
|
28
|
+
|
29
|
+
Style/FrozenStringLiteralComment:
|
30
|
+
Exclude:
|
31
|
+
- lib/guard/rubocop/templates/Guardfile
|
32
|
+
|
33
|
+
Style/RegexpLiteral:
|
34
|
+
Exclude:
|
35
|
+
- '**/*.gemspec'
|
36
|
+
- '**/Guardfile'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-01-20 14:55:30 +0900 using RuboCop version 0.52.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: CountComments.
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Max: 103
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,27 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v1.4.0
|
6
|
+
|
7
|
+
* Support RuboCop 1.0
|
8
|
+
|
9
|
+
## v1.3.0
|
10
|
+
|
11
|
+
* Add `:launchy` option ([#21](https://github.com/yujinakayama/guard-rubocop/pull/21), [#35](https://github.com/yujinakayama/guard-rubocop/pull/35))
|
12
|
+
* Modify the `Guardfile` template so that RuboCop can be run when `.rubocop_todo.yml` is modified ([#36](https://github.com/yujinakayama/guard-rubocop/pull/36))
|
13
|
+
|
14
|
+
## v1.2.0
|
15
|
+
|
16
|
+
* Add `:hide_stdout` option ([#15](https://github.com/yujinakayama/guard-rubocop/pull/15))
|
17
|
+
|
18
|
+
## v1.1.0
|
19
|
+
|
20
|
+
* Use RuboCop's `--force-exclusion` option to always ignore files specified in the `Exclude` configuration in `.rubocop.yml`
|
21
|
+
|
22
|
+
## v1.0.2
|
23
|
+
|
24
|
+
* Support both spelling “offense” (RuboCop 0.19 or later) and “offence” (prior to RuboCop 0.19) ([rubocop#700](https://github.com/bbatsov/rubocop/issues/700))
|
25
|
+
|
5
26
|
## v1.0.1
|
6
27
|
|
7
28
|
* Fix inappripriate multiple run on a save with Vim ([#6](https://github.com/yujinakayama/guard-rubocop/pull/6))
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# A sample Guardfile
|
2
4
|
# More info at https://github.com/guard/guard#readme
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
group :red_green_refactor, halt_on_fail: true do
|
7
|
+
guard :rspec, all_after_pass: true, all_on_start: true, cmd: 'bundle exec rspec' do
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
10
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
11
|
+
watch(%r{^spec/support/.+\.rb$}) { 'spec' }
|
12
|
+
end
|
10
13
|
|
11
|
-
guard :rubocop do
|
12
|
-
|
13
|
-
|
14
|
+
guard :rubocop do
|
15
|
+
watch(%r{.+\.rb$})
|
16
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
17
|
+
end
|
14
18
|
end
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
[](http://badge.fury.io/rb/guard-rubocop)
|
2
|
+
[](https://github.com/yujinakayama/guard-rubocop/actions)
|
3
|
+
[](https://coveralls.io/github/yujinakayama/guard-rubocop?branch=master)
|
4
|
+
[](https://codeclimate.com/github/yujinakayama/guard-rubocop)
|
2
5
|
|
3
|
-
#
|
6
|
+
# guard-rubocop
|
4
7
|
|
5
|
-
|
8
|
+
**guard-rubocop** allows you to automatically check Ruby code style with [RuboCop](https://github.com/bbatsov/rubocop) when files are modified.
|
6
9
|
|
7
|
-
Tested on MRI
|
10
|
+
Tested on MRI 2.4 - 2.7.
|
8
11
|
|
9
12
|
## Installation
|
10
13
|
|
@@ -30,7 +33,7 @@ or install it yourself as:
|
|
30
33
|
$ gem install guard-rubocop
|
31
34
|
```
|
32
35
|
|
33
|
-
Add the default Guard::
|
36
|
+
Add the default Guard::RuboCop definition to your `Guardfile` by running:
|
34
37
|
|
35
38
|
```sh
|
36
39
|
$ guard init rubocop
|
@@ -55,9 +58,11 @@ end
|
|
55
58
|
```ruby
|
56
59
|
all_on_start: true # Check all files at Guard startup.
|
57
60
|
# default: true
|
58
|
-
cli:
|
61
|
+
cli: '--rails' # Pass arbitrary RuboCop CLI arguments.
|
59
62
|
# An array or string is acceptable.
|
60
63
|
# default: nil
|
64
|
+
hide_stdout: false # Do not display console output (in case outputting to file).
|
65
|
+
# default: false
|
61
66
|
keep_failed: true # Keep failed files until they pass.
|
62
67
|
# default: true
|
63
68
|
notification: :failed # Display Growl notification after each run.
|
@@ -65,8 +70,46 @@ notification: :failed # Display Growl notification after each run.
|
|
65
70
|
# false - Never notify
|
66
71
|
# :failed - Notify only when failed
|
67
72
|
# default: :failed
|
73
|
+
launchy: nil # Filename to launch using Launchy after RuboCop runs.
|
74
|
+
# default: nil
|
75
|
+
```
|
76
|
+
|
77
|
+
### Using Launchy to view results
|
78
|
+
|
79
|
+
guard-rubocop can be configured to launch a results file in lieu of or in addition to outputing results to the terminal.
|
80
|
+
Configure your Guardfile with the launchy option:
|
81
|
+
|
82
|
+
``` ruby
|
83
|
+
guard :rubocop, cli: %w(--format fuubar --format html -o ./tmp/rubocop_results.html), launchy: './tmp/rubocop_results.html' do
|
84
|
+
# ...
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
## Advanced Tips
|
89
|
+
|
90
|
+
If you're using a testing Guard plugin such as [`guard-rspec`](https://github.com/guard/guard-rspec) together with `guard-rubocop` in the TDD way (the red-green-refactor cycle),
|
91
|
+
you might be uncomfortable with the offense reports from RuboCop in the red-green phase:
|
92
|
+
|
93
|
+
* In the red-green phase, you're not necessarily required to write clean code – you just focus writing code to pass the test. It means, in this phase, `guard-rspec` should be run but `guard-rubocop` should not.
|
94
|
+
* In the refactor phase, you're required to make the code clean while keeping the test passing. In this phase, both `guard-rspec` and `guard-rubocop` should be run.
|
95
|
+
|
96
|
+
In this case, you may consider making use of the [group method](https://github.com/guard/guard/wiki/Guardfile-DSL---Configuring-Guard#group) in your `Guardfile`:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# This group allows to skip running RuboCop when RSpec failed.
|
100
|
+
group :red_green_refactor, halt_on_fail: true do
|
101
|
+
guard :rspec do
|
102
|
+
# ...
|
103
|
+
end
|
104
|
+
|
105
|
+
guard :rubocop do
|
106
|
+
# ...
|
107
|
+
end
|
108
|
+
end
|
68
109
|
```
|
69
110
|
|
111
|
+
Note: You need to use `guard-rspec` 4.2.3 or later due to a [bug](https://github.com/guard/guard-rspec/pull/234) where it unintentionally fails when there are no spec files to be run.
|
112
|
+
|
70
113
|
## Contributing
|
71
114
|
|
72
115
|
1. Fork it
|
@@ -77,6 +120,6 @@ notification: :failed # Display Growl notification after each run.
|
|
77
120
|
|
78
121
|
## License
|
79
122
|
|
80
|
-
Copyright (c) 2013 Yuji Nakayama
|
123
|
+
Copyright (c) 2013–2014 Yuji Nakayama
|
81
124
|
|
82
125
|
See the [LICENSE.txt](LICENSE.txt) for details.
|
data/Rakefile
CHANGED
@@ -1,23 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
require 'rubocop/rake_task'
|
4
6
|
|
5
7
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
|
8
|
-
namespace :ci do
|
9
|
-
task :spec do
|
10
|
-
ENV['CI'] = 'true'
|
11
|
-
|
12
|
-
ENV['CI_REPORTS'] = 'spec/reports'
|
13
|
-
require 'ci/reporter/rake/rspec'
|
14
|
-
Rake::Task['ci:setup:rspec'].invoke
|
15
|
-
|
16
|
-
Rake::Task['spec'].invoke
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
desc 'Run RSpec and RuboCop'
|
21
|
-
task all: [:spec, :style]
|
8
|
+
RuboCop::RakeTask.new(:style)
|
22
9
|
|
23
|
-
task
|
10
|
+
task ci: %i[spec style]
|
data/guard-rubocop.gemspec
CHANGED
@@ -1,32 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
6
|
require 'guard/rubocop/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.name = 'guard-rubocop'
|
10
|
-
spec.version =
|
10
|
+
spec.version = GuardRuboCopVersion.to_s
|
11
11
|
spec.authors = ['Yuji Nakayama']
|
12
12
|
spec.email = ['nkymyj@gmail.com']
|
13
13
|
spec.summary = 'Guard plugin for RuboCop'
|
14
|
-
spec.description = 'Guard::
|
14
|
+
spec.description = 'Guard::RuboCop automatically checks Ruby code style with RuboCop ' \
|
15
|
+
'when files are modified.'
|
15
16
|
spec.homepage = 'https://github.com/yujinakayama/guard-rubocop'
|
16
17
|
spec.license = 'MIT'
|
17
18
|
|
18
|
-
spec.
|
19
|
-
|
20
|
-
spec.
|
19
|
+
spec.required_ruby_version = '>= 2.4'
|
20
|
+
|
21
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
22
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(/^spec\//)
|
21
24
|
spec.require_paths = ['lib']
|
22
25
|
|
23
26
|
spec.add_runtime_dependency 'guard', '~> 2.0'
|
24
|
-
spec.add_runtime_dependency 'rubocop', '
|
27
|
+
spec.add_runtime_dependency 'rubocop', '< 2.0'
|
25
28
|
|
26
|
-
spec.add_development_dependency 'bundler'
|
27
|
-
spec.add_development_dependency '
|
28
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'guard-rspec', '>= 4.2.3', '< 5.0'
|
31
|
+
spec.add_development_dependency 'launchy', '~> 2.4'
|
32
|
+
spec.add_development_dependency 'rake', '>= 12.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
34
|
spec.add_development_dependency 'simplecov', '~> 0.7'
|
30
|
-
spec.add_development_dependency 'guard-rspec', '~> 4.0'
|
31
|
-
spec.add_development_dependency 'ruby_gntp', '~> 0.3'
|
32
35
|
end
|
data/lib/guard/rubocop.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'guard'
|
4
4
|
require 'guard/plugin'
|
5
5
|
|
6
6
|
module Guard
|
7
|
-
# This class gets API calls from `guard` and runs `rubocop` command via {Guard::
|
7
|
+
# This class gets API calls from `guard` and runs `rubocop` command via {Guard::RuboCop::Runner}.
|
8
8
|
# An instance of this class stays alive in a `guard` command session.
|
9
|
-
class
|
9
|
+
class RuboCop < Plugin
|
10
10
|
autoload :Runner, 'guard/rubocop/runner'
|
11
11
|
|
12
12
|
attr_reader :options, :failed_paths
|
@@ -16,9 +16,10 @@ module Guard
|
|
16
16
|
|
17
17
|
@options = {
|
18
18
|
all_on_start: true,
|
19
|
-
keep_failed:
|
19
|
+
keep_failed: true,
|
20
20
|
notification: :failed,
|
21
|
-
cli: nil
|
21
|
+
cli: nil,
|
22
|
+
hide_stdout: false
|
22
23
|
}.merge(options)
|
23
24
|
|
24
25
|
@failed_paths = []
|
@@ -64,8 +65,8 @@ module Guard
|
|
64
65
|
passed = runner.run(paths)
|
65
66
|
@failed_paths = runner.failed_paths
|
66
67
|
throw :task_has_failed unless passed
|
67
|
-
rescue => error
|
68
|
-
UI.error 'The following exception occurred while running guard-rubocop: '
|
68
|
+
rescue StandardError => error
|
69
|
+
UI.error 'The following exception occurred while running guard-rubocop: ' \
|
69
70
|
"#{error.backtrace.first} #{error.message} (#{error.class.name})"
|
70
71
|
end
|
71
72
|
|
@@ -74,7 +75,8 @@ module Guard
|
|
74
75
|
paths.map! { |path| File.expand_path(path) }
|
75
76
|
paths.uniq!
|
76
77
|
paths.reject! do |path|
|
77
|
-
next true unless File.
|
78
|
+
next true unless File.exist?(path)
|
79
|
+
|
78
80
|
included_in_other_path?(path, paths)
|
79
81
|
end
|
80
82
|
paths
|
data/lib/guard/rubocop/runner.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module Guard
|
6
|
-
class
|
6
|
+
class RuboCop
|
7
7
|
# This class runs `rubocop` command, retrieves result and notifies.
|
8
8
|
# An instance of this class is intended to invoke `rubocop` only once in its lifetime.
|
9
9
|
class Runner
|
@@ -22,21 +22,28 @@ module Guard
|
|
22
22
|
notify(passed)
|
23
23
|
end
|
24
24
|
|
25
|
+
open_launchy_if_needed
|
26
|
+
|
25
27
|
passed
|
26
28
|
end
|
27
29
|
|
28
30
|
def build_command(paths)
|
29
31
|
command = ['rubocop']
|
30
32
|
|
31
|
-
|
32
|
-
command.concat(%w
|
33
|
+
if should_add_default_formatter_for_console?
|
34
|
+
command.concat(%w[--format progress]) # Keep default formatter for console.
|
33
35
|
end
|
34
36
|
|
35
37
|
command.concat(['--format', 'json', '--out', json_file_path])
|
38
|
+
command << '--force-exclusion'
|
36
39
|
command.concat(args_specified_by_user)
|
37
40
|
command.concat(paths)
|
38
41
|
end
|
39
42
|
|
43
|
+
def should_add_default_formatter_for_console?
|
44
|
+
!@options[:hide_stdout] && !include_formatter_for_console?(args_specified_by_user)
|
45
|
+
end
|
46
|
+
|
40
47
|
def args_specified_by_user
|
41
48
|
@args_specified_by_user ||= begin
|
42
49
|
args = @options[:cli]
|
@@ -44,7 +51,7 @@ module Guard
|
|
44
51
|
when Array then args
|
45
52
|
when String then args.shellsplit
|
46
53
|
when NilClass then []
|
47
|
-
else
|
54
|
+
else raise ArgumentError, ':cli option must be either an array or string'
|
48
55
|
end
|
49
56
|
end
|
50
57
|
end
|
@@ -92,13 +99,15 @@ module Guard
|
|
92
99
|
text = pluralize(summary[:inspected_file_count], 'file')
|
93
100
|
text << ' inspected, '
|
94
101
|
|
95
|
-
|
102
|
+
offense_count = summary[:offense_count] || summary[:offence_count]
|
103
|
+
text << pluralize(offense_count, 'offense', no_for_zero: true)
|
96
104
|
text << ' detected'
|
97
105
|
end
|
98
106
|
|
99
107
|
def failed_paths
|
100
108
|
failed_files = result[:files].reject do |file|
|
101
|
-
file[:offences]
|
109
|
+
offenses = file[:offenses] || file[:offences]
|
110
|
+
offenses.empty?
|
102
111
|
end
|
103
112
|
failed_files.map do |file|
|
104
113
|
file[:path]
|
@@ -106,19 +115,26 @@ module Guard
|
|
106
115
|
end
|
107
116
|
|
108
117
|
def pluralize(number, thing, options = {})
|
109
|
-
text =
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
118
|
+
text =
|
119
|
+
if number.zero? && options[:no_for_zero]
|
120
|
+
+'no'
|
121
|
+
else
|
122
|
+
number.to_s
|
123
|
+
end
|
116
124
|
|
117
125
|
text << " #{thing}"
|
118
126
|
text << 's' unless number == 1
|
119
127
|
|
120
128
|
text
|
121
129
|
end
|
130
|
+
|
131
|
+
def open_launchy_if_needed
|
132
|
+
return unless (output_path = @options[:launchy])
|
133
|
+
return unless File.exist?(output_path)
|
134
|
+
|
135
|
+
require 'launchy'
|
136
|
+
::Launchy.open(output_path)
|
137
|
+
end
|
122
138
|
end
|
123
139
|
end
|
124
140
|
end
|