rubocop-wait_for 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2838e7a28daeb2b42c69f22aa9a355d4c1b8121a20418a34f0c4e32eb0f92c0f
4
+ data.tar.gz: 49c4575ac16e5ac806c04ec6d7233dde8e1b714afa4a4cc7f1244b35fddbcdd2
5
+ SHA512:
6
+ metadata.gz: fc900f5b918bf09c8677f3536bba3afd463477439976779622cb9924fb51189871648e0d834c9b30962e56323683ed54d513dd8810abb0fac58d51e563c11ff1
7
+ data.tar.gz: 3481d3386f03e303c75c443995af1d9ad025f4016b8a3e48e110dd0b3c03475bd075f62a03e0e20813ec81c79022a022f682144ba71b4362eb9bcb7900c03379
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ plugins:
2
+ - rubocop-internal_affairs
3
+ - rubocop-packaging
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+ - rubocop-wait_for
7
+
8
+ AllCops:
9
+ NewCops: enable
10
+
11
+ Naming/FileName:
12
+ Exclude:
13
+ - lib/rubocop-wait_for.rb
14
+
15
+ Style/FormatStringToken:
16
+ Exclude:
17
+ - spec/**/*
18
+
19
+ WaitFor/ConditionMet:
20
+ Exclude:
21
+ - lib/rubocop/cop/wait_for/condition_met.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-07
4
+
5
+ - Initial release.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yaroslav
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,102 @@
1
+ # RuboCop WaitFor
2
+
3
+ ## Installation
4
+
5
+ Just install the `rubocop-wait_for` gem
6
+
7
+ ```bash
8
+ gem install rubocop-wait_for
9
+ ```
10
+
11
+ or if you use bundler put this in your `Gemfile`
12
+
13
+ ```ruby
14
+ gem 'rubocop-wait_for', require: false
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ You need to tell RuboCop to load the WaitFor extension. There are two
20
+ ways to do this:
21
+
22
+ ### RuboCop configuration file
23
+
24
+ Put this into your `.rubocop.yml`.
25
+
26
+ ```yaml
27
+ plugins:
28
+ - rubocop-other-extension
29
+ - rubocop-wait_for
30
+ ```
31
+
32
+ Now you can run `rubocop` and it will automatically load the RuboCop WaitFor
33
+ cops together with the standard cops.
34
+
35
+ > [!NOTE]
36
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
37
+
38
+ ### Command line
39
+
40
+ ```bash
41
+ rubocop --plugin rubocop-wait_for
42
+ ```
43
+
44
+ ### Rake task
45
+
46
+ ```ruby
47
+ RuboCop::RakeTask.new do |task|
48
+ task.plugins << 'rubocop-wait_for'
49
+ end
50
+ ```
51
+
52
+ ## Purpose
53
+
54
+ `rubocop-wait_for` introduces the `WaitFor/ConditionMet` cop, which scans source comments for wait-for directives:
55
+
56
+ ```ruby
57
+ # wait-for Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0')
58
+ some_code_to_remove_once_ruby34_is_in_use()
59
+ ```
60
+
61
+ > [!NOTE]
62
+ >
63
+ > Use can alias use an alias `rubocop-wait-for <code>`
64
+
65
+ If the condition inside the comment evaluates to `true` at the time of linting, RuboCop registers an offense.
66
+
67
+ This enables workflows like:
68
+
69
+ - Automatically flagging feature-flagged code once the feature is launched.
70
+
71
+ - Alerting when temporary code should be deleted (e.g. after a given date or version).
72
+
73
+ - Monitoring environment-specific conditions in CI pipelines.
74
+
75
+ > [!WARNING]
76
+ > All the code found after the directive is passed directly to `Kernel.eval`. Use with caution.
77
+
78
+ ### Caveats
79
+
80
+ 1. Missing dependencies
81
+
82
+ RuboCop does not automatically load project dependencies from your `Gemfile.lock`. If your condition relies on gems like Rails, you may need to require them manually:
83
+
84
+ ```ruby
85
+ # wait-for require 'rails/gem_version'; Rails.gem_version >= Gem::Version.new('9.0.0')
86
+ some_code_to_remove_once_rails90_is_in_use()
87
+ ```
88
+
89
+ 2. Caching
90
+
91
+ Since `rubocop-wait_for` depends on RuboCop’s caching mechanism, offenses might not be reported until the cache is invalidated — for instance for dynamic conditions like time-based checks.
92
+
93
+ You can force cache invalidation by passing `RUBOCOP_WAIT_FOR_CHECK_ALL=1` environment variable:
94
+
95
+ ```shell
96
+ RUBOCOP_WAIT_FOR_CHECK_ALL=1 bundle exec rubocop --only WaitFor/ConditionMet
97
+ ```
98
+
99
+ ## License
100
+
101
+ `rubocop-wait_for` is MIT licensed. [See the accompanying file](LICENSE) for
102
+ the full text.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ task default: %i[spec]
6
+
7
+ require 'rspec/core/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ desc 'Generate a new cop with a template'
14
+ task :new_cop, [:cop] do |_task, args|
15
+ require 'rubocop'
16
+
17
+ cop_name = args.fetch(:cop) do
18
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
19
+ exit!
20
+ end
21
+
22
+ generator = RuboCop::Cop::Generator.new(cop_name)
23
+
24
+ generator.write_source
25
+ generator.write_spec
26
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/wait_for_cops.rb')
27
+ generator.inject_config(config_file_path: 'config/default.yml')
28
+
29
+ puts generator.todo
30
+ end
@@ -0,0 +1,6 @@
1
+ # Write it!
2
+
3
+ WaitFor/ConditionMet:
4
+ Description: 'TODO: Write a description of the cop.'
5
+ Enabled: pending
6
+ VersionAdded: '<<next>>'
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module WaitFor
6
+ # Evaluates annotated comments that specify a runtime condition and
7
+ # registers an offense once the condition evaluates to true.
8
+ #
9
+ # It is designed to support use cases such as removing temporary code once a
10
+ # feature flag is enabled, a deprecation deadline is reached, or some
11
+ # environment-dependent behavior becomes active.
12
+ #
13
+ # @example
14
+ # # bad
15
+ # # Assuming RUBY_VERSION is '3.4.4'
16
+ # # wait-for Gem::Version.new(RUBY_VERSION) >= '3.4.0'
17
+ # some_code_to_update_upon_upgrading_to_ruby34
18
+ #
19
+ # # good
20
+ # # Assuming RUBY_VERSION is '3.3.8'
21
+ # # wait-for Gem::Version.new(RUBY_VERSION) >= '3.4.0'
22
+ # some_code_to_update_upon_upgrading_to_ruby34
23
+ class ConditionMet < Base
24
+ DIRECTIVE_PATTERN = /#\s*(?:rubocop[:\-])?wait-for\s+(.+)/.freeze
25
+ private_constant(*constants(false))
26
+
27
+ MSG = 'condition has been met.'
28
+
29
+ def external_dependency_checksum
30
+ Time.now.to_i.to_s if ENV['RUBOCOP_WAIT_FOR_CHECK_ALL'] == '1'
31
+ end
32
+
33
+ def on_new_investigation
34
+ return if processed_source.buffer.source.empty?
35
+
36
+ processed_source.comments.each do |comment|
37
+ next unless (condition = DIRECTIVE_PATTERN.match(comment.text))
38
+
39
+ result = evaluate_condition(condition.captures[0])
40
+
41
+ add_offense(comment) if result == true
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def evaluate_condition(condition)
48
+ Kernel.eval(condition) # rubocop:disable Security/Eval
49
+ rescue Exception => e # rubocop:disable Lint/RescueException
50
+ Kernel.warn "#{self.class.name}: Encountered exception during evaluating condition: #{e.message}"
51
+
52
+ false
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'wait_for/condition_met'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module WaitFor
7
+ # A plugin that integrates rubocop-wait_for with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ def about
10
+ LintRoller::About.new(
11
+ name: 'rubocop-wait_for',
12
+ version: VERSION,
13
+ homepage: 'https://github.com/viralpraxis/rubocop-wait_for',
14
+ description: 'A RuboCop extension for tracking code that depends on runtime conditions.'
15
+ )
16
+ end
17
+
18
+ def supported?(context)
19
+ context.engine == :rubocop
20
+ end
21
+
22
+ def rules(_context)
23
+ LintRoller::Rules.new(
24
+ type: :path,
25
+ config_format: :rubocop,
26
+ value: Pathname.new(__dir__).join('../../../config/default.yml')
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module WaitFor
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'wait_for/version'
4
+
5
+ module RuboCop
6
+ module WaitFor
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/wait_for'
6
+ require_relative 'rubocop/wait_for/version'
7
+ require_relative 'rubocop/wait_for/plugin'
8
+
9
+ require_relative 'rubocop/cop/wait_for_cops'
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-wait_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Kurbatov
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: lint_roller
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rubocop
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ description: |-
41
+ Provides a custom RuboCop cop that flags annotated code once a specified runtime condition becomes true.
42
+ Useful for enforcing cleanup of temporary code paths,
43
+ such as feature toggles, deprecations, or environment-based logic.
44
+ email:
45
+ - iaroslav2k@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - CHANGELOG.md
53
+ - CODE_OF_CONDUCT.md
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - config/default.yml
58
+ - lib/rubocop-wait_for.rb
59
+ - lib/rubocop/cop/wait_for/condition_met.rb
60
+ - lib/rubocop/cop/wait_for_cops.rb
61
+ - lib/rubocop/wait_for.rb
62
+ - lib/rubocop/wait_for/plugin.rb
63
+ - lib/rubocop/wait_for/version.rb
64
+ homepage: https://github.com/viralpraxis/rubocop-wait_for
65
+ licenses: []
66
+ metadata:
67
+ homepage_uri: https://github.com/viralpraxis/rubocop-wait_for
68
+ source_code_uri: https://github.com/viralpraxis/rubocop-wait_for
69
+ changelog_uri: https://github.cohm/viralpraxis/rubocop-wait_for/blob/main/CHANGELOG.md
70
+ default_lint_roller_plugin: RuboCop::WaitFor::Plugin
71
+ rubygems_mfa_required: 'true'
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.7.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.6.7
87
+ specification_version: 4
88
+ summary: A RuboCop extension for tracking code that depends on runtime conditions.
89
+ test_files: []