empty_example_cop 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: e0be7d5ab101cb6b152cab80a9507240fbf5b59dea8434269c96d4046c9c1161
4
+ data.tar.gz: 0bde0aed2a517db144d47d6d234c5600d3d44d5c9a703771d69238675b54cef1
5
+ SHA512:
6
+ metadata.gz: 07e31362cadd4a8deb31cbb3fa731c21aeeb47e62d48c91c25943c3ec257d65603de5f033d32df4da8d9c03019dc2bb6fabba0b8cb8cc4ed9e81cd3ebeb89ea5
7
+ data.tar.gz: c361a76eb0fefaa8c0dad94d2a78d07c88e034c84181320b226b0d8308c4d70be4c52b677d626a541cc34af3e0f923b564511e13986c9c61bab52f5c7320e960
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0] - 2021-12-06
2
+
3
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
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
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
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
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at unright@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
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.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ 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.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in empty_example_cop.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 makicamel
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,59 @@
1
+ # EmptyExampleCop
2
+
3
+ EmptyExampleCop is a tiny custom cop to detect empty examples which don't include any expectations.
4
+
5
+ ```ruby
6
+ # bad
7
+ describe Bacon do
8
+ let(:bacon) { Bacon.new(chunkiness) }
9
+ let(:chunkiness) { true }
10
+
11
+ it 'is chunky' do
12
+ bacon.chunky?
13
+ end
14
+ end
15
+
16
+ # good
17
+ describe Bacon do
18
+ let(:bacon) { Bacon.new(chunkiness) }
19
+ let(:chunkiness) { true }
20
+
21
+ it 'is chunky' do
22
+ expect(bacon.chunky?).to be_truthy
23
+ end
24
+ end
25
+ ```
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'empty_example_cop', require: false
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Add `empty_example_cop` to your `.rubocop.yml`:
38
+
39
+ ```yml
40
+ require:
41
+ - rubocop-rspec
42
+ - empty_example_cop
43
+ ```
44
+
45
+ ```console
46
+ bundle exec rubocop <options>
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/makicamel/empty_example_cop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/makicamel/empty_example_cop/blob/master/CODE_OF_CONDUCT.md).
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the EmptyExampleCop project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/makicamel/empty_example_cop/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
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
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "empty_example_cop"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,3 @@
1
+ RSpec/EmptyExample:
2
+ Description: Detect empty examples which don't include any expectations.
3
+ Enabled: true
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/empty_example_cop/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "empty_example_cop"
7
+ spec.version = EmptyExampleCop::VERSION
8
+ spec.authors = ["makicamel"]
9
+ spec.email = ["unright@gmail.com"]
10
+
11
+ spec.summary = "A tiny custom cop to detect empty example."
12
+ spec.description = "A tiny custom cop to detect empty example."
13
+ spec.homepage = "https://github.com/makicamel/empty_example_cop"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/makicamel/empty_example_cop/blob/main/CHANGELOG.md"
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(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "rubocop"
31
+ spec.add_dependency "rubocop-rspec"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
@@ -0,0 +1,23 @@
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 and
4
+ # https://github.com/rubocop/rubocop-extension-generator/blob/master/lib/rubocop/extension/generator/generator.rb
5
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
6
+ module RuboCop
7
+ module EmptyExampleCop
8
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
9
+ # bit of our configuration.
10
+ module Inject
11
+ def self.defaults!
12
+ project_root = Pathname.new(__dir__).parent.parent.expand_path.freeze
13
+ config_default = project_root.join('config', 'default.yml').freeze
14
+ path = config_default.to_s
15
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
16
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
17
+ puts "configuration from #{path}" if ConfigLoader.debug?
18
+ config = ConfigLoader.merge_with_default(config, path)
19
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EmptyExampleCop
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+ require_relative './empty_example_cop/version'
5
+ require_relative './empty_example_cop/inject'
6
+
7
+ RuboCop::EmptyExampleCop::Inject.defaults!
8
+
9
+ require_relative './rubocop/cop/rspec/empty_example_cops'
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ class EmptyExample < Base
7
+ # Checks if an example does not include any expectations.
8
+ #
9
+ # @example usage
10
+ #
11
+ # # bad
12
+ # describe Bacon do
13
+ # let(:bacon) { Bacon.new(chunkiness) }
14
+ # let(:chunkiness) { true }
15
+ #
16
+ # it 'is chunky' do
17
+ # bacon.chunky?
18
+ # end
19
+ # end
20
+ #
21
+ # # good
22
+ # describe Bacon do
23
+ # let(:bacon) { Bacon.new(chunkiness) }
24
+ # let(:chunkiness) { true }
25
+ #
26
+ # it 'is chunky' do
27
+ # expect(bacon.chunky?).to be_truthy
28
+ # end
29
+ # end
30
+ MSG = 'Empty example detected.'
31
+
32
+ def_node_matcher :it_description?, <<-PATTERN
33
+ (block
34
+ (send nil? :it ...) ...)
35
+ PATTERN
36
+
37
+ def_node_matcher :expect?, <<-PATTERN
38
+ (send nil? {:expect :is_expected :expect_any_instance_of} ...)
39
+ PATTERN
40
+
41
+ def_node_matcher :should?, <<-PATTERN
42
+ (send nil? {:should :should_not} ...)
43
+ PATTERN
44
+
45
+ def_node_matcher :assert?, <<-PATTERN
46
+ (send nil? {:assert_response} ...)
47
+ PATTERN
48
+
49
+ def on_block(node)
50
+ return unless it_description?(node)
51
+
52
+ unless example_present?(node)
53
+ add_offense(node, message: MSG)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def example_present?(node)
60
+ if expect?(node) || should?(node) || assert?(node)
61
+ true
62
+ elsif node.nil?
63
+ false
64
+ elsif RuboCop::AST::Node === node && node.children.size > 0
65
+ node.children.any? { |child| example_present?(child) }
66
+ else # something not expectation
67
+ false
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: empty_example_cop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - makicamel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-06 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
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A tiny custom cop to detect empty example.
42
+ email:
43
+ - unright@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - config/default.yml
57
+ - empty_example_cop.gemspec
58
+ - lib/empty_example_cop.rb
59
+ - lib/empty_example_cop/inject.rb
60
+ - lib/empty_example_cop/version.rb
61
+ - lib/rubocop/cop/rspec/empty_example_cops.rb
62
+ homepage: https://github.com/makicamel/empty_example_cop
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://github.com/makicamel/empty_example_cop
67
+ source_code_uri: https://github.com/makicamel/empty_example_cop
68
+ changelog_uri: https://github.com/makicamel/empty_example_cop/blob/main/CHANGELOG.md
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.2.32
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A tiny custom cop to detect empty example.
88
+ test_files: []