-
Notifications
You must be signed in to change notification settings - Fork 7
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 #97 from chef/custom_cops
Signed-off-by: Tim Smith <tsmith@chef.io>
- Loading branch information
Showing
16 changed files
with
496 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
/test.rb # used for quick testing of cops |
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
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,11 @@ | ||
# frozen_string_literal: true | ||
module RuboCop | ||
# RuboCop Chef project namespace | ||
module Chef | ||
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze | ||
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "chefstyle.yml").freeze | ||
CONFIG = YAML.load(CONFIG_DEFAULT.read).freeze | ||
|
||
private_constant(*constants(false)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Copyright:: Chef Software, Inc. | ||
# Author:: Tim Smith (<tsmith@chef.io>) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module RuboCop | ||
module Cop | ||
module Chef | ||
module ChefRuby | ||
# Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now. | ||
class GemspecRequireRubygems < Base | ||
extend RuboCop::Cop::AutoCorrector | ||
include RangeHelp | ||
|
||
MSG = "Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now." | ||
|
||
def_node_matcher :require_rubygems?, <<-PATTERN | ||
(send nil? :require (str "rubygems") ) | ||
PATTERN | ||
|
||
def on_send(node) | ||
require_rubygems?(node) do |r| | ||
node = node.parent if node.parent && node.parent.conditional? # make sure we identify conditionals on the require | ||
add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector| | ||
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
57 changes: 57 additions & 0 deletions
57
lib/rubocop/cop/chef/ruby/ruby_27_keyword_argument_warnings.rb
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,57 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Copyright:: Chef Software, Inc. | ||
# Author:: Tim Smith (<tsmith@chef.io>) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module RuboCop | ||
module Cop | ||
module Chef | ||
module ChefRuby | ||
# Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings. | ||
# | ||
# @example | ||
# | ||
# # bad | ||
# shell_out!('hostnamectl status', { returns: [0, 1] }) | ||
# shell_out('hostnamectl status', { returns: [0, 1] }) | ||
# | ||
# # good | ||
# shell_out!('hostnamectl status', returns: [0, 1]) | ||
# shell_out('hostnamectl status', returns: [0, 1]) | ||
# | ||
class Ruby27KeywordArgumentWarnings < Base | ||
extend RuboCop::Cop::AutoCorrector | ||
|
||
MSG = "Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings." | ||
|
||
def_node_matcher :positional_shellout?, <<-PATTERN | ||
(send nil? {:shell_out :shell_out!} ... $(hash ... )) | ||
PATTERN | ||
|
||
def on_send(node) | ||
positional_shellout?(node) do |h| | ||
next unless h.braces? | ||
|
||
add_offense(h.loc.expression, message: MSG, severity: :refactor) do |corrector| | ||
corrector.replace(h.loc.expression, h.loc.expression.source[1..-2]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.