rubocop-twirp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5fd2c1e5539fcf54151b1a5a5fd90f83f7b841ada41ed672bc791212bc160c40
4
+ data.tar.gz: 8d61149045abd2246ddf00e30dabd67620b69b49e3212e37d132af265f24c7b7
5
+ SHA512:
6
+ metadata.gz: ce634e64bdc75f3702aff3d39cbd60373d17c90589aa3eb241116b52eed3bbf579e7ca554d375afbb305787681a9996d93f509fdeb0ce398372315b1dd182ffb
7
+ data.tar.gz: d51f7c50615aa2fa207c117cfeaf7d7234dd59ff3f6c946964e1c028ebd61bafcdbf9a17d67860ad9efa5fde8209fe06df210e1526552044e42470d30f3a50ea
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### v0.0.1 (2023-02-25)
2
+ -
3
+
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # TODO: remove hack/fix after twirp 1.10.1
4
+ # https://github.com/github/twirp-ruby/commit/aa4000f8ea9ff84447060ab8a7f425ed70e0bf56
5
+ gem "rack"
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-twirp (0.0.1)
5
+ rubocop (>= 1)
6
+ twirp (>= 1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ byebug (11.1.3)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
+ faraday (2.7.4)
16
+ faraday-net_http (>= 2.0, < 3.1)
17
+ ruby2_keywords (>= 0.0.4)
18
+ faraday-net_http (3.0.2)
19
+ google-protobuf (3.22.0-x86_64-darwin)
20
+ json (2.6.3)
21
+ parallel (1.22.1)
22
+ parser (3.2.1.0)
23
+ ast (~> 2.4.1)
24
+ rack (3.0.4.1)
25
+ rainbow (3.1.1)
26
+ regexp_parser (2.7.0)
27
+ rexml (3.2.5)
28
+ rspec (3.12.0)
29
+ rspec-core (~> 3.12.0)
30
+ rspec-expectations (~> 3.12.0)
31
+ rspec-mocks (~> 3.12.0)
32
+ rspec-core (3.12.1)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-expectations (3.12.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-mocks (3.12.3)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-support (3.12.0)
41
+ rubocop (1.46.0)
42
+ json (~> 2.3)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.2.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml (>= 3.2.5, < 4.0)
48
+ rubocop-ast (>= 1.26.0, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 2.4.0, < 3.0)
51
+ rubocop-ast (1.26.0)
52
+ parser (>= 3.2.1.0)
53
+ ruby-progressbar (1.11.0)
54
+ ruby2_keywords (0.0.5)
55
+ simplecov (0.22.0)
56
+ docile (~> 1.1)
57
+ simplecov-html (~> 0.11)
58
+ simplecov_json_formatter (~> 0.1)
59
+ simplecov-html (0.12.3)
60
+ simplecov_json_formatter (0.1.4)
61
+ twirp (1.10.0)
62
+ faraday (< 3)
63
+ google-protobuf (~> 3.0, >= 3.7.0)
64
+ unicode-display_width (2.4.2)
65
+
66
+ PLATFORMS
67
+ x86_64-darwin-21
68
+
69
+ DEPENDENCIES
70
+ byebug
71
+ rack
72
+ rspec
73
+ rubocop-twirp!
74
+ simplecov
75
+
76
+ BUNDLED WITH
77
+ 2.4.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Daniel Pepper
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ rubocop-twirp
2
+ ======
3
+ ![Gem](https://img.shields.io/gem/dt/rubocop-twirp?style=plastic)
4
+ [![codecov](https://codecov.io/gh/dpep/rubocop-twirp/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/rubocop-twirp)
5
+
6
+ ...
7
+
8
+ [RuboCop](https://github.com/bbatsov/rubocop)
9
+
10
+
11
+
12
+ ```ruby
13
+ gem install rubocop-twirp
14
+
15
+ # or add to your Gemfile
16
+ gem "rubocop-twirp", require: false
17
+ ```
18
+
19
+ Add this to your .rubocop.yml:
20
+ ```
21
+ require: rubocop-twirp
22
+ ```
23
+
24
+ Scan for issues
25
+ ```
26
+ rubocop -r rubocop-twirp --only Twirp
27
+ ```
28
+
29
+ ----
30
+ ## Contributing
31
+
32
+ Yes please :)
33
+
34
+ 1. Fork it
35
+ 1. Create your feature branch (`git checkout -b my-feature`)
36
+ 1. Ensure the tests pass (`bundle exec rspec`)
37
+ 1. Commit your changes (`git commit -am 'awesome new feature'`)
38
+ 1. Push your branch (`git push origin my-feature`)
39
+ 1. Create a Pull Request
@@ -0,0 +1,7 @@
1
+ Twirp:
2
+ Enabled: true
3
+
4
+ Twirp/DeprecatedArguments:
5
+ Description: 'Use keyword args for `Twirp::ClientResp.new`'
6
+ Enabled: true
7
+ VersionAdded: '0.1'
@@ -0,0 +1,61 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Twirp
4
+ # Checks that Twirp::ClientResp uses keyword arguments
5
+ # instead of positional arguments.
6
+ #
7
+ # @example
8
+ # # bad
9
+ # Twirp::ClientResp.new(data, error)
10
+ #
11
+ # # good
12
+ # Twirp::ClientResp.new(data: data, error: error)
13
+ #
14
+ class DeprecatedArguments < Base
15
+ RESTRICT_ON_SEND = [:new].freeze
16
+ POSITIONAL_ARGS = [:data, :error].freeze
17
+
18
+ def_node_matcher :pos_args?, <<~PATTERN
19
+ (send (const (const { nil? cbase } :Twirp) :ClientResp) :new $!hash_type?+)
20
+ PATTERN
21
+
22
+
23
+ include RangeHelp
24
+ extend AutoCorrector
25
+
26
+ MSG = "Positional args are deprecated, use keyword args: " \
27
+ "`%<class_name>s.%<method_name>s(%<kwargs>s)`"
28
+
29
+ def on_send(node)
30
+ # kwargs were introduced in Twirp v1.10
31
+ return unless Gem::Version.new(::Twirp::VERSION) >= Gem::Version.new("1.10")
32
+
33
+ return unless pos_args?(node)
34
+
35
+ kwargs = POSITIONAL_ARGS.map.with_index do |arg, index|
36
+ "#{arg}: #{node.arguments[index].source}"
37
+ end.join(", ")
38
+
39
+ message = format(
40
+ MSG,
41
+ class_name: node.receiver.source,
42
+ kwargs: kwargs,
43
+ method_name: node.method_name,
44
+ )
45
+
46
+ offense_range = range_between(
47
+ node.arguments.first.source_range.begin_pos,
48
+ node.arguments.last.source_range.end_pos
49
+ )
50
+
51
+ add_offense(
52
+ offense_range,
53
+ message: message,
54
+ ) do |corrector|
55
+ corrector.replace(offense_range, kwargs)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module Twirp
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "rubocop"
2
+ require "rubocop/twirp/version"
3
+ require "twirp"
4
+
5
+ # load cops
6
+ Dir["./cop/twirp/**/*.rb", base: __dir__].each { |f| require_relative f }
@@ -0,0 +1 @@
1
+ require "rubocop/twirp"
@@ -0,0 +1,21 @@
1
+ require_relative "lib/rubocop/twirp/version"
2
+ package = RuboCop::Twirp
3
+
4
+
5
+ Gem::Specification.new do |s|
6
+ s.authors = ["Daniel Pepper"]
7
+ s.description = "..."
8
+ s.files = `git ls-files * ':!:spec'`.split("\n")
9
+ s.homepage = "https://github.com/dpep/rubocop-twirp"
10
+ s.license = "MIT"
11
+ s.name = File.basename(__FILE__).split(".")[0]
12
+ s.summary = package.to_s
13
+ s.version = package.const_get "VERSION"
14
+
15
+ s.add_dependency "rubocop", ">= 1"
16
+ s.add_dependency "twirp", ">= 1"
17
+
18
+ s.add_development_dependency "byebug"
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency "simplecov"
21
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-twirp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Pepper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-26 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: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: twirp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: "..."
84
+ email:
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - CHANGELOG.md
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.md
94
+ - config/default.yml
95
+ - lib/rubocop-twirp.rb
96
+ - lib/rubocop/cop/twirp/deprecated_arguments.rb
97
+ - lib/rubocop/twirp.rb
98
+ - lib/rubocop/twirp/version.rb
99
+ - rubocop-twirp.gemspec
100
+ homepage: https://github.com/dpep/rubocop-twirp
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.3.7
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: RuboCop::Twirp
123
+ test_files: []