rubocop-wait_for 0.1.1 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +21 -3
- data/config/default.yml +3 -5
- data/lib/rubocop/cop/wait_for/condition_met.rb +31 -4
- data/lib/rubocop/wait_for/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc356107f4623b869f2744a7129a6ff2b19e41d5364e6d5f1b01ac635e5015fa
|
4
|
+
data.tar.gz: c3315dc89ad9f8760b67caa07c816c04c62cabd7343c33d4aaf68f0a6163b68f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fd55f9eb3bfd4efb51a4d9512d64cf956257ac0242604e77afb78cf3082e07b053168c08b5ed354d3499d149d62be1009a77ac50b14e7301c0c360d2e4f93a7
|
7
|
+
data.tar.gz: 57fa72330e959a0821402ab3a30e2a2e5b6cdf7c8e6bfe649ac2bc87ecd290d1ed76b66f1bc84a62d3af001de165ae62f80e2594fad443f4cc899f36f033d96a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.1] - 2025:08-20
|
4
|
+
|
5
|
+
- Fix `config/default.yml` configuration. [#6](https://github.com/viralpraxis/rubocop-wait_for/pull/6)
|
6
|
+
|
7
|
+
## [0.2.0] - 2025-08-13
|
8
|
+
|
9
|
+
- Add support for statically evaluated gem version requirements. [#4](https://github.com/viralpraxis/rubocop-wait_for/pull/4)
|
10
|
+
|
3
11
|
## [0.1.0] - 2025-07-07
|
4
12
|
|
5
13
|
- Initial release.
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ some_code_to_remove_once_ruby34_is_in_use()
|
|
60
60
|
|
61
61
|
> [!NOTE]
|
62
62
|
>
|
63
|
-
> Use can
|
63
|
+
> Use can use an alias `# rubocop-wait-for <code>`
|
64
64
|
|
65
65
|
If the condition inside the comment evaluates to `true` at the time of linting, RuboCop registers an offense.
|
66
66
|
|
@@ -75,6 +75,24 @@ This enables workflows like:
|
|
75
75
|
> [!WARNING]
|
76
76
|
> All the code found after the directive is passed directly to `Kernel.eval`. Use with caution.
|
77
77
|
|
78
|
+
Another situation this cop might be useful in is checking gem version.
|
79
|
+
|
80
|
+
You can achieve it by using a special form of the magic comment:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# wait-for gem-version rails '>= 8.1'
|
84
|
+
```
|
85
|
+
|
86
|
+
This condition evaluates to `true` when the detected Rails version is at least `8.1`.
|
87
|
+
|
88
|
+
Note that gem versions are determined statically using RuboCop’s [built-in feature](https://docs.rubocop.org/rubocop/development.html#limit-by-ruby-or-gem-versions).
|
89
|
+
|
90
|
+
You can also use multiple version requirements:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# wait-for gem-version rails '>= 8.1' '< 8.4'
|
94
|
+
```
|
95
|
+
|
78
96
|
### Caveats
|
79
97
|
|
80
98
|
1. Missing dependencies
|
@@ -82,8 +100,8 @@ This enables workflows like:
|
|
82
100
|
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
101
|
|
84
102
|
```ruby
|
85
|
-
# wait-for require 'rails
|
86
|
-
|
103
|
+
# wait-for require 'rails'; defined?(::Rails.some_new_feature) != nil
|
104
|
+
some_code_to_remove_once_new_rails_feature_is_available()
|
87
105
|
```
|
88
106
|
|
89
107
|
2. Caching
|
data/config/default.yml
CHANGED
@@ -45,11 +45,38 @@ module RuboCop
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def evaluate_condition(condition)
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
if (gem_condition = gem_version_condition(condition))
|
49
|
+
gem_version_requirement_met?(gem_condition)
|
50
|
+
else
|
51
|
+
begin
|
52
|
+
Kernel.eval(condition) # rubocop:disable Security/Eval
|
53
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
54
|
+
Kernel.warn "#{self.class.name}: Encountered exception during evaluating condition: #{e.message}"
|
51
55
|
|
52
|
-
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def gem_version_condition(condition)
|
62
|
+
unless (match_data = /\Agem-version\s+([a-zA-Z0-9_-]+)\s+((?:['"][^'"]+['"]\s*)+)\z/i.match(condition.strip))
|
63
|
+
return
|
64
|
+
end
|
65
|
+
|
66
|
+
{
|
67
|
+
gem_name: match_data[1],
|
68
|
+
requirements: Gem::Requirement.new(match_data[2].scan(/['"]([^'"]+)['"]/).flatten)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def gem_version_requirement_met?(gem_version_requirement)
|
73
|
+
all_gem_versions_in_target = @config.gem_versions_in_target
|
74
|
+
return false unless all_gem_versions_in_target
|
75
|
+
|
76
|
+
gem_version_in_target = all_gem_versions_in_target[gem_version_requirement.fetch(:gem_name)]
|
77
|
+
return false unless gem_version_in_target
|
78
|
+
|
79
|
+
gem_version_requirement.fetch(:requirements).satisfied_by?(gem_version_in_target)
|
53
80
|
end
|
54
81
|
end
|
55
82
|
end
|