diff --git a/rails/rubocop-for-gem.yml b/rails/rubocop-for-gem.yml new file mode 100644 index 0000000000000000000000000000000000000000..525eae02a23afdcde3aae855e0832170410e355e --- /dev/null +++ b/rails/rubocop-for-gem.yml @@ -0,0 +1,12 @@ +require: + - rubocop-packaging + +inherit_from: + - ./rubocop-base.yml + +# gem 'rubocop', '1.65.1', require: false +# gem 'rubocop-minitest', '0.35.1', require: false +# gem 'rubocop-performance', '1.21.1', require: false +# gem 'rubocop-packaging', '0.5.2', require: false +AllCops: + NewCops: enable # pending cops get enabled by default and must be disabled by hand, if needed diff --git a/rails/rubocop.yml b/rails/rubocop.yml index 247bc2a8509d626d32cbda434b084c8eb21a1759..a62ef2627ff7a56e1140499017ed192db56bfd31 100644 --- a/rails/rubocop.yml +++ b/rails/rubocop.yml @@ -3,164 +3,12 @@ require: - rubocop-performance - rubocop-rails +inherit_from: + - ./rubocop/rubocop-base.yml + - ./rubocop/rubocop-minitest.yml + - ./rubocop/rubocop-rails.yml + # gem 'rubocop', '1.65.1', require: false # gem 'rubocop-minitest', '0.35.1', require: false # gem 'rubocop-performance', '1.21.1', require: false # gem 'rubocop-rails', '2.25.1', require: false -AllCops: - NewCops: enable # pending cops get enabled by default and must be disabled by hand, if needed - - -# BEGIN Customizations -# BEGIN Layout -# only before, enforcing also after adds too many blank lines -Layout/EmptyLinesAroundAccessModifier: - EnforcedStyle: only_before # default: around - -# indent first element one level deeper than the 'parent' -Layout/FirstArrayElementIndentation: - EnforcedStyle: consistent # default: special_inside_parentheses - -# indent first element one level deeper than the 'parent' -Layout/FirstHashElementIndentation: - EnforcedStyle: consistent # default: special_inside_parentheses - -# every screen should be able to handle 150 characters -Layout/LineLength: - Max: 150 # default: 120 - -# indent each method call one level deeper than the 'parent' -Layout/MultilineMethodCallIndentation: - EnforcedStyle: indented # default: aligned -# END Layout - - -# BEGIN Metrics -# too restrictive, this kind of high complexity is needed at times -Metrics/AbcSize: - Enabled: false - -# default is too restrictive, however, having some restriction incentivizes to use helper methods -Metrics/BlockLength: - AllowedMethods: ['class_eval', 'module_eval', 'refine'] # default: 'refine' - CountAsOne: &array_hash_heredoc_method_call ['array', 'hash', 'heredoc', 'method_call'] # default: [] - Exclude: &test_config_db ['test/**/*', 'config/**/*', 'db/**/*'] - -# default is too restrictive, having some restriction incentivizes to split up overly large classes -Metrics/ClassLength: - CountAsOne: *array_hash_heredoc_method_call # default: [] - Max: 200 # default: 100 - Exclude: *test_config_db - -# default is too restrictive, allow higher complexity -Metrics/CyclomaticComplexity: - Max: 14 # default: 7 - -# default is too restrictive, allow longer methods -Metrics/MethodLength: - CountAsOne: *array_hash_heredoc_method_call # default: [] - Max: 30 # default: 10 - Exclude: *test_config_db - -# default is too restrictive, allow longer modules -Metrics/ModuleLength: - CountAsOne: *array_hash_heredoc_method_call # default: [] - Max: 200 # default: 100 - Exclude: *test_config_db - -# long parameter lists add too much complexity, keyword args are named and thus more obvious what is expected, ignore them -Metrics/ParameterLists: - CountKeywordArgs: false # default: true - -# default is too restrictive, allow higher complexity -Metrics/PerceivedComplexity: - Max: 16 # default: 8 -# END Metrics - - -# BEGIN Minitest -# seems kind of buggy, when a custom message is given, this is flagged -Minitest/AssertWithExpectedArgument: - Enabled: false - -# allow more assertions than default, but also not too many -Minitest/MultipleAssertions: - Max: 8 # default: 3 -# END Minitest - - -# BEGIN Rails -# file paths should be built with arguments instead of a single string -Rails/ApplicationController: - Exclude: ['app/controllers/api/**/*', 'app/controllers/a_p_i/**/*'] # exclude API namespace, but not others (convention) - -# exclude migrations since non-ApplicationRecord behavior might be desired -Rails/ApplicationRecord: - Exclude: ['db/migrate/*'] - -# ensure paths are built using a filesystem agnostic way, i.e. arguments instead of a single string -Rails/FilePath: - EnforcedStyle: arguments # default: slashes - -# no reason not to use an established Rails feature if developers see fit -Rails/HasAndBelongsToMany: - Enabled: false - -# prevent puts, but exclude test, config, db since Rails Logger may not have been loaded -Rails/Output: - Exclude: *test_config_db - -# allow usage of methods that skip validations; we trust developers know what they are doing -Rails/SkipsModelValidations: - Enabled: false - -# allow usage of three-state boolean columns, it may be an STI table -Rails/ThreeStateBooleanColumn: - Enabled: false -# END Rails - - -# BEGIN Style -# prefer compact style, since Zeitwerk handles initialization of modules -Style/ClassAndModuleChildren: - EnforcedStyle: compact # default: nested - Exclude: ['config/application.rb'] - -# documentation of classes in migrations and tests is not needed -Style/Documentation: - Exclude: *test_config_db - -# allow in auto-generated files -Style/GlobalStdStream: - Exclude: *test_config_db - -# allow empty parentheses to differentiate method calls vs attributes -Style/MethodCallWithoutArgsParentheses: - Enabled: false - -# explicit returns are nice and convey meaning, so allow them -Style/RedundantReturn: - Enabled: false - -# allow for explicit calls to self to help differentiate between method calls vs local variables -Style/RedundantSelf: - Enabled: false - -# enforce double quotes in string literals -Style/StringLiterals: - EnforcedStyle: double_quotes # default: single_quotes - -# enforce double quotes inside string interpolations -Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes # default: single_quotes - -# allow only brackets, not %i or %I -Style/SymbolArray: - EnforcedStyle: brackets # default: percent - MinSize: 1 # default: 2 - -# allow only brackets, not %w or %W -Style/WordArray: - EnforcedStyle: brackets # default: percent - MinSize: 1 # default: 2 -# END Style diff --git a/rails/rubocop/rubocop-base.yml b/rails/rubocop/rubocop-base.yml new file mode 100644 index 0000000000000000000000000000000000000000..207d8efac3298dc41e28c0e2f11ab99737286b9b --- /dev/null +++ b/rails/rubocop/rubocop-base.yml @@ -0,0 +1,120 @@ +require: + - rubocop-performance + +# gem 'rubocop', '1.65.1', require: false +# gem 'rubocop-performance', '1.21.1', require: false +AllCops: + NewCops: enable # pending cops get enabled by default and must be disabled by hand, if needed + + +# BEGIN Customizations +# BEGIN Layout +# only before, enforcing also after adds too many blank lines +Layout/EmptyLinesAroundAccessModifier: + EnforcedStyle: only_before # default: around + +# indent first element one level deeper than the 'parent' +Layout/FirstArrayElementIndentation: + EnforcedStyle: consistent # default: special_inside_parentheses + +# indent first element one level deeper than the 'parent' +Layout/FirstHashElementIndentation: + EnforcedStyle: consistent # default: special_inside_parentheses + +# every screen should be able to handle 150 characters +Layout/LineLength: + Max: 150 # default: 120 + +# indent each method call one level deeper than the 'parent' +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented # default: aligned +# END Layout + + +# BEGIN Metrics +# too restrictive, this kind of high complexity is needed at times +Metrics/AbcSize: + Enabled: false + +# default is too restrictive, however, having some restriction incentivizes to use helper methods +Metrics/BlockLength: + AllowedMethods: ['class_eval', 'module_eval', 'refine'] # default: 'refine' + CountAsOne: &array_hash_heredoc_method_call ['array', 'hash', 'heredoc', 'method_call'] # default: [] + Exclude: &test_config_db ['test/**/*', 'config/**/*', 'db/**/*'] + +# default is too restrictive, having some restriction incentivizes to split up overly large classes +Metrics/ClassLength: + CountAsOne: *array_hash_heredoc_method_call # default: [] + Max: 200 # default: 100 + Exclude: *test_config_db + +# default is too restrictive, allow higher complexity +Metrics/CyclomaticComplexity: + Max: 14 # default: 7 + +# default is too restrictive, allow longer methods +Metrics/MethodLength: + CountAsOne: *array_hash_heredoc_method_call # default: [] + Max: 30 # default: 10 + Exclude: *test_config_db + +# default is too restrictive, allow longer modules +Metrics/ModuleLength: + CountAsOne: *array_hash_heredoc_method_call # default: [] + Max: 200 # default: 100 + Exclude: *test_config_db + +# long parameter lists add too much complexity, keyword args are named and thus more obvious what is expected, ignore them +Metrics/ParameterLists: + CountKeywordArgs: false # default: true + +# default is too restrictive, allow higher complexity +Metrics/PerceivedComplexity: + Max: 16 # default: 8 +# END Metrics + + +# BEGIN Style +# prefer compact style, since Zeitwerk handles initialization of modules +Style/ClassAndModuleChildren: + EnforcedStyle: compact # default: nested + Exclude: ['config/application.rb'] + +# documentation of classes in migrations and tests is not needed +Style/Documentation: + Exclude: *test_config_db + +# allow in auto-generated files +Style/GlobalStdStream: + Exclude: *test_config_db + +# allow empty parentheses to differentiate method calls vs attributes +Style/MethodCallWithoutArgsParentheses: + Enabled: false + +# explicit returns are nice and convey meaning, so allow them +Style/RedundantReturn: + Enabled: false + +# allow for explicit calls to self to help differentiate between method calls vs local variables +Style/RedundantSelf: + Enabled: false + +# enforce double quotes in string literals +Style/StringLiterals: + EnforcedStyle: double_quotes # default: single_quotes + +# enforce double quotes inside string interpolations +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes # default: single_quotes + +# allow only brackets, not %i or %I +Style/SymbolArray: + EnforcedStyle: brackets # default: percent + MinSize: 1 # default: 2 + +# allow only brackets, not %w or %W +Style/WordArray: + EnforcedStyle: brackets # default: percent + MinSize: 1 # default: 2 +# END Style diff --git a/rails/rubocop-inherit.yml b/rails/rubocop/rubocop-inherit.yml similarity index 100% rename from rails/rubocop-inherit.yml rename to rails/rubocop/rubocop-inherit.yml diff --git a/rails/rubocop/rubocop-minitest.yml b/rails/rubocop/rubocop-minitest.yml new file mode 100644 index 0000000000000000000000000000000000000000..575b66fd716267e4c311fb4a3005ba844938e789 --- /dev/null +++ b/rails/rubocop/rubocop-minitest.yml @@ -0,0 +1,19 @@ +require: + - rubocop-minitest + +# gem 'rubocop', '1.65.1', require: false +# gem 'rubocop-minitest', '0.35.1', require: false +AllCops: + NewCops: enable # pending cops get enabled by default and must be disabled by hand, if needed + + +# BEGIN Customizations +# BEGIN Minitest +# seems kind of buggy, when a custom message is given, this is flagged +Minitest/AssertWithExpectedArgument: + Enabled: false + +# allow more assertions than default, but also not too many +Minitest/MultipleAssertions: + Max: 8 # default: 3 +# END Minitest diff --git a/rails/rubocop/rubocop-rails.yml b/rails/rubocop/rubocop-rails.yml new file mode 100644 index 0000000000000000000000000000000000000000..00e5f1b71d6ff53be568538d29e412e74be22363 --- /dev/null +++ b/rails/rubocop/rubocop-rails.yml @@ -0,0 +1,39 @@ +require: + - rubocop-rails + +# gem 'rubocop', '1.65.1', require: false +# gem 'rubocop-rails', '2.25.1', require: false +AllCops: + NewCops: enable # pending cops get enabled by default and must be disabled by hand, if needed + + +# BEGIN Customizations +# BEGIN Rails +# file paths should be built with arguments instead of a single string +Rails/ApplicationController: + Exclude: ['app/controllers/api/**/*', 'app/controllers/a_p_i/**/*'] # exclude API namespace, but not others (convention) + +# exclude migrations since non-ApplicationRecord behavior might be desired +Rails/ApplicationRecord: + Exclude: ['db/migrate/*'] + +# ensure paths are built using a filesystem agnostic way, i.e. arguments instead of a single string +Rails/FilePath: + EnforcedStyle: arguments # default: slashes + +# no reason not to use an established Rails feature if developers see fit +Rails/HasAndBelongsToMany: + Enabled: false + +# prevent puts, but exclude test, config, db since Rails Logger may not have been loaded +Rails/Output: + Exclude: *test_config_db + +# allow usage of methods that skip validations; we trust developers know what they are doing +Rails/SkipsModelValidations: + Enabled: false + +# allow usage of three-state boolean columns, it may be an STI table +Rails/ThreeStateBooleanColumn: + Enabled: false +# END Rails