style: allow python versions with two digits

This commit is contained in:
Rylan Polster 2020-10-11 09:46:14 -04:00
parent 40e4b38d05
commit 3b944434cf
2 changed files with 101 additions and 1 deletions

View File

@ -335,7 +335,7 @@ module RuboCop
find_strings(body_node).each do |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]
@fix = if match[1]

View File

@ -793,6 +793,30 @@ describe RuboCop::Cop::FormulaAudit::PythonVersions do
RUBY
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
expect_offense(<<~RUBY)
class Foo < Formula
@ -819,6 +843,32 @@ describe RuboCop::Cop::FormulaAudit::PythonVersions do
RUBY
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
source = <<~RUBY
class Foo < Formula
@ -868,6 +918,56 @@ describe RuboCop::Cop::FormulaAudit::PythonVersions do
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
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