Class: RuboCop::Cop::InSpecStyle::AwsIamUserProperty
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::InSpecStyle::AwsIamUserProperty
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/inspecstyle/aws_iam_user_property.rb
Overview
aws_iam_users resource properties `user|password|last_change|expiry_date|line` is deprecated in favor of `users|passwords|last_changes|expiry_dates|lines`
Constant Summary collapse
- MSG =
'Use `:%<solution>s` instead of `:%<violation>s` as a property ' \ 'for the `aws_iam_user` resource. This property will be removed in InSpec 5'
- MAP =
{ user: "aws_user_struct", name: "username" }
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rubocop/cop/inspecstyle/aws_iam_user_property.rb', line 70 def autocorrect(node) lambda do |corrector| case node.children[0].children[-1].inspect when "s(:str, \"name\")" corrector.replace(offense_range(node), 'username') when "s(:str, \"user\")" corrector.replace(offense_range(node), 'aws_user_struct') else break end end end |
#on_block(node) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubocop/cop/inspecstyle/aws_iam_user_property.rb', line 53 def on_block(node) return unless inside_aws_iam_users_spec?(node) node.descendants.each do |descendant| deprecated_aws_iam_users_property?(descendant) do |violation| add_offense( descendant, location: offense_range(descendant), message: format( MSG, violation: violation, solution: MAP[violation.to_sym] ) ) end end end |