workitcop 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 105f11e7651eb4303dfb37311cb725b555d55f6e67699a61b59e948d2a7a4b2b
4
- data.tar.gz: 93a36d5502242fdde058da0b9edc6b9746a5b7d5cd9ef1deaab4cb0590ed47ee
3
+ metadata.gz: 27336368b30a080fc58a6053182931a6abb0addbf3481fc19266a008ab574c3a
4
+ data.tar.gz: 23cbb18bc27d25f68003200c0eb505efec7200f45b4634fe32d9e69a2b72cdf5
5
5
  SHA512:
6
- metadata.gz: 519e92ed299bd9a0d72d7cd56b30d4b8eaeb959122d84d5d74d6b99cac48d620b587230b5ee0b2b90903a4a9456fca11628b7270371b5892809c23392433e6d2
7
- data.tar.gz: 76ce34040930118778dc28a5c53661d758b70cf0e836e8789e7ee4e532aa96a79aac5b6ff5062de55b7645b94a5a756c5bea58d8e88c675ea6e519e41112de79
6
+ metadata.gz: 9ed01c88aeabb5f4759e710555ba6566d248f800e7fc239ea0634f7a2d735acf6e5551c244fa81e810fc617438bb5094f33d344014300917e5c7afb1dec12d39
7
+ data.tar.gz: f5ff520cccd27c6d58c687b2a9bf7ab34d38c931c37dd03e6f4037831ecd56309964402301572ddd3faaab6e986fac9f3ec5e2c98488153fb9399a20beeef920
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
- ## [Unreleased]
1
+ # Change log
2
2
 
3
- ## [0.1.0] - 2022-06-17
3
+ ## Unreleased
4
+
5
+ ## 0.2.0 - 2022-11-07
6
+
7
+ - Add new `Workit/ActionArgs` cop. ([@ydah])
8
+ - Add new `Workit/NoopRescue` cop. ([@ydah])
9
+
10
+ ## 0.1.0 - 2022-07-04
4
11
 
5
12
  - Initial release
13
+
14
+ <!-- Contributors -->
15
+
16
+ [@ydah]: https://github.com/ydah
data/CODE_OF_CONDUCT.md CHANGED
@@ -10,21 +10,21 @@ We pledge to act and interact in ways that contribute to an open, welcoming, div
10
10
 
11
11
  Examples of behavior that contributes to a positive environment for our community include:
12
12
 
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
18
 
19
19
  Examples of unacceptable behavior include:
20
20
 
21
- * The use of sexualized language or imagery, and sexual attention or
21
+ - The use of sexualized language or imagery, and sexual attention or
22
22
  advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
23
+ - Trolling, insulting or derogatory comments, and personal or political attacks
24
+ - Public or private harassment
25
+ - Publishing others' private information, such as a physical or email
26
26
  address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
27
+ - Other conduct which could reasonably be considered inappropriate in a
28
28
  professional setting
29
29
 
30
30
  ## Enforcement Responsibilities
@@ -74,11 +74,11 @@ Community leaders will follow these Community Impact Guidelines in determining t
74
74
  ## Attribution
75
75
 
76
76
  This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
77
+ available at <https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.
78
78
 
79
79
  Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
80
 
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
81
  For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
82
+ <https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.
83
+
84
+ [homepage]: https://www.contributor-covenant.org
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Workitcop
1
+ # Workitcop [![Gem Version](https://badge.fury.io/rb/workitcop.svg)](https://badge.fury.io/rb/workitcop) [![CI](https://github.com/ydah/workitcop/actions/workflows/ci.yml/badge.svg)](https://github.com/ydah/workitcop/actions/workflows/ci.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/77fd345a1f0e8ab706ed/maintainability)](https://codeclimate.com/github/ydah/workitcop/maintainability)
2
2
 
3
3
  Custom cops for [RuboCop](https://github.com/rubocop/rubocop).
4
4
 
@@ -6,20 +6,39 @@ Custom cops for [RuboCop](https://github.com/rubocop/rubocop).
6
6
 
7
7
  Install the gem and add to the application's Gemfile by executing:
8
8
 
9
- $ bundle add workitcop
9
+ ```command
10
+ bundle add workitcop
11
+ ```
10
12
 
11
13
  If bundler is not being used to manage dependencies, install the gem by executing:
12
14
 
13
- $ gem install workitcop
15
+ ```command
16
+ gem install workitcop
17
+ ```
14
18
 
15
19
  ## Usage
16
20
 
21
+ You need to tell RuboCop to load the Workitcop extension.
22
+
23
+ ### RuboCop configuration file
24
+
25
+ Put this into your `.rubocop.yml`.
26
+
27
+ ```yaml
28
+ require: workitcop
29
+ ```
30
+
31
+ Alternatively, use the following array notation when specifying multiple extensions.
32
+
17
33
  ```yaml
18
- # .rubocop.yml
19
34
  require:
35
+ - rubocop-other-extension
20
36
  - workitcop
21
37
  ```
22
38
 
39
+ Now you can run `rubocop` and it will automatically load the Workitcop
40
+ cops together with the standard cops.
41
+
23
42
  ## License
24
43
 
25
44
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/config/default.yml CHANGED
@@ -1,3 +1,28 @@
1
+ ---
2
+ inherit_mode:
3
+ merge:
4
+ - Exclude
5
+
6
+ Workit/ActionArgs:
7
+ Description: |
8
+ Check for controller action must be using `action_args`.
9
+ Enabled: pending
10
+ VersionAdded: '0.2'
11
+ Include:
12
+ - 'controllers/**/*'
13
+ ControllerMethods:
14
+ - index
15
+ - show
16
+ - create
17
+ - update
18
+ - cancel
19
+ - destroy
20
+
21
+ Workit/NoopRescue:
22
+ Description: 'Check for suppress or ignore checked exception.'
23
+ Enabled: false
24
+ VersionAdded: '0.2'
25
+
1
26
  Workit/RestrictOnSend:
2
27
  Description: |
3
28
  Check for `RESTRICT_ON_SEND` is defined if `on_send` or `after_send` are defined.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Workit
6
+ # Check for controller action must be using `action_args`.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # class FooController
11
+ # def index
12
+ # # ...
13
+ # end
14
+ # end
15
+ #
16
+ # # good
17
+ # class FooController
18
+ # def index(foo:)
19
+ # # ...
20
+ # end
21
+ #
22
+ # def not_action
23
+ # # ...
24
+ # end
25
+ # end
26
+ #
27
+ class ActionArgs < Base
28
+ MSG = "Consider using `action_args`."
29
+
30
+ def on_def(node)
31
+ add_offense(node) if !node.arguments? && controller_methods.include?(node.method_name.to_s)
32
+ end
33
+
34
+ private
35
+
36
+ def controller_methods
37
+ cop_config.fetch("ControllerMethods", [])
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Workit
6
+ # Check for suppress or ignore checked exception.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # foo rescue nil
11
+ #
12
+ # # bad
13
+ # def foo
14
+ # do_something
15
+ # rescue StandardError => e
16
+ # # no op
17
+ # end
18
+ #
19
+ # # good
20
+ # foo rescue do_something
21
+ #
22
+ # # good
23
+ # def foo
24
+ # do_something
25
+ # rescue StandardError => e
26
+ # do_something
27
+ # end
28
+ #
29
+ class NoopRescue < Base
30
+ MSG = "Don't suppress or ignore checked exception."
31
+
32
+ # @!method send_node_include?(node)
33
+ def_node_search :send_node_include?, <<~PATTERN
34
+ (send ...)
35
+ PATTERN
36
+
37
+ def on_resbody(node)
38
+ add_offense(node) if noop?(node.body)
39
+ end
40
+
41
+ private
42
+
43
+ def noop?(node)
44
+ return true unless node
45
+
46
+ !send_node_include?(node)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Workitcop
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/workitcop.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require_relative "workitcop/inject"
4
4
  require_relative "workitcop/version"
5
5
 
6
+ require_relative "rubocop/cop/workit/action_args"
7
+ require_relative "rubocop/cop/workit/noop_rescue"
6
8
  require_relative "rubocop/cop/workit/restrict_on_send"
7
9
 
8
10
  module Workitcop
metadata CHANGED
@@ -1,51 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workitcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ydah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-04 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.27'
19
+ version: '1.31'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.27'
26
+ version: '1.31'
27
27
  description:
28
28
  email:
29
29
  - t.yudai92@gmail.com
30
30
  executables: []
31
31
  extensions: []
32
- extra_rdoc_files: []
32
+ extra_rdoc_files:
33
+ - LICENSE.txt
34
+ - README.md
33
35
  files:
34
- - ".rspec"
35
- - ".rubocop.yml"
36
36
  - CHANGELOG.md
37
37
  - CODE_OF_CONDUCT.md
38
- - Gemfile
39
38
  - LICENSE.txt
40
39
  - README.md
41
- - Rakefile
42
40
  - config/default.yml
41
+ - lib/rubocop/cop/workit/action_args.rb
42
+ - lib/rubocop/cop/workit/noop_rescue.rb
43
43
  - lib/rubocop/cop/workit/restrict_on_send.rb
44
44
  - lib/workitcop.rb
45
45
  - lib/workitcop/inject.rb
46
46
  - lib/workitcop/version.rb
47
- - sig/workitcop.rbs
48
- - workitcop.gemspec
49
47
  homepage: https://github.com/ydah/workitcop
50
48
  licenses:
51
49
  - MIT
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,21 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
3
- SuggestExtensions: false
4
- NewCops: enable
5
-
6
- Layout/LineLength:
7
- Enabled: false
8
-
9
- Metrics:
10
- Enabled: false
11
-
12
- Style/Documentation:
13
- Enabled: false
14
-
15
- Style/StringLiterals:
16
- Enabled: true
17
- EnforcedStyle: double_quotes
18
-
19
- Style/StringLiteralsInInterpolation:
20
- Enabled: true
21
- EnforcedStyle: double_quotes
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec
6
-
7
- gem "rake", "~> 13.0"
8
- gem "rspec", "~> 3.0"
9
- gem "rubocop", "~> 1.21"
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
data/sig/workitcop.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Workitcop
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
data/workitcop.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/workitcop/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "workitcop"
7
- spec.version = Workitcop::VERSION
8
- spec.authors = ["ydah"]
9
- spec.email = ["t.yudai92@gmail.com"]
10
-
11
- spec.summary = "Custom cops for `RuboCop`."
12
- spec.homepage = "https://github.com/ydah/workitcop"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
18
- spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
- spec.metadata["rubygems_mfa_required"] = "true"
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(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
- end
27
- end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
31
- spec.add_runtime_dependency "rubocop", ">= 1.27"
32
- end