style: allow python versions with two digits
This commit is contained in:
parent
40e4b38d05
commit
3b944434cf
@ -335,7 +335,7 @@ module RuboCop
|
|||||||
find_strings(body_node).each do |str|
|
find_strings(body_node).each do |str|
|
||||||
string_content = string_content(str)
|
string_content = string_content(str)
|
||||||
|
|
||||||
next unless match = string_content.match(/^python(@)?(\d\.\d)$/)
|
next unless match = string_content.match(/^python(@)?(\d\.\d+)$/)
|
||||||
next if python_version == match[2]
|
next if python_version == match[2]
|
||||||
|
|
||||||
@fix = if match[1]
|
@fix = if match[1]
|
||||||
|
|||||||
@ -793,6 +793,30 @@ describe RuboCop::Cop::FormulaAudit::PythonVersions do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allow matching versions with two digits" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.10"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python@3.10"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allow matching versions without `@` with two digits" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.10"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python3.10"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "do not allow mismatching versions" do
|
it "do not allow mismatching versions" do
|
||||||
expect_offense(<<~RUBY)
|
expect_offense(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -819,6 +843,32 @@ describe RuboCop::Cop::FormulaAudit::PythonVersions do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "do not allow mismatching versions with two digits" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.11"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python@3.10"
|
||||||
|
^^^^^^^^^^^^^ References to `python@3.10` should match the specified python dependency (`python@3.11`)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "do not allow mismatching versions without `@` with two digits" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.11"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python3.10"
|
||||||
|
^^^^^^^^^^^^ References to `python3.10` should match the specified python dependency (`python3.11`)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "autocorrects mismatching versions" do
|
it "autocorrects mismatching versions" do
|
||||||
source = <<~RUBY
|
source = <<~RUBY
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -868,6 +918,56 @@ describe RuboCop::Cop::FormulaAudit::PythonVersions do
|
|||||||
new_source = autocorrect_source(source)
|
new_source = autocorrect_source(source)
|
||||||
expect(new_source).to eq(corrected_source)
|
expect(new_source).to eq(corrected_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "autocorrects mismatching versions with two digits" do
|
||||||
|
source = <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.10"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python@3.9"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
corrected_source = <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.10"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python@3.10"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
new_source = autocorrect_source(source)
|
||||||
|
expect(new_source).to eq(corrected_source)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "autocorrects mismatching versions without `@` with two digits" do
|
||||||
|
source = <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.11"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python3.10"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
corrected_source = <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
depends_on "python@3.11"
|
||||||
|
|
||||||
|
def install
|
||||||
|
puts "python3.11"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
new_source = autocorrect_source(source)
|
||||||
|
expect(new_source).to eq(corrected_source)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user