rubocop-rubycw 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 267e9277fc92afe3b044dcc764e15313316387553c4343b18bdddc61a70c82ce
4
+ data.tar.gz: 9b0e4621f503b1163dc2be5f7bd593250a7f1ff95cff6008d0cb898ee3a162dd
5
+ SHA512:
6
+ metadata.gz: '0819b989df9b8d331f67d76872a9c7239e045fd1a32e4dd57b2ae508c6b388af1d88bc4a0d10786e0662d36b9701613771d660bdb0d657e436835d181952ef19'
7
+ data.tar.gz: 19916ad772aa2cb71089d537d205b2c18e6fabbcaa51ce6214965f912b48edc7193527d9430073fdc15fa6f876b1ecae67f9693fcf4494e078da19320676d281
@@ -0,0 +1,50 @@
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-2.7:
32
+ docker:
33
+ - image: circleci/ruby:2.7
34
+ <<: *steps
35
+
36
+ ruby-head:
37
+ docker:
38
+ - image: rubocophq/circleci-ruby-snapshot:latest
39
+ <<: *steps
40
+
41
+ workflows:
42
+ version: 2
43
+ build:
44
+ jobs:
45
+ - ruby-2.3
46
+ - ruby-2.4
47
+ - ruby-2.5
48
+ - ruby-2.6
49
+ - ruby-2.7
50
+ - 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'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Masataka Pocke Kuwabara
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
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
+ ## Requirements
8
+
9
+ * Ruby 2.3 or greater.
10
+ * But I highly recommend to use Ruby 2.6 or greater.
11
+ Because it is about 10x slower if it works on Ruby 2.5 or lower.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'rubocop-rubycw'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install rubocop-rubycw
28
+
29
+ ## Usage
30
+
31
+ Put this into your `.rubocop.yml`.
32
+
33
+ ```yaml
34
+ require: rubocop-rubycw
35
+ ```
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop-hq/rubocop-rubycw.
46
+
@@ -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.4"
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Rubycw
5
+ module WarningCapturer
6
+ if defined?(RubyVM::AbstractSyntaxTree)
7
+ module ::Warning
8
+ def self.warn(*message)
9
+ if WarningCapturer.warnings
10
+ WarningCapturer.warnings.concat message
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.capture(source)
18
+ start
19
+ RubyVM::AbstractSyntaxTree.parse(source)
20
+ warnings
21
+ ensure
22
+ stop
23
+ end
24
+
25
+ def self.start
26
+ @verbose = $VERBOSE
27
+ $VERBOSE = true
28
+ @warnings = []
29
+ end
30
+
31
+ def self.stop
32
+ $VERBOSE = @verbose if defined?(@verbose)
33
+ @warnings = nil
34
+ end
35
+
36
+ def self.warnings
37
+ @warnings
38
+ end
39
+
40
+ stop
41
+ else
42
+ require 'rbconfig'
43
+ require 'open3'
44
+
45
+ def self.capture(source)
46
+ _stdout, stderr, _status = Open3.capture3(RbConfig.ruby, '-cw', stdin_data: source)
47
+ stderr.lines.map(&:chomp)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,32 @@
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/rubocop-hq/rubocop-rubycw"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.license = 'MIT'
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency 'rubocop'
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-rubycw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-02 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
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - config/default.yml
45
+ - lib/rubocop-rubycw.rb
46
+ - lib/rubocop/cop/rubycw/rubycw.rb
47
+ - lib/rubocop/cop/rubycw_cops.rb
48
+ - lib/rubocop/rubycw.rb
49
+ - lib/rubocop/rubycw/inject.rb
50
+ - lib/rubocop/rubycw/version.rb
51
+ - lib/rubocop/rubycw/warning_capturer.rb
52
+ - rubocop-rubycw.gemspec
53
+ homepage: https://github.com/rubocop-hq/rubocop-rubycw
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/rubocop-hq/rubocop-rubycw
58
+ source_code_uri: https://github.com/rubocop-hq/rubocop-rubycw
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.3.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.1.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Integrate RuboCop and ruby -cw
78
+ test_files: []