rubocop-rubycw 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60b45d27802b3ad9ac0f525498f2874c1a5ebab0d5b5546f1eda189ad67c9b27
4
- data.tar.gz: 3b017269d8ac789d4f1b2b2bf6393fe2bbf295a3f53bc7034dbf79ee586432a9
3
+ metadata.gz: 87fd1bec83b5aa40bb75389248446b77be192dae8e6cd995459f39568d78f677
4
+ data.tar.gz: fe7852ed6d94b11292258597015e5035387177c54001417f59cc4ae61009a600
5
5
  SHA512:
6
- metadata.gz: 5d13c09ef2e7d28bfb5af34c4526ae49c205aba2771bf0f440485325fab9f5309528c133eaf127b610ca61c7e6f92965e0a11ea3b843529c2a2e623277320732
7
- data.tar.gz: a37de4fa589c706853da0332f945e33ace663488205cd6ea998497dcfaa82cd6396372900ed39a372d1746a94dbb485374444f3fa84e7d390874d37a4e4dcfdc
6
+ metadata.gz: 9149d4541c6252ffae31f4f6194184779e67a88493bc642f867529d7761a2a1691bbf80e297f14b40d56a7b8d026e82faee57f9990cf68a479897013d0d5f4df
7
+ data.tar.gz: 858e238744ce39b500106a1e97e536687d3acc6f1887df39268033edbb7fd66604be9366aa0c505e93527d0551414eb87fdc638146a4a2a7789dab523eb9a089
@@ -0,0 +1,44 @@
1
+ version: 2
2
+
3
+ steps: &steps
4
+ steps:
5
+ - checkout
6
+ - run: bundle install
7
+ - run: bundle exec rake
8
+
9
+ jobs:
10
+
11
+ ruby-2.3:
12
+ docker:
13
+ - image: circleci/ruby:2.3
14
+ <<: *steps
15
+
16
+ ruby-2.4:
17
+ docker:
18
+ - image: circleci/ruby:2.4
19
+ <<: *steps
20
+
21
+ ruby-2.5:
22
+ docker:
23
+ - image: circleci/ruby:2.5
24
+ <<: *steps
25
+
26
+ ruby-2.6:
27
+ docker:
28
+ - image: circleci/ruby:2.6
29
+ <<: *steps
30
+
31
+ ruby-head:
32
+ docker:
33
+ - image: rubocophq/circleci-ruby-snapshot:latest
34
+ <<: *steps
35
+
36
+ workflows:
37
+ version: 2
38
+ build:
39
+ jobs:
40
+ - ruby-2.3
41
+ - ruby-2.4
42
+ - ruby-2.5
43
+ - ruby-2.6
44
+ - ruby-head
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Rubocop::Rubycw
1
+ # RuboCop Rubycw
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/rubycw`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Integrate RuboCop and `ruby -cw`.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ You can get Ruby's warning as a RuboCop offense by rubocop-rubycw.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,11 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Put this into your `.rubocop.yml`.
26
+
27
+ ```yaml
28
+ require: rubocop-rubycw
29
+ ```
26
30
 
27
31
  ## Development
28
32
 
@@ -8,4 +8,5 @@ require_relative 'rubocop/rubycw/inject'
8
8
 
9
9
  RuboCop::Rubycw::Inject.defaults!
10
10
 
11
+ require_relative 'rubocop/rubycw/warning_capturer'
11
12
  require_relative 'rubocop/cop/rubycw_cops'
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'open3'
4
- require 'rbconfig'
5
-
6
3
  module RuboCop
7
4
  module Cop
8
5
  module Rubycw
@@ -12,20 +9,18 @@ module RuboCop
12
9
 
13
10
  def investigate(processed_source)
14
11
  source = processed_source.raw_source
15
- _stdout, stderr, _status = Open3.capture3(ruby, '-cw', '-e', source)
16
12
 
17
- stderr.each_line do |line|
18
- line.chomp!
19
- lnum = line[/-e:(\d+):/, 1].to_i
20
- message = line[/-e:\d+: warning: (.+)$/, 1]
13
+ warnings(source).each do |line|
14
+ lnum = line[/.+:(\d+):/, 1].to_i
15
+ message = line[/.+:\d+: warning: (.+)$/, 1]
21
16
 
22
17
  range = source_range(processed_source.buffer, lnum, 0)
23
18
  add_offense(range, location: range, message: message)
24
19
  end
25
20
  end
26
21
 
27
- def ruby
28
- RbConfig.ruby
22
+ def warnings(source)
23
+ RuboCop::Rubycw::WarningCapturer.capture(source)
29
24
  end
30
25
  end
31
26
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module Rubycw
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Rubycw
5
+ module WarningCapturer
6
+ if defined?(RubyVM::AbstractSyntaxTree)
7
+ require 'stringio'
8
+
9
+ module ::Warning
10
+ def warn(*message)
11
+ if WarningCapturer.warnings
12
+ WarningCapturer.warnings.concat message
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.capture(source)
20
+ start
21
+ RubyVM::AbstractSyntaxTree.parse(source)
22
+ warnings
23
+ ensure
24
+ stop
25
+ end
26
+
27
+ def self.start
28
+ @verbose = $VERBOSE
29
+ $VERBOSE = true
30
+ @warnings = []
31
+ end
32
+
33
+ def self.stop
34
+ $VERBOSE = @verbose if defined?(@verbose)
35
+ @warnings = nil
36
+ end
37
+
38
+ def self.warnings
39
+ @warnings
40
+ end
41
+
42
+ stop
43
+ else
44
+ require 'rbconfig'
45
+ require 'open3'
46
+
47
+ def self.capture(source)
48
+ _stdout, stderr, _status = Open3.capture3(RbConfig.ruby, '-cw', '-e', source)
49
+ stderr.lines.map(&:chomp)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rubycw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Pocke Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".circleci/config.yml"
34
35
  - ".gitignore"
35
36
  - ".rspec"
36
37
  - ".rubocop.yml"
@@ -46,6 +47,7 @@ files:
46
47
  - lib/rubocop/rubycw.rb
47
48
  - lib/rubocop/rubycw/inject.rb
48
49
  - lib/rubocop/rubycw/version.rb
50
+ - lib/rubocop/rubycw/warning_capturer.rb
49
51
  - rubocop-rubycw.gemspec
50
52
  homepage: https://github.com/pocke/rubocop-rubycw
51
53
  licenses: []