rubocop-committee 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: 85d35285a988e66ac1d5976d7ac3bf7ac7f207015d1fcd352eed7b8bdac60625
4
+ data.tar.gz: 6c2d9fa4b9d4d28bcbb596446e750a4befd6f0674301d1f03a1f5a604a5679b7
5
+ SHA512:
6
+ metadata.gz: 2af73171d6c98048f001c48be91ebcf2a7c92c1dce94c1af6fb07cb91e1ace600f52d6787c3792dd12929a93e934fa1ac22f3e2db8c91831d21f1e9f65706436
7
+ data.tar.gz: 2fcb0125bdece926274d5b9cfab219497126bf3dbc599c386daa8ed3e02069c3a73f710c2de2d0efc98c2d24c213005b822de4c36c54a5181c9ec402a0fe96dc
data/.codespellignore ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ require:
2
+ - rubocop/cop/internal_affairs
3
+ - rubocop-performance
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+
7
+ AllCops:
8
+ NewCops: enable
9
+ TargetRubyVersion: 2.6
10
+ SuggestExtensions: false
11
+
12
+ Layout/LineLength:
13
+ Enabled: false
14
+
15
+ Metrics:
16
+ Enabled: false
17
+
18
+ Naming/FileName:
19
+ Exclude:
20
+ - lib/rubocop-committee.rb
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/StringLiterals:
26
+ EnforcedStyle: double_quotes
27
+
28
+ Style/StringLiteralsInInterpolation:
29
+ EnforcedStyle: double_quotes
30
+
31
+ RSpec/ExampleLength:
32
+ Enabled: false
data/.yamllint.yml ADDED
@@ -0,0 +1,9 @@
1
+ extends: default
2
+
3
+ rules:
4
+ comments:
5
+ min-spaces-from-content: 1
6
+ document-start: disable
7
+ line-length: disable
8
+ truthy:
9
+ check-keys: false
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ --hide-void-return
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Unreleased
2
+
3
+ ## 0.1.0 - 2022-12-29
4
+
5
+ - Initial release ([@ydah])
6
+
7
+ <!-- Contributors -->
8
+
9
+ [@ydah]: https://github.com/ydah
@@ -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 13041216+ydah@users.noreply.github.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
+ For answers to common questions about this code of conduct, see the FAQ at
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/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem 'bump', require: false
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "rubocop-performance"
11
+ gem "rubocop-rake"
12
+ gem "rubocop-rspec"
13
+ gem "yard"
data/MIT-LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Yudai Takada
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,86 @@
1
+ # RuboCop Committee
2
+
3
+ ![GitHub top language](https://img.shields.io/github/languages/top/ydah/rubocop-committee?color=39ff14) [![Gem Version](https://badge.fury.io/rb/rubocop-committee.svg)](https://badge.fury.io/rb/rubocop-committee) [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop) [![CI](https://github.com/ydah/rubocop-committee/actions/workflows/ci.yml/badge.svg)](https://github.com/ydah/rubocop-committee/actions/workflows/ci.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/a1b121696e9d1b425406/maintainability)](https://codeclimate.com/github/ydah/rubocop-committee/maintainability)
4
+
5
+ Committee-specific analysis for your projects, as an extension to
6
+ [RuboCop](https://github.com/rubocop/rubocop).
7
+
8
+ ## Installation
9
+
10
+ Just install the `rubocop-committee` gem
11
+
12
+ ```bash
13
+ gem install rubocop-committee
14
+ ```
15
+
16
+ or if you use bundler put this in your `Gemfile`
17
+
18
+ ```
19
+ gem 'rubocop-committee', require: false
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ You need to tell RuboCop to load the Committee extension. There are two
25
+ ways to do this:
26
+
27
+ ### RuboCop configuration file
28
+
29
+ Put this into your `.rubocop.yml`.
30
+
31
+ ```yaml
32
+ require: rubocop-committee
33
+ ```
34
+
35
+ Alternatively, use the following array notation when specifying multiple extensions.
36
+
37
+ ```yaml
38
+ require:
39
+ - rubocop-other-extension
40
+ - rubocop-committee
41
+ ```
42
+
43
+ Now you can run `rubocop` and it will automatically load the RuboCop Committee
44
+ cops together with the standard cops.
45
+
46
+ ### Command line
47
+
48
+ ```bash
49
+ rubocop --require rubocop-committee
50
+ ```
51
+
52
+ ### Rake task
53
+
54
+ ```ruby
55
+ RuboCop::RakeTask.new do |task|
56
+ task.requires << 'rubocop-committee'
57
+ end
58
+ ```
59
+
60
+ ## Documentation
61
+
62
+ You can read more about RuboCop Committee in its official manual.
63
+
64
+ ## The Cops
65
+
66
+ All cops are located under
67
+ [`lib/rubocop/cop/committee`](lib/rubocop/cop/committee), and contain
68
+ examples/documentation.
69
+
70
+ In your `.rubocop.yml`, you may treat the Committee cops just like any other
71
+ cop. For example:
72
+
73
+ ```yaml
74
+ Committee/FilePath:
75
+ Exclude:
76
+ - spec/my_poorly_named_spec_file.rb
77
+ ```
78
+
79
+ ## Contributing
80
+
81
+ Checkout the [contribution guidelines](.github/CONTRIBUTING.md).
82
+
83
+ ## License
84
+
85
+ `rubocop-committee` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
86
+ the full text.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
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
+ Dir["tasks/**/*.rake"].each { |t| load t }
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[spec rubocop]
@@ -0,0 +1,19 @@
1
+ ---
2
+ inherit_mode:
3
+ merge:
4
+ - Exclude
5
+
6
+ Committee:
7
+ Enabled: true
8
+
9
+ Committee/UnspecifiedExpectedStatus:
10
+ Description: |
11
+ Check if the status code is specified as an argument to the method of the Committee
12
+ where the expected response status code is required.
13
+ Enabled: pending
14
+ VersionAdded: '0.1'
15
+
16
+ Committee/RedundantResponseStatusAssertions:
17
+ Description: Check for validation of redundant response HTTP status codes.
18
+ Enabled: pending
19
+ VersionAdded: '0.1'
@@ -0,0 +1,6 @@
1
+ * xref:index.adoc[Home]
2
+ * xref:installation.adoc[Installation]
3
+ * xref:usage.adoc[Usage]
4
+ * xref:cops.adoc[Cops]
5
+ * Cops Documentation
6
+ ** xref:cops_committee.adoc[Committee]
@@ -0,0 +1,8 @@
1
+ // START_COP_LIST
2
+
3
+ === Department xref:cops_committee.adoc[Committee]
4
+
5
+ * xref:cops_committee.adoc#committeeredundantresponsestatusassertions[Committee/RedundantResponseStatusAssertions]
6
+ * xref:cops_committee.adoc#committeeunspecifiedexpectedstatus[Committee/UnspecifiedExpectedStatus]
7
+
8
+ // END_COP_LIST
@@ -0,0 +1,66 @@
1
+ = Committee
2
+
3
+ == Committee/RedundantResponseStatusAssertions
4
+
5
+ |===
6
+ | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
7
+
8
+ | Pending
9
+ | Yes
10
+ | Yes
11
+ | 0.1
12
+ | -
13
+ |===
14
+
15
+ Check for validation of redundant response HTTP status codes.
16
+
17
+ === Examples
18
+
19
+ [source,ruby]
20
+ ----
21
+ # bad
22
+ it 'something' do
23
+ subject
24
+ expect(response).to have_http_status 400
25
+ assert_schema_conform(400)
26
+ end
27
+
28
+ # good
29
+ it 'something' do
30
+ subject
31
+ assert_schema_conform(400)
32
+ end
33
+ ----
34
+
35
+ == Committee/UnspecifiedExpectedStatus
36
+
37
+ |===
38
+ | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
39
+
40
+ | Pending
41
+ | Yes
42
+ | Yes
43
+ | 0.1
44
+ | -
45
+ |===
46
+
47
+ Check if the status code is specified as an argument to the method of the Committee
48
+ where the expected response status code is required.
49
+
50
+ === Examples
51
+
52
+ [source,ruby]
53
+ ----
54
+ # bad
55
+ it 'something' do
56
+ subject
57
+ expect(response).to have_http_status 400
58
+ assert_schema_conform
59
+ end
60
+
61
+ # good
62
+ it 'something' do
63
+ subject
64
+ assert_schema_conform(400)
65
+ end
66
+ ----
@@ -0,0 +1,15 @@
1
+ = RuboCop Committee
2
+
3
+ Committee-specific analysis for your projects, as an extension to
4
+ https://github.com/rubocop/rubocop[RuboCop].
5
+
6
+ RuboCop Committee follows the https://docs.rubocop.org/rubocop/versioning.html[RuboCop versioning guide].
7
+ In a nutshell, between major versions new cops are introduced in a special `pending` status.
8
+ That means that they won’t be run unless explicitly told otherwise.
9
+ RuboCop will warn on start that certain cops are neither explicitly enabled and disabled.
10
+ On a major version release, all `pending` cops are enabled.
11
+
12
+ == Project Goals
13
+
14
+ * Enforce the style of the test code to be best practice when using committee
15
+ * Simplify the process of adopting new Committee functionality
@@ -0,0 +1,15 @@
1
+ = Installation
2
+
3
+ Just install the `rubocop-committee` gem
4
+
5
+ [source,bash]
6
+ ----
7
+ gem install rubocop-committee
8
+ ----
9
+
10
+ or if you use bundler put this in your `Gemfile`
11
+
12
+ [source,ruby]
13
+ ----
14
+ gem 'rubocop-committee'
15
+ ----
@@ -0,0 +1,37 @@
1
+ = Usage
2
+
3
+ You need to tell RuboCop to load the RuboCop Committee extension.
4
+ There are some ways to do this:
5
+
6
+ == RuboCop configuration file
7
+
8
+ Put this into your `.rubocop.yml`:
9
+
10
+ ----
11
+ require: rubocop-committee
12
+ ----
13
+
14
+ or, if you are using several extensions:
15
+
16
+ ----
17
+ require:
18
+ - rubocop-committee
19
+ - rubocop-rspec
20
+ ----
21
+
22
+ Now you can run `rubocop` and it will automatically load the RuboCop Committee
23
+ cops together with the standard cops.
24
+
25
+ [source,bash]
26
+ ----
27
+ $ rubocop --require rubocop-committee
28
+ ----
29
+
30
+ == Rake task
31
+
32
+ [source,ruby]
33
+ ----
34
+ RuboCop::RakeTask.new do |task|
35
+ task.requires << 'rubocop-committee'
36
+ end
37
+ ----
@@ -0,0 +1,5 @@
1
+ name: rubocop-committee
2
+ title: RuboCop Committee
3
+ version: "0.1.0"
4
+ nav:
5
+ - modules/ROOT/nav.adoc
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "rubocop-rspec"
5
+
6
+ module RuboCop
7
+ module Committee
8
+ module Inject
9
+ def self.defaults!
10
+ path = CONFIG_DEFAULT.to_s
11
+ hash = ::RuboCop::ConfigLoader.send(:load_yaml_configuration, path)
12
+ config = ::RuboCop::Config.new(hash, path).tap(&:make_excludes_absolute)
13
+ puts "configuration from #{path}" if ::RuboCop::ConfigLoader.debug?
14
+ config = ::RuboCop::ConfigLoader.merge_with_default(config, path)
15
+ ::RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Committee
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Committee
6
+ # Check for validation of redundant response HTTP status codes.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # it 'something' do
11
+ # subject
12
+ # expect(response).to have_http_status 400
13
+ # assert_schema_conform(400)
14
+ # end
15
+ #
16
+ # # good
17
+ # it 'something' do
18
+ # subject
19
+ # assert_schema_conform(400)
20
+ # end
21
+ #
22
+ class RedundantResponseStatusAssertions < Base
23
+ include RangeHelp
24
+ extend AutoCorrector
25
+
26
+ MSG = "Remove redundant HTTP response status code validation."
27
+ RESTRICT_ON_SEND = %i[assert_schema_conform assert_response_schema_confirm].freeze
28
+
29
+ # @!method have_http_status(node)
30
+ def_node_search :have_http_status, <<~PATTERN
31
+ $(send nil? :have_http_status (:int _))
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ return if node.first_argument.nil?
36
+
37
+ have_http_status(node.parent) do |http_node|
38
+ return autocorrect(node, http_node.parent.loc.expression)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def autocorrect(_node, bad_range)
45
+ add_offense(bad_range) do |corrector|
46
+ corrector.remove(range_by_whole_lines(bad_range, include_final_newline: true))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Committee
6
+ # Check if the status code is specified as an argument to the method of the Committee
7
+ # where the expected response status code is required.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # it 'something' do
12
+ # subject
13
+ # expect(response).to have_http_status 400
14
+ # assert_schema_conform
15
+ # end
16
+ #
17
+ # # good
18
+ # it 'something' do
19
+ # subject
20
+ # assert_schema_conform(400)
21
+ # end
22
+ #
23
+ class UnspecifiedExpectedStatus < Base
24
+ include RangeHelp
25
+ extend AutoCorrector
26
+
27
+ MSG = "Specify the HTTP status code of the expected response as an argument."
28
+ RESTRICT_ON_SEND = %i[assert_schema_conform assert_response_schema_confirm].freeze
29
+
30
+ # @!method have_http_status(node)
31
+ def_node_search :have_http_status, <<~PATTERN
32
+ (send nil? :have_http_status (:int $_))
33
+ PATTERN
34
+
35
+ def on_send(node)
36
+ return if node.arguments?
37
+
38
+ have_http_status(node.parent) do |status|
39
+ return autocorrect(node, status)
40
+ end
41
+
42
+ add_offense(node)
43
+ end
44
+
45
+ private
46
+
47
+ def autocorrect(node, status)
48
+ add_offense(node) do |corrector|
49
+ corrector.insert_after(node, "(#{status})")
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rubocop/committee/inject"
4
+ require_relative "rubocop/committee/version"
5
+
6
+ require_relative "rubocop/cop/committee/redundant_response_status_assertions"
7
+ require_relative "rubocop/cop/committee/unspecified_expected_status"
8
+
9
+ module RuboCop
10
+ module Committee
11
+ PROJECT_ROOT = ::Pathname.new(__dir__).parent.expand_path.freeze
12
+ CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
13
+ CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
14
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
15
+ end
16
+ end
17
+
18
+ RuboCop::Committee::Inject.defaults!
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "rubocop-committee"
5
+ require "rubocop/cops_documentation_generator"
6
+ require "yard"
7
+
8
+ YARD::Rake::YardocTask.new(:yard_for_generate_documentation) do |task|
9
+ task.files = ["lib/rubocop/cop/**/*.rb"]
10
+ task.options = ["--no-output"]
11
+ end
12
+
13
+ desc "Generate docs of all cops departments"
14
+ task generate_cops_documentation: :yard_for_generate_documentation do
15
+ generator = CopsDocumentationGenerator.new(
16
+ departments: %w[Committee]
17
+ )
18
+ generator.call
19
+ end
20
+
21
+ desc "Syntax check for the documentation comments"
22
+ task documentation_syntax_check: :yard_for_generate_documentation do
23
+ require "parser/ruby25"
24
+
25
+ ok = true
26
+ YARD::Registry.load!
27
+ cops = RuboCop::Cop::Registry.global
28
+ cops.each do |cop|
29
+ examples = YARD::Registry.all(:class).find do |code_object|
30
+ next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
31
+
32
+ break code_object.tags("example")
33
+ end
34
+
35
+ examples.to_a.each do |example|
36
+ buffer = Parser::Source::Buffer.new("<code>", 1)
37
+ buffer.source = example.text
38
+ parser = Parser::Ruby25.new(RuboCop::AST::Builder.new)
39
+ parser.diagnostics.all_errors_are_fatal = true
40
+ parser.parse(buffer)
41
+ rescue Parser::SyntaxError => e
42
+ path = example.object.file
43
+ puts "#{path}: Syntax Error in an example. #{e}"
44
+ ok = false
45
+ end
46
+ end
47
+ abort unless ok
48
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bump"
4
+
5
+ namespace :cut_release do
6
+ def update_file(path)
7
+ content = File.read(path)
8
+ File.write(path, yield(content))
9
+ end
10
+
11
+ %w[major minor patch pre].each do |release_type|
12
+ desc "Cut a new #{release_type} release and update documents."
13
+ task release_type do
14
+ run(release_type)
15
+ end
16
+ end
17
+
18
+ def version_sans_patch(version)
19
+ version.split(".").take(2).join(".")
20
+ end
21
+
22
+ # Replace `<<next>>` (and variations) with version being cut.
23
+ def update_cop_versions(version)
24
+ update_file("config/default.yml") do |default|
25
+ default.gsub(/['"]?<<\s*next\s*>>['"]?/i,
26
+ "'#{version_sans_patch(version)}'")
27
+ end
28
+ RuboCop::ConfigLoader.default_configuration = nil # invalidate loaded conf
29
+ end
30
+
31
+ def update_docs(version)
32
+ update_file("docs/antora.yml") do |antora_metadata|
33
+ antora_metadata.sub("version: ~",
34
+ "version: '#{version_sans_patch(version)}'")
35
+ end
36
+ end
37
+
38
+ def add_header_to_changelog(version)
39
+ update_file("CHANGELOG.md") do |changelog|
40
+ changelog.sub("## Master (Unreleased)\n\n",
41
+ '\0' "## #{version} (#{Time.now.strftime("%F")})\n\n")
42
+ end
43
+ end
44
+
45
+ def run(release_type)
46
+ old_version = Bump::Bump.current
47
+ Bump::Bump.run(release_type, commit: false, bundle: false, tag: false)
48
+ new_version = Bump::Bump.current
49
+
50
+ update_cop_versions(new_version)
51
+ `bundle exec rake generate_cops_documentation`
52
+ update_docs(new_version) if %w[major minor].include?(release_type)
53
+ add_header_to_changelog(new_version)
54
+
55
+ puts "Changed version from #{old_version} to #{new_version}."
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc "Generate a new cop with a template"
4
+ task :new_cop, [:cop] do |_task, args|
5
+ require "rubocop"
6
+
7
+ cop_name = args.fetch(:cop) do
8
+ warn "usage: bundle exec rake 'new_cop[Committee/Name]'"
9
+ exit!
10
+ end
11
+
12
+ generator = RuboCop::Cop::Generator.new(cop_name)
13
+
14
+ generator.write_source
15
+ generator.write_spec
16
+ generator.inject_require(root_file_path: "lib/rubocop-committee.rb")
17
+ generator.inject_config(config_file_path: "config/default.yml")
18
+
19
+ puts generator.todo
20
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-committee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ydah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-28 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
+ description: |
28
+ Automatic committee code style checking tool.
29
+ A RuboCop extension focused on enforcing committee.
30
+ email:
31
+ - t.yudai92@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".codespellignore"
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - ".yamllint.yml"
40
+ - ".yardopts"
41
+ - CHANGELOG.md
42
+ - CODE_OF_CONDUCT.md
43
+ - Gemfile
44
+ - MIT-LICENSE.md
45
+ - README.md
46
+ - Rakefile
47
+ - config/default.yml
48
+ - docs/modules/ROOT/nav.adoc
49
+ - docs/modules/ROOT/pages/cops.adoc
50
+ - docs/modules/ROOT/pages/cops_committee.adoc
51
+ - docs/modules/ROOT/pages/index.adoc
52
+ - docs/modules/ROOT/pages/installation.adoc
53
+ - docs/modules/ROOT/pages/usage.adoc
54
+ - docs/modules/antora.yml
55
+ - lib/rubocop-committee.rb
56
+ - lib/rubocop/committee/inject.rb
57
+ - lib/rubocop/committee/version.rb
58
+ - lib/rubocop/cop/committee/redundant_response_status_assertions.rb
59
+ - lib/rubocop/cop/committee/unspecified_expected_status.rb
60
+ - tasks/cops_documentation.rake
61
+ - tasks/cut_release.rake
62
+ - tasks/new_cop.rake
63
+ homepage: https://github.com/ydah/rubocop-committee
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://github.com/ydah/rubocop-committee
68
+ source_code_uri: https://github.com/ydah/rubocop-committee
69
+ changelog_uri: https://github.com/ydah/rubocop-committee/releases
70
+ rubygems_mfa_required: 'true'
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.6.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.3.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Automatic committee code style checking tool.
90
+ test_files: []