Skip to content

Commit

Permalink
Merge branch 'main' into roger/improve-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerluan authored Oct 21, 2023
2 parents 947debe + 7984722 commit b898a72
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 185 deletions.
190 changes: 174 additions & 16 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,204 @@
inherit_from: .rubocop_todo.yml

# Last reviewed on Aug 31st 2023, using RuboCop v1.56.1

require:
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.7
NewCops: enable
TargetRubyVersion: 2.7

Style/FrozenStringLiteralComment:
Enabled: true

Metrics/MethodLength:
Enabled: false

Metrics/PerceivedComplexity:
Max: 9

Metrics/CyclomaticComplexity:
Max: 9

# Our displays are wide enough. IDEs are configured to linebreak beautifully when needed :) we trust common sense here.
Layout/LineLength:
Enabled: false

# Enforce that all string literals must use double quotes. This ensures real consistency.
# https://www.viget.com/articles/just-use-double-quoted-ruby-strings/
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

# Multiline literals and method calls should always have a trailing comma as that makes diffs less noisy.
# https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8
Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma
Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma
Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

# Allows to write case/when/end statements like:
# long_variable_name = case x
# when "a" then 1
# when "b" then 2
# end
# Instead of having to indent it near the the case statement which looks weird.
Layout/CaseIndentation:
EnforcedStyle: end
IndentOneStep: true
Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line

# The default style is `special_inside_parentheses` which looks like:
#
# this_is_a_method_call({
# some_key: "value",
# })
#
# This would cause an unnecessary huge diff if `in_a_method_call` is renamed,
# because all following lines need to be re-indented. That's why we prefer
# the layout like this:
#
# this_is_a_method_call({
# some_key: "value",
# })
#
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

# Make sure gems are always alphabetically ordered.
Bundler/OrderedGems:
Enabled: true

# Emojis are fun, guys. Let's use them! 🚀 (also, special characters such as "→" are way better than e.g. "->")
Style/AsciiComments:
Enabled: false

# Lengthy blocks shouldn't be an issue in rspec…
Metrics/BlockLength:
Exclude:
- 'spec/**/*'

# Prefer word array literals using %w[] syntax
# https://stackoverflow.com/a/1274703/4075379
Style/WordArray:
Enabled: true
EnforcedStyle: percent

Layout/LineLength:
# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Next
Style/Next:
Enabled: true
EnforcedStyle: skip_modifier_ifs

# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/GuardClause
Style/GuardClause:
Enabled: true

# Check for if and case statements where each branch is used for assignment to the same variable when using the return of the condition can be used instead.
Style/ConditionalAssignment:
Enabled: true
EnforcedStyle: assign_to_condition

# Long positional parameter lists make it hard to reason about the code, but named arguments are easier to follow, so we allow them.
Metrics/ParameterLists:
CountKeywordArgs: false

# We leave this one up to the developer's best judgement. For this to work well, we'd need to enable Layout/LineLength,
# which we don't want to because it would affect other areas of the codebase.
# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/IfUnlessModifier
Style/IfUnlessModifier:
Enabled: false

Style/FetchEnvVar:
# Aligning hash keys is important :)
# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/HashAlignment
Layout/HashAlignment:
Enabled: true
EnforcedHashRocketStyle: key
EnforcedColonStyle: key
EnforcedLastArgumentHashStyle: always_inspect

# This extra empty line is not needed.
Layout/EmptyLineAfterGuardClause:
Enabled: false

Metrics/PerceivedComplexity:
Max: 6
# Ensures that each key, element, parameter, and argument in a multiline hash start on a separate line.
Layout/MultilineHashKeyLineBreaks:
Enabled: true
Layout/MultilineArrayLineBreaks:
Enabled: true
Layout/MultilineMethodParameterLineBreaks:
Enabled: true
Layout/MultilineMethodArgumentLineBreaks:
Enabled: true

Metrics/CyclomaticComplexity:
Max: 7
# Ensures a line break before the first element in a multiline hash, array, parameter, and argument.
Layout/FirstHashElementLineBreak:
Enabled: true
Layout/FirstArrayElementLineBreak:
Enabled: true
Layout/FirstMethodParameterLineBreak:
Enabled: true
Layout/FirstMethodArgumentLineBreak:
Enabled: false # Except this one because sometimes it makes code more complex to read than it should be.

Metrics/BlockLength:
IgnoredMethods:
- 'describe'
- 'context'
# Helpful to make large numbers more readable.
Style/NumericLiterals:
Enabled: true
Exclude:
- 'db/schema.rb' # Don't format the magic date-like numbers generated by Rails.

# Most of these are more complicated to read & write than simply writing the conventional way.
Style/SymbolArray:
Enabled: false

Style/PerlBackrefs:
Enabled: false

# Omitting the hash value makes the code look too obscure. Not great for newcomers who are not used to this.
Style/HashSyntax:
Enabled: false

# If it's redundant, let's get rid of the block as it's more noisy.
Style/RedundantFetchBlock:
Enabled: true

# Use $stdout instead of STDOUT.
Style/GlobalStdStream:
Enabled: true

# Prefer Api::V1::MyController instead of nested and indented modules
Style/ClassAndModuleChildren:
Enabled: false

# This one measures "Assignment Branch Condition size". It's annoying and not helpful at all.
Metrics/AbcSize:
Enabled: false

# Don't enforce documentation. Trust common sense here.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
Enabled: false

Metrics/MethodLength:
RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NestedGroups:
Enabled: false
44 changes: 44 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-21 20:17:34 UTC using RuboCop version 1.53.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 24
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 108
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/config_parser_spec.rb'
- 'spec/dotenv_helper_spec.rb'
- 'spec/encoder_spec.rb'
- 'spec/helpers/string_spec.rb'
- 'spec/helpers/swift_template_helper_spec.rb'
- 'spec/models/arguments_spec.rb'
- 'spec/models/config_spec.rb'
- 'spec/models/secret_spec.rb'
- 'spec/models/template_arguments_spec.rb'
- 'spec/models/type_spec.rb'
- 'spec/salt_generator_spec.rb'

# Offense count: 7
RSpec/StubbedMock:
Exclude:
- 'spec/config_parser_spec.rb'
- 'spec/helpers/ui_spec.rb'
- 'spec/models/arguments_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedVars.
Style/FetchEnvVar:
Exclude:
- 'lib/arkana/encoder.rb'
14 changes: 7 additions & 7 deletions lib/arkana/helpers/swift_template_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
module SwiftTemplateHelper
def self.swift_type(type)
case type
when :string then "String"
when :boolean then "Bool"
when :integer then "Int"
else raise "Unknown variable type '#{type}' received.'"
when :string then "String"
when :boolean then "Bool"
when :integer then "Int"
else raise "Unknown variable type '#{type}' received.'"
end
end

def self.protocol_getter(declaration_strategy)
case declaration_strategy
when "lazy var" then "mutating get"
when "var", "let" then "get"
else raise "Unknown declaration strategy '#{declaration_strategy}' received.'"
when "lazy var" then "mutating get"
when "var", "let" then "get"
else raise "Unknown declaration strategy '#{declaration_strategy}' received.'"
end
end
end
12 changes: 6 additions & 6 deletions lib/arkana/models/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ module Type

def self.new(string_value:)
case string_value
when "true", "false"
BOOLEAN
when /^\d+$/
INTEGER
else
STRING
when "true", "false"
BOOLEAN
when /^\d+$/
INTEGER
else
STRING
end
end
end
9 changes: 5 additions & 4 deletions spec/arkana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
let(:config_filepath) { "spec/fixtures/arkana-fixture.yml" }
let(:arguments) { Arguments.new }
let(:config) { ConfigParser.parse(arguments) }

before { ARGV.replace(["--config-filepath", config_filepath]) }

context "when one or more env vars are missing" do
it "should raise error" do
expect { Arkana.run(arguments) }.to raise_error(/Secret '(?:.*)' was declared but couldn't be found in the environment variables nor in the specified dotenv file./)
it "raises error" do
expect { described_class.run(arguments) }.to raise_error(/Secret '(?:.*)' was declared but couldn't be found in the environment variables nor in the specified dotenv file./)
end
end

Expand All @@ -20,9 +21,9 @@
end
end

it "should call SwiftCodeGenerator.generate" do
it "calls SwiftCodeGenerator.generate" do
expect(SwiftCodeGenerator).to receive(:generate)
Arkana.run(arguments)
described_class.run(arguments)
end
end
end
Expand Down
Loading

0 comments on commit b898a72

Please sign in to comment.