rubocop-parse_int 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44e78f1e3a89c35fabebd6e455100f0388d89003
4
+ data.tar.gz: 807096a1d938e3eb56600050e5afafd6b5637fdc
5
+ SHA512:
6
+ metadata.gz: 46ef7bb8d1120949b5067db538d6be09ffe19f09f799cd9a37bebdca23add252e558a5f0f5e77a73ba62549bf3768ae9c3ba6d9bd66b0c05f09256eed8a013d8
7
+ data.tar.gz: 20e8f7c16931e25879a7fff75449566497db3cfc5dbb2cd55f7500192ce0fc99a0339d7c27cf787c19c42fe0cd0f3068e0f2977a41d07f7cfce9229461c88b1f
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - spec/**/*.rb
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop-parse_int.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ryo Kato
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,61 @@
1
+ # Rubocop ParseInt
2
+
3
+ RuboCop plugin to check for unsafe integer parsings
4
+
5
+ This plugin is composed of:
6
+
7
+ - Lint/KernelIntegerWithoutBase
8
+ - Lint/StringToInt (See the 'Note' section below)
9
+
10
+ ## Installation
11
+
12
+ Just install the `rubocop-parse_int` gem
13
+
14
+ ```bash
15
+ gem install rubocop-parse_int
16
+ ```
17
+
18
+ or if you use bundler plt this in your `Gemfile`
19
+
20
+ ```ruby
21
+ gem 'rubocop-rspec'
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### RuboCop configuration file
27
+
28
+ Put this into your `.rubocop.yml`.
29
+
30
+ ```
31
+ require: rubocop-parse_int
32
+ ```
33
+
34
+ Now you can run `rubocop` and it will automatically load the RuboCop ParseInt
35
+ cops together with the standard cops.
36
+
37
+ ### Command line
38
+
39
+ ```bash
40
+ rubocop --require rubocop-parse_int
41
+ ```
42
+
43
+ ### Rake task
44
+
45
+ ```ruby
46
+ RuboCop::RakeTask.new do |task|
47
+ task.requires << 'rubocop-parse_int'
48
+ end
49
+ ```
50
+
51
+ ## Note
52
+
53
+ Currently, `Lint/StringToInt` responds to calls to #to_i on a non-String variable too.
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hashedhyphen/rubocop-parse_int.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubocop/parse_int'
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__)
data/bin/setup ADDED
@@ -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,8 @@
1
+ Lint/KernelIntegerWithoutBase:
2
+ Description: 'Checks for calls to Kernel.#Integer without a base.'
3
+ Enabled: true
4
+
5
+ Lint/StringToInteger:
6
+ Description: 'Check for possible calls to String#to_i instead of Kernel#.Integer.'
7
+ Enabled: true
8
+ Severity: convention
@@ -0,0 +1,31 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Lint
4
+ # This cop checks for calls to Kernel.#Integer without a base.
5
+ class KernelIntegerWithoutBase < Cop
6
+ MSG = 'Specify a base as 2nd arg. e.g. `Integer(str, base)`.'.freeze
7
+
8
+ def on_send(node)
9
+ receiver, method_name, *args = *node
10
+
11
+ return unless method_name == :Integer
12
+ return unless check_receiver(receiver)
13
+ return unless check_args(args)
14
+
15
+ add_offense(node, :expression)
16
+ end
17
+
18
+ private
19
+
20
+ def check_receiver(receiver)
21
+ return true unless receiver
22
+ receiver.const_type? && receiver.const_name == 'Kernel'
23
+ end
24
+
25
+ def check_args(args)
26
+ args.size < 2
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Lint
4
+ # This cop checks for possible calls to String#to_i instead of
5
+ # Kernel#.Integer.
6
+ class StringToInt < Cop
7
+ MSG = 'Perhaps String#to_i is called? Use `Integer(str, base)`.'.freeze
8
+
9
+ def on_send(node)
10
+ receiver, method_name, * = *node
11
+
12
+ return unless method_name == :to_i
13
+ return unless check_receiver(receiver)
14
+
15
+ add_offense(node, :expression)
16
+ end
17
+
18
+ private
19
+
20
+ def check_receiver(receiver)
21
+ return false unless receiver
22
+ receiver.str_type? || receiver.lvar_type?
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubocop'
2
+ require 'rubocop/parse_int/version'
3
+ require 'rubocop/parse_int/inject'
4
+
5
+ RuboCop::ParseInt::Inject.defaults!
6
+
7
+ # cops
8
+ require 'rubocop/cop/lint/string_to_int'
9
+ require 'rubocop/cop/lint/kernel_integer_without_base'
@@ -0,0 +1,24 @@
1
+ # This file is copied from rubocop-rspec
2
+ # https://github.com/backus/rubocop-rspec/blob/75827985e33ad0e8b306f1bbfe31e678b28e594e/lib/rubocop/rspec/inject.rb
3
+ require 'yaml'
4
+
5
+ module RuboCop
6
+ module ParseInt
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ DEFAULT_FILE = File.expand_path(
11
+ '../../../../config/default.yml', __FILE__
12
+ )
13
+
14
+ def self.defaults!
15
+ path = File.absolute_path(DEFAULT_FILE)
16
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
17
+ config = Config.new(hash, path)
18
+ puts "configuration from #{path}" if ConfigLoader.debug?
19
+ config = ConfigLoader.merge_with_default(config, path)
20
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Rubocop
2
+ module ParseInt
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rubocop/parse_int/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rubocop-parse_int'
9
+ spec.version = Rubocop::ParseInt::VERSION
10
+ spec.authors = ['Ryo Kato']
11
+ spec.email = ['ryo_kato@hashedhyphen.com']
12
+
13
+ spec.summary = 'RuboCop plugin to check for unsafe integer parsings'
14
+ spec.description = <<-end_description
15
+ RuboCop plugin to check for unsafe integer parsings.
16
+ A plugin for the RuboCop code style enforcing & linting tool.
17
+ end_description
18
+ spec.homepage = 'https://github.com/hashedhyphen/rubocop-parse_int'
19
+ spec.license = 'MIT'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_runtime_dependency 'rubocop', '>= 0.49.0'
29
+
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'rspec'
33
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-parse_int
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Kato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-24 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.49.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.49.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |2
70
+ RuboCop plugin to check for unsafe integer parsings.
71
+ A plugin for the RuboCop code style enforcing & linting tool.
72
+ email:
73
+ - ryo_kato@hashedhyphen.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - config/default.yml
89
+ - lib/rubocop/cop/lint/kernel_integer_without_base.rb
90
+ - lib/rubocop/cop/lint/string_to_int.rb
91
+ - lib/rubocop/parse_int.rb
92
+ - lib/rubocop/parse_int/inject.rb
93
+ - lib/rubocop/parse_int/version.rb
94
+ - rubocop-parse_int.gemspec
95
+ homepage: https://github.com/hashedhyphen/rubocop-parse_int
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.6.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: RuboCop plugin to check for unsafe integer parsings
119
+ test_files: []