-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17867 from branchvincent/std_npm_args
- Loading branch information
Showing
4 changed files
with
137 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rubocops/lines" | ||
|
||
RSpec.describe RuboCop::Cop::FormulaAudit::StdNpmArgs do | ||
subject(:cop) { described_class.new } | ||
|
||
context "when auditing node formulae" do | ||
it "reports an offense when `npm install` is called without std_npm_args arguments" do | ||
expect_offense(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install" | ||
^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use `std_npm_args` for npm install | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "reports and corrects an offense when using local_npm_install_args" do | ||
expect_offense(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *Language::Node.local_npm_install_args, "--production" | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use 'std_npm_args' instead of 'local_npm_install_args'. | ||
end | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *std_npm_args(prefix: false), "--production" | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "reports and corrects an offense when using std_npm_install_args with libexec" do | ||
expect_offense(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *Language::Node.std_npm_install_args(libexec), "--production" | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use 'std_npm_args' instead of 'std_npm_install_args'. | ||
end | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *std_npm_args, "--production" | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "reports and corrects an offense when using std_npm_install_args without libexec" do | ||
expect_offense(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *Language::Node.std_npm_install_args(buildpath), "--production" | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use 'std_npm_args' instead of 'std_npm_install_args'. | ||
end | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *std_npm_args(prefix: buildpath), "--production" | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it "does not report an offense when using std_npm_args" do | ||
expect_no_offenses(<<~RUBY) | ||
class Foo < Formula | ||
def install | ||
system "npm", "install", *std_npm_args | ||
end | ||
end | ||
RUBY | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters