Skip to content

Commit

Permalink
Move away from the singleton approach and introduce Guard::Engine (#982)
Browse files Browse the repository at this point in the history
* Move away from the singleton approach and introduce Guard::Engine
* Create a new Guardfile::Result class to hold the data from Guardfile evaluation
* Fix DslDescriber spec when using Unicode characters
* Improve internal structure further
* Allow to reset the scopes from the interactor

Signed-off-by: Rémy Coutable <remy@rymai.me>
  • Loading branch information
rymai committed Jul 22, 2022
1 parent a97713c commit cc8d97a
Show file tree
Hide file tree
Showing 134 changed files with 3,477 additions and 5,989 deletions.
5 changes: 3 additions & 2 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
fail_on_violations: true
fail_on_violations: false

rubocop:
enabled: true
version: 0.75.0
version: 0.83.0
config_file: .rubocop.yml

reek:
enabled: true
config_file: .reek.yml

flog:
enabled: true
80 changes: 80 additions & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
detectors:
UtilityFunction:
public_methods_only: true

BooleanParameter:
exclude:
- "Guard::Interactor#initialize"

FeatureEnvy:
exclude:
- "Guard::CLI#show"
- "Guard::CLI#notifiers"
- "Guard::Engine#_evaluate"
- "Guard::TestHelpers::Template::Session#match"
- "Guard::DslDescriber#show"
- "Guard::DslDescriber#list"

ControlParameter:
exclude:
- "Guard::Engine#interactor="
- "Guard::Runner#run"
- "stub_file"

InstanceVariableAssumption:
exclude:
- "Guard::Dsl"

NilCheck:
exclude:
- "Guard::Cli::Environments::ReadyOnly#start"
- "Guard::UI#clear"
- "Guard::DslDescriber#show"

NestedIterators:
exclude:
- "Guard::Dsl#self.cleanup_backtrace"
- "Guard::DslDescriber#show"

TooManyStatements:
exclude:
- "Guard::Dsl#evaluate"
- "Guard::Dsl#self.cleanup_backtrace"
- "Guard::Engine#_guardfile_deprecated_check"
- "Guard::Engine#_evaluate"
- "Guard::Engine#start"
- "Guard::Engine#pause"
- "Guard::Engine#stop"
- "Guard::Engine#_instantiate"
- "Guard::PluginUtil#plugin_class"
- "Guard::TestHelpers::Template::Session#_watches"

TooManyMethods:
exclude:
- "Guard::Engine"

IrresponsibleModule:
exclude:
- "Guard::Notifier"
- "Guard::Cli::Environments::Base"
- "Guard::Cli::Environments::ReadOnly"
- "Guard::Cli::Environments::Write"
- "Guard::Dsl"
- "Guard::Dummy"
- "Guard::Doe"
- "Guard::FooBar"
- "Guard::FooBaz"
- "Guard::TestHelper"
- "FakePry"
- "ApplicationController#respond"

UncommunicativeVariableName:
exclude:
- "ArubaAdapter"
- "Guard::Cli::Environments::ReadOnly"
- "Guard::Cli::Environments::Write"
- "Guard::Dsl#evaluate"
- "Guard::Engine#start"
- "Guard::PluginUtil#initialize_plugin"
- "Guard::PluginUtil#plugin_class"
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--fail-fast
--format documentation
--color
--require spec_helper
54 changes: 49 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
Exclude:
- "vendor/**/*"
- "db/schema.rb"
- "tmp/**/*"
- "Guardfile"
- "config/Guardfile"
UseCache: false

Style/CollectionMethods:
Description: Preferred collection methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
Expand All @@ -17,6 +17,7 @@ Style/CollectionMethods:
find: detect
find_all: select
reduce: inject

Layout/DotPosition:
Description: Checks the position of the dot in multi-line method calls.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
Expand All @@ -25,23 +26,28 @@ Layout/DotPosition:
SupportedStyles:
- leading
- trailing

Naming/FileName:
Description: Use snake_case for source file names.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
Enabled: false
Exclude: []

Style/GuardClause:
Description: Check for conditionals that can be replaced with guard clauses
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
Enabled: false
MinBodyLength: 1

Style/IfUnlessModifier:
Description: Favor modifier if/unless usage when you have a single-line body.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
Enabled: false

Style/OptionHash:
Description: Don't use option hashes when you can use keyword arguments.
Enabled: false

Style/PercentLiteralDelimiters:
Description: Use `%`-literal delimiters consistently
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
Expand All @@ -56,6 +62,7 @@ Style/PercentLiteralDelimiters:
"%w": "()"
"%W": "()"
"%x": "()"

Naming/PredicateName:
Description: Check the names of predicate methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
Expand All @@ -64,10 +71,11 @@ Naming/PredicateName:
- is_
- has_
- have_
NamePrefixBlacklist:
ForbiddenPrefixes:
- is_
Exclude:
- spec/**/*

Style/RaiseArgs:
Description: Checks the arguments passed to raise/fail.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
Expand All @@ -76,6 +84,7 @@ Style/RaiseArgs:
SupportedStyles:
- compact
- exploded

Style/SignalException:
Description: Checks for proper usage of fail and raise.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
Expand All @@ -85,6 +94,7 @@ Style/SignalException:
- only_raise
- only_fail
- semantic

Style/SingleLineBlockParams:
Description: Enforces the names of some block params.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
Expand All @@ -96,11 +106,13 @@ Style/SingleLineBlockParams:
- inject:
- a
- e

Style/SingleLineMethods:
Description: Avoid single-line methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
Enabled: false
AllowIfMethodIsEmpty: true

Style/StringLiterals:
Description: Checks if uses of quotes match the configured preference.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
Expand All @@ -109,6 +121,7 @@ Style/StringLiterals:
SupportedStyles:
- single_quotes
- double_quotes

Style/StringLiteralsInInterpolation:
Description: Checks if uses of quotes inside expressions in interpolated strings
match the configured preference.
Expand All @@ -117,6 +130,7 @@ Style/StringLiteralsInInterpolation:
SupportedStyles:
- single_quotes
- double_quotes

Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Expand All @@ -126,6 +140,7 @@ Style/TrailingCommaInArguments:
# - comma
# - consistent_comma
# - no_comma

Style/TrailingCommaInHashLiteral:
Description: 'Checks for trailing comma in hash literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Expand All @@ -135,6 +150,7 @@ Style/TrailingCommaInHashLiteral:
# - comma
# - consistent_comma
# - no_comma

Style/TrailingCommaInArrayLiteral:
Description: 'Checks for trailing comma in array literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Expand All @@ -144,30 +160,36 @@ Style/TrailingCommaInArrayLiteral:
# - comma
# - consistent_comma
# - no_comma

Metrics/AbcSize:
Description: A calculated magnitude based on number of assignments, branches, and
conditions.
Enabled: false
Max: 15

Metrics/ClassLength:
Description: Avoid classes longer than 100 lines of code.
Enabled: false
CountComments: false
Max: 100

Metrics/ModuleLength:
CountComments: false
Max: 100
Description: Avoid modules longer than 100 lines of code.
Enabled: false

Metrics/BlockLength:
Exclude:
- spec/**/*.rb

Metrics/CyclomaticComplexity:
Description: A complexity metric that is strongly correlated to the number of test
cases needed to validate a method.
Enabled: false
Max: 6
Metrics/LineLength:

Layout/LineLength:
Enabled: true
Max: 125
# To make it possible to copy or click on URIs in the code, we allow lines
Expand All @@ -184,92 +206,114 @@ Metrics/LineLength:
# elements. Strings will be converted to Regexp objects. A line that matches
# any regular expression listed in this option will be ignored by LineLength.
IgnoredPatterns: []

Metrics/MethodLength:
Description: Avoid methods longer than 10 lines of code.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
Enabled: false
CountComments: false
Max: 10

Metrics/ParameterLists:
Description: Avoid parameter lists longer than three or four parameters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
Enabled: false
Max: 5
CountKeywordArgs: true

Metrics/PerceivedComplexity:
Description: A complexity metric geared towards measuring complexity for a human
reader.
Enabled: false
Max: 7

Lint/AssignmentInCondition:
Description: Don't use assignment in conditions.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
Enabled: false
AllowSafeAssignment: true

Style/InlineComment:
Description: Avoid inline comments.
Enabled: false

Naming/AccessorMethodName:
Description: Check the naming of accessor methods for get_/set_.
Enabled: false

Style/Alias:
Description: Use alias_method instead of alias.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
Enabled: false

Style/Documentation:
Description: Document classes and non-namespace modules.
Enabled: false

Style/DoubleNegation:
Description: Checks for uses of double negation (!!).
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
Enabled: false

Style/EachWithObject:
Description: Prefer `each_with_object` over `inject` or `reduce`.
Enabled: false

Style/EmptyLiteral:
Description: Prefer literals to Array.new/Hash.new/String.new.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
Enabled: false

Style/ModuleFunction:
Description: Checks for usage of `extend self` in modules.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
Enabled: false

Style/OneLineConditional:
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
Enabled: false

Style/PerlBackrefs:
Description: Avoid Perl-style regex back references.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
Enabled: false

Style/Send:
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
may overlap with existing methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
Enabled: false

Style/SpecialGlobalVars:
Description: Avoid Perl-style global variables.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
Enabled: false

Style/VariableInterpolation:
Description: Don't interpolate global, instance and class variables directly in
strings.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
Enabled: false

Style/WhenThen:
Description: Use when x then ... for one-line cases.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
Enabled: false

Lint/EachWithObjectArgument:
Description: Check for immutable argument given to each_with_object.
Enabled: true
Lint/HandleExceptions:

Lint/SuppressedException:
Description: Don't suppress exception.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
Enabled: false

Lint/LiteralAsCondition:
Description: Checks of literals used in conditions.
Enabled: false

Lint/LiteralInInterpolation:
Description: Checks for literals used in interpolation.
Enabled: false
Loading

0 comments on commit cc8d97a

Please sign in to comment.