Skip to content

Commit 113eb8a

Browse files
authored
Merge pull request #401 from envato/rubocop
2 parents 92c9aad + dcc8160 commit 113eb8a

15 files changed

Lines changed: 131 additions & 143 deletions

File tree

.rubocop.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# The behavior of RuboCop can be controlled via the .rubocop.yml
2+
# configuration file. It makes it possible to enable/disable
3+
# certain cops (checks) and to alter their behavior if they accept
4+
# any parameters. The file can be placed either in your home
5+
# directory or in some project directory.
6+
#
7+
# RuboCop will start looking for the configuration file in the directory
8+
# where the inspected file is and continue its way up to the root directory.
9+
#
10+
# See https://docs.rubocop.org/rubocop/configuration
11+
12+
inherit_mode:
13+
merge:
14+
- Exclude
115
inherit_from: .rubocop_todo.yml
216

317
AllCops:

.rubocop_todo.yml

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100 --no-offense-counts --no-auto-gen-timestamp`
3-
# using RuboCop version 1.81.7.
3+
# using RuboCop version 1.84.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -18,12 +18,6 @@ Layout/TrailingWhitespace:
1818
Exclude:
1919
- 'spec/stack_master/commands/status_spec.rb'
2020

21-
# This cop supports unsafe autocorrection (--autocorrect-all).
22-
# Configuration parameters: AllowSafeAssignment.
23-
Lint/AssignmentInCondition:
24-
Exclude:
25-
- 'lib/stack_master/parameter_resolvers/latest_container.rb'
26-
2721
# Configuration parameters: AllowedMethods.
2822
# AllowedMethods: enums
2923
Lint/ConstantDefinitionInBlock:
@@ -41,11 +35,6 @@ Lint/DuplicateMethods:
4135
- 'lib/stack_master/stack_definition.rb'
4236
- 'lib/stack_master/test_driver/cloud_formation.rb'
4337

44-
Lint/IneffectiveAccessModifier:
45-
Exclude:
46-
- 'lib/stack_master/parameter_loader.rb'
47-
- 'lib/stack_master/template_compilers/sparkle_formation.rb'
48-
4938
# This cop supports unsafe autocorrection (--autocorrect-all).
5039
# Configuration parameters: EnforcedStyle.
5140
# SupportedStyles: standard_error, runtime_error
@@ -99,33 +88,19 @@ Lint/SelfAssignment:
9988
Exclude:
10089
- 'lib/stack_master/cli.rb'
10190

102-
# This cop supports safe autocorrection (--autocorrect).
103-
Lint/SendWithMixinArgument:
104-
Exclude:
105-
- 'lib/stack_master/sparkle_formation/template_file.rb'
106-
10791
# Configuration parameters: AllowComments, AllowNil.
10892
Lint/SuppressedException:
10993
Exclude:
11094
- 'Rakefile'
11195
- 'lib/stack_master/stack_events/streamer.rb'
11296
- 'lib/stack_master/stack_status.rb'
11397

114-
# This cop supports safe autocorrection (--autocorrect).
115-
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
116-
Lint/UnusedBlockArgument:
117-
Exclude:
118-
- 'features/step_definitions/parameter_store_steps.rb'
119-
- 'lib/stack_master/stack_differ.rb'
120-
12198
# This cop supports safe autocorrection (--autocorrect).
12299
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
123100
# NotImplementedExceptions: NotImplementedError
124101
Lint/UnusedMethodArgument:
125102
Exclude:
126-
- 'lib/stack_master/test_driver/cloud_formation.rb'
127103
- 'lib/stack_master/test_driver/s3.rb'
128-
- 'spec/stack_master/parameter_resolver_spec.rb'
129104
- 'spec/support/aws_stubs.rb'
130105

131106
# This cop supports safe autocorrection (--autocorrect).
@@ -135,14 +110,6 @@ Lint/UselessAccessModifier:
135110
- 'lib/stack_master/parameter_loader.rb'
136111
- 'lib/stack_master/template_compilers/sparkle_formation.rb'
137112

138-
# This cop supports safe autocorrection (--autocorrect).
139-
Lint/UselessAssignment:
140-
Exclude:
141-
- 'lib/stack_master/cli.rb'
142-
- 'lib/stack_master/commands/tidy.rb'
143-
- 'lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb'
144-
- 'lib/stack_master/template_compiler.rb'
145-
146113
# This cop supports safe autocorrection (--autocorrect).
147114
# Configuration parameters: CheckForMethodsWithNoSideEffects.
148115
Lint/Void:
@@ -176,7 +143,6 @@ Metrics/AbcSize:
176143
# AllowedMethods: refine
177144
Metrics/BlockLength:
178145
Exclude:
179-
- '**/*.gemspec'
180146
- 'example/simple/templates/myapp_vpc.rb'
181147
- 'spec/integration/drift_spec.rb'
182148
- 'spec/stack_master/aws_driver/s3_spec.rb'
@@ -320,7 +286,6 @@ Naming/AccessorMethodName:
320286
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
321287
Naming/FileName:
322288
Exclude:
323-
- 'Rakefile.rb'
324289
- 'spec/fixtures/templates/rb/cfndsl/sample-ctp-repeated.rb'
325290
- 'spec/fixtures/templates/rb/cfndsl/sample-ctp.rb'
326291

@@ -352,7 +317,6 @@ Naming/MethodParameterName:
352317
# MethodDefinitionMacros: define_method, define_singleton_method
353318
Naming/PredicatePrefix:
354319
Exclude:
355-
- 'spec/**/*'
356320
- 'lib/stack_master/parameter_resolvers/one_password.rb'
357321
- 'lib/stack_master/sparkle_formation/compile_time/definitions_validator.rb'
358322
- 'lib/stack_master/sparkle_formation/compile_time/empty_validator.rb'
@@ -405,8 +369,6 @@ Style/ClassAndModuleChildren:
405369
# Configuration parameters: AllowedConstants.
406370
Style/Documentation:
407371
Exclude:
408-
- 'spec/**/*'
409-
- 'test/**/*'
410372
- 'lib/stack_master.rb'
411373
- 'lib/stack_master/aws_driver/cloud_formation.rb'
412374
- 'lib/stack_master/aws_driver/s3.rb'
@@ -503,6 +465,13 @@ Style/GlobalStdStream:
503465
- 'lib/stack_master/cli.rb'
504466
- 'spec/stack_master/commands/apply_spec.rb'
505467

468+
# This cop supports safe autocorrection (--autocorrect).
469+
# Configuration parameters: EnforcedStyle.
470+
# SupportedStyles: braces, no_braces
471+
Style/HashAsLastArrayItem:
472+
Exclude:
473+
- 'spec/integration/drift_spec.rb'
474+
506475
# This cop supports unsafe autocorrection (--autocorrect-all).
507476
Style/HashTransformValues:
508477
Exclude:
@@ -541,7 +510,6 @@ Style/MutableConstant:
541510
# SupportedStyles: predicate, comparison
542511
Style/NumericPredicate:
543512
Exclude:
544-
- 'spec/**/*'
545513
- 'lib/stack_master/cli.rb'
546514
- 'lib/stack_master/commands/events.rb'
547515
- 'lib/stack_master/commands/nag.rb'

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ The format is based on [Keep a Changelog], and this project adheres to
1010

1111
## [Unreleased]
1212

13+
### Fixed
14+
15+
- Resolve lint issues identified by RuboCop. ([#401])
16+
1317
[Unreleased]: https://github.com/envato/stack_master/compare/v2.18.0...HEAD
18+
[#401]: https://github.com/envato/stack_master/pull/401
1419

1520
## [2.18.0] - 2026-02-02
1621

features/step_definitions/parameter_store_steps.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Given(/^(?:a|the)\ SSM\ parameter(?:\ named)?\ "([^"]*)"
2-
\ with\ value\ "([^"]*)"\ in\ region\ "([^"]*)"$/x) do |parameter_name, parameter_value, parameter_region|
2+
\ with\ value\ "([^"]*)"\ in\ region\ "([^"]*)"$/x) do |parameter_name, parameter_value, _parameter_region|
33
Aws.config[:ssm] = {
44
stub_responses: {
55
get_parameter: {

lib/stack_master/cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def default_config_file
263263
def load_config(file)
264264
stack_file = file || default_config_file
265265
StackMaster::Config.load!(stack_file)
266-
rescue Errno::ENOENT => e
266+
rescue Errno::ENOENT
267267
say "Failed to load config file #{stack_file}"
268268
@kernel.exit false
269269
end
@@ -301,7 +301,7 @@ def execute_stacks_command(command, args, options)
301301
end
302302

303303
def show_other_region_candidates(config, stack_name)
304-
candidates = config.filter(region = '', stack_name = stack_name)
304+
candidates = config.filter('', stack_name = stack_name)
305305
return if candidates.empty?
306306

307307
StackMaster.stdout.puts "Stack name #{stack_name} exists in regions: #{candidates.map(&:region).join(', ')}"

lib/stack_master/commands/tidy.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ class Tidy
55
include StackMaster::Commands::TerminalHelper
66

77
def perform
8-
used_templates = []
9-
used_parameter_files = []
10-
118
templates = Set.new(find_templates)
129
parameter_files = Set.new(find_parameter_files)
1310

14-
status = @config.stacks.each do |stack_definition|
11+
@config.stacks.each do |stack_definition|
1512
parameter_files.subtract(stack_definition.parameter_files_from_globs)
1613
template = File.absolute_path(stack_definition.template_file_path)
1714

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
require 'active_support/core_ext/object/deep_dup'
22

33
module StackMaster
4-
class ParameterLoader
4+
module ParameterLoader
55
COMPILE_TIME_PARAMETERS_KEY = 'compile_time_parameters'
66

7-
def self.load(parameter_files: [], parameters: {})
8-
StackMaster.debug 'Searching for parameter files...'
9-
all_parameters = parameter_files.map { |file_name| load_parameters(file_name) } + [parameters]
10-
all_parameters.each_with_object({ template_parameters: {}, compile_time_parameters: {} }) do |parameters, hash|
11-
template_parameters = create_template_parameters(parameters)
12-
compile_time_parameters = create_compile_time_parameters(parameters)
13-
14-
merge_and_camelize(hash[:template_parameters], template_parameters)
15-
merge_and_camelize(hash[:compile_time_parameters], compile_time_parameters)
7+
class << self
8+
def load(parameter_files: [], parameters: {})
9+
StackMaster.debug 'Searching for parameter files...'
10+
all_parameters = parameter_files.map { |file_name| load_parameters(file_name) } + [parameters]
11+
all_parameters.each_with_object({ template_parameters: {}, compile_time_parameters: {} }) do |parameters, hash|
12+
template_parameters = create_template_parameters(parameters)
13+
compile_time_parameters = create_compile_time_parameters(parameters)
14+
15+
merge_and_camelize(hash[:template_parameters], template_parameters)
16+
merge_and_camelize(hash[:compile_time_parameters], compile_time_parameters)
17+
end
1618
end
17-
end
1819

19-
private
20+
private
2021

21-
def self.load_parameters(file_name)
22-
file_exists = File.exist?(file_name)
23-
StackMaster.debug file_exists ? " #{file_name} found" : " #{file_name} not found"
24-
file_exists ? load_file(file_name) : {}
25-
end
22+
def load_parameters(file_name)
23+
file_exists = File.exist?(file_name)
24+
StackMaster.debug file_exists ? " #{file_name} found" : " #{file_name} not found"
25+
file_exists ? load_file(file_name) : {}
26+
end
2627

27-
def self.load_file(file_name)
28-
YAML.load(File.read(file_name)) || {}
29-
end
28+
def load_file(file_name)
29+
YAML.load(File.read(file_name)) || {}
30+
end
3031

31-
def self.create_template_parameters(parameters)
32-
parameters.deep_dup.tap do |parameters_clone|
33-
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY) ||
34-
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY.camelize)
32+
def create_template_parameters(parameters)
33+
parameters.deep_dup.tap do |parameters_clone|
34+
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY) ||
35+
parameters_clone.delete(COMPILE_TIME_PARAMETERS_KEY.camelize)
36+
end
3537
end
36-
end
3738

38-
def self.create_compile_time_parameters(parameters)
39-
(parameters[COMPILE_TIME_PARAMETERS_KEY] || parameters[COMPILE_TIME_PARAMETERS_KEY.camelize] || {}).deep_dup
40-
end
39+
def create_compile_time_parameters(parameters)
40+
(parameters[COMPILE_TIME_PARAMETERS_KEY] || parameters[COMPILE_TIME_PARAMETERS_KEY.camelize] || {}).deep_dup
41+
end
4142

42-
def self.merge_and_camelize(hash, parameters)
43-
parameters.each { |key, value| hash[key.camelize] = value }
43+
def merge_and_camelize(hash, parameters)
44+
parameters.each { |key, value| hash[key.camelize] = value }
45+
end
4446
end
4547
end
4648
end

lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(config, stack_definition)
1010
end
1111

1212
def resolve(value)
13-
filters = @ami_finder.build_filters_from_string(value, prefix = 'tag')
13+
filters = @ami_finder.build_filters_from_string(value, 'tag')
1414
@ami_finder.find_latest_ami(filters)&.image_id
1515
end
1616
end

lib/stack_master/parameter_resolvers/latest_container.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def resolve(parameters)
3737
def fetch_images(repository_name, registry_id, ecr)
3838
images = []
3939
next_token = nil
40-
while resp = ecr.describe_images(
40+
while (resp = ecr.describe_images(
4141
{
4242
repository_name: repository_name,
4343
registry_id: registry_id,
@@ -46,7 +46,7 @@ def fetch_images(repository_name, registry_id, ecr)
4646
tag_status: 'TAGGED'
4747
}
4848
}
49-
)
49+
))
5050

5151
images += resp.image_details
5252
next_token = resp.next_token

lib/stack_master/sparkle_formation/template_file.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ def _user_data_file(file_name, vars = {})
6161
end
6262
end
6363

64-
SparkleFormation::SparkleAttribute::Aws.send(:include, StackMaster::SparkleFormation::UserDataFile)
65-
SparkleFormation::SparkleAttribute::Aws.send(:include, StackMaster::SparkleFormation::JoinedFile)
64+
SparkleFormation::SparkleAttribute::Aws.include StackMaster::SparkleFormation::UserDataFile
65+
SparkleFormation::SparkleAttribute::Aws.include StackMaster::SparkleFormation::JoinedFile

0 commit comments

Comments
 (0)