rubocop-grape 0.1.0

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: c384295c459e02395aee22afb61dce8fe77a11603b72c57188ea65761bc981c2
4
+ data.tar.gz: ff1aff8360ad4014f513af0a5312e5647f866e602e513580509854577dff21be
5
+ SHA512:
6
+ metadata.gz: 4f8488742a3f79cfdd660154d4ed29db6f8f6797356f945d7761815a53bda297f459fd8d5a77b81928814da124679cc4c38232b089ff5d0a95304d1db3a1bb58
7
+ data.tar.gz: 17561aee4d974b9b8642a0ca6e40be8c289e4b6ac942971fe61a022daa69224970f2bff7677be52788332e127a5cdabd4b4d5b07a17c9ac8e21ca64ce59b80e2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Akito Hikasa
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,35 @@
1
+ # RuboCop::Grape
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/grape`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rubocop-grape'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rubocop-grape
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop-grape.
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rubocop-grape'
6
+
7
+ require 'irb'
8
+ ARGV.clear
9
+
10
+ IRB.start(__FILE__)
@@ -0,0 +1,4 @@
1
+ Grape/RouteParamType:
2
+ Enabled: true
3
+ Safe: false
4
+ VersionAdded: '0.1'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Grape
6
+ # Checks whether type is specified at points where `Grape::API#route_param` is called.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # route_param :id
12
+ #
13
+ # # good
14
+ # route_param :id, type: Integer
15
+ # route_param :filename, type: String
16
+ # route_param :status, type: String, desc: 'Resource Status'
17
+ #
18
+ class RouteParamType < Base
19
+ MSG = 'Define Parameter Type'
20
+
21
+ def_node_matcher :route_param?, <<~RUBY
22
+ (send _ :route_param ({sym str} _) ...)
23
+ RUBY
24
+
25
+ def_node_matcher :include_key_type?, <<~RUBY
26
+ (pair (sym :type) _)
27
+ RUBY
28
+
29
+ def on_send(node)
30
+ return unless route_param?(node)
31
+
32
+ options = node.children.last.children
33
+ return if options.any? { |clild_node| include_key_type?(clild_node) }
34
+
35
+ add_offense(node)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'grape/route_param_type'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Grape
5
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
+ # bit of our configuration.
7
+ module Inject
8
+ def self.defaults!
9
+ path = CONFIG_DEFAULT.to_s
10
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
11
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
+ puts "configuration from #{path}" if ConfigLoader.debug?
13
+ config = ConfigLoader.merge_with_default(config, path)
14
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Grape
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'grape/version'
4
+
5
+ module RuboCop
6
+ # RuboCop Grape project namespace
7
+ module Grape
8
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
9
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
10
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
11
+
12
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/grape'
6
+ require_relative 'rubocop/grape/version'
7
+ require_relative 'rubocop/grape/inject'
8
+
9
+ RuboCop::Grape::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/grape_cops'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-grape
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akito Hikasa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-21 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.7.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.7.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ description: |
34
+ Automatic Grape code style checking tool.
35
+ A RuboCop extension focused on enforcing Grape best practices and coding conventions.
36
+ email:
37
+ - wetsand.wfs@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - LICENSE.txt
43
+ - README.md
44
+ - bin/console
45
+ - config/default.yml
46
+ - lib/rubocop-grape.rb
47
+ - lib/rubocop/cop/grape/route_param_type.rb
48
+ - lib/rubocop/cop/grape_cops.rb
49
+ - lib/rubocop/grape.rb
50
+ - lib/rubocop/grape/inject.rb
51
+ - lib/rubocop/grape/version.rb
52
+ homepage: https://github.com/kakubin/rubocop-grape
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ allowed_push_host: https://rubygems.org
57
+ homepage_uri: https://github.com/kakubin/rubocop-grape
58
+ source_code_uri: https://github.com/kakubin/rubocop-grape
59
+ changelog_uri: https://github.com/kakubin/rubocop-grape/blob/master/CHANGELOG.md
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.6.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.3.7
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Automatice Grape code style checking tool.
79
+ test_files: []