rubocop-rubycw 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87fd1bec83b5aa40bb75389248446b77be192dae8e6cd995459f39568d78f677
4
+ data.tar.gz: fe7852ed6d94b11292258597015e5035387177c54001417f59cc4ae61009a600
5
+ SHA512:
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
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ Naming/FileName:
2
+ Exclude:
3
+ - lib/rubocop-rubycw.rb
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rubocop-rubycw.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem 'rspec'
@@ -0,0 +1,40 @@
1
+ # RuboCop Rubycw
2
+
3
+ Integrate RuboCop and `ruby -cw`.
4
+
5
+ You can get Ruby's warning as a RuboCop offense by rubocop-rubycw.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rubocop-rubycw'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rubocop-rubycw
22
+
23
+ ## Usage
24
+
25
+ Put this into your `.rubocop.yml`.
26
+
27
+ ```yaml
28
+ require: rubocop-rubycw
29
+ ```
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/rubocop-rubycw.
40
+
@@ -0,0 +1,30 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ desc 'Generate a new cop with a template'
11
+ task :new_cop, [:cop] do |_task, args|
12
+ require 'rubocop'
13
+
14
+ cop_name = args.fetch(:cop) do
15
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
16
+ exit!
17
+ end
18
+
19
+ github_user = `git config github.user`.chop
20
+ github_user = 'your_id' if github_user.empty?
21
+
22
+ generator = RuboCop::Cop::Generator.new(cop_name, github_user)
23
+
24
+ generator.write_source
25
+ generator.write_spec
26
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/rubycw_cops.rb')
27
+ generator.inject_config(config_file_path: 'config/default.yml')
28
+
29
+ puts generator.todo
30
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubocop/rubycw"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # Write it!
2
+
3
+ Rubycw/Rubycw:
4
+ Description: 'Execute `ruby -cw` and wrap the warning as RuboCop offense.'
5
+ Enabled: true
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/rubycw'
6
+ require_relative 'rubocop/rubycw/version'
7
+ require_relative 'rubocop/rubycw/inject'
8
+
9
+ RuboCop::Rubycw::Inject.defaults!
10
+
11
+ require_relative 'rubocop/rubycw/warning_capturer'
12
+ require_relative 'rubocop/cop/rubycw_cops'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rubycw
6
+ # Execute `ruby -cw` and wrap the warning as RuboCop offense.
7
+ class Rubycw < Cop
8
+ include RangeHelp
9
+
10
+ def investigate(processed_source)
11
+ source = processed_source.raw_source
12
+
13
+ warnings(source).each do |line|
14
+ lnum = line[/.+:(\d+):/, 1].to_i
15
+ message = line[/.+:\d+: warning: (.+)$/, 1]
16
+
17
+ range = source_range(processed_source.buffer, lnum, 0)
18
+ add_offense(range, location: range, message: message)
19
+ end
20
+ end
21
+
22
+ def warnings(source)
23
+ RuboCop::Rubycw::WarningCapturer.capture(source)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'rubycw/rubycw'
@@ -0,0 +1,14 @@
1
+ require "rubocop/rubycw/version"
2
+
3
+ module RuboCop
4
+ module Rubycw
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
8
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
9
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
10
+
11
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
12
+ end
13
+ end
14
+
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Rubycw
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module Rubycw
3
+ VERSION = "0.1.1"
4
+ end
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
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/rubocop/rubycw/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rubocop-rubycw"
5
+ spec.version = RuboCop::Rubycw::VERSION
6
+ spec.authors = ["Masataka Pocke Kuwabara"]
7
+ spec.email = ["kuwabara@pocke.me"]
8
+
9
+ spec.summary = %q{Integrate RuboCop and ruby -cw}
10
+ spec.description = %q{Integrate RuboCop and ruby -cw}
11
+ spec.homepage = "https://github.com/pocke/rubocop-rubycw"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency 'rubocop'
30
+ end
31
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-rubycw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-13 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Integrate RuboCop and ruby -cw
28
+ email:
29
+ - kuwabara@pocke.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".circleci/config.yml"
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - Gemfile
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - config/default.yml
44
+ - lib/rubocop-rubycw.rb
45
+ - lib/rubocop/cop/rubycw/rubycw.rb
46
+ - lib/rubocop/cop/rubycw_cops.rb
47
+ - lib/rubocop/rubycw.rb
48
+ - lib/rubocop/rubycw/inject.rb
49
+ - lib/rubocop/rubycw/version.rb
50
+ - lib/rubocop/rubycw/warning_capturer.rb
51
+ - rubocop-rubycw.gemspec
52
+ homepage: https://github.com/pocke/rubocop-rubycw
53
+ licenses: []
54
+ metadata:
55
+ homepage_uri: https://github.com/pocke/rubocop-rubycw
56
+ source_code_uri: https://github.com/pocke/rubocop-rubycw
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Integrate RuboCop and ruby -cw
76
+ test_files: []