diff --git a/Gemfile.lock b/Gemfile.lock index 58134b9e..7eef2b3f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,7 @@ PATH specs: rubocop-shopify (3.0.2) lint_roller - rubocop (~> 1.72, >= 1.72.1) + rubocop (~> 1.89) GEM remote: https://rubygems.org/ @@ -63,7 +63,7 @@ GEM jekyll (>= 3.8, < 5.0) jekyll-watch (2.2.1) listen (~> 3.0) - json (2.21.1) + json (2.21.2) kramdown (2.5.2) rexml (>= 3.4.4) kramdown-parser-gfm (1.1.0) @@ -81,7 +81,7 @@ GEM drb (~> 2.0) prism (~> 1.5) parallel (2.1.0) - parser (3.3.11.1) + parser (3.3.12.0) ast (~> 2.4.1) racc pathutil (0.16.2) @@ -97,7 +97,7 @@ GEM regexp_parser (2.12.0) rexml (3.4.4) rouge (4.7.0) - rubocop (1.88.2) + rubocop (1.89.0) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -111,7 +111,7 @@ GEM rubocop-ast (1.50.0) parser (>= 3.3.7.2) prism (~> 1.7) - rubocop-minitest (0.39.1) + rubocop-minitest (0.40.0) lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.38.0, < 2.0) diff --git a/dev.yml b/dev.yml index 96327e43..ee30f733 100644 --- a/dev.yml +++ b/dev.yml @@ -8,5 +8,5 @@ test: bundle exec rake commands: dump-config: - description: Dump the full RuboCop config as a YAML file for testing + desc: Dump the full RuboCop config as a YAML file for testing run: bundle exec rake config:dump diff --git a/lib/rubocop-shopify.rb b/lib/rubocop-shopify.rb index 4ebc1e1a..b486ff73 100644 --- a/lib/rubocop-shopify.rb +++ b/lib/rubocop-shopify.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true +require "rubocop" require "rubocop/shopify/version" require "rubocop/shopify/plugin" -require "rubocop/cop/lint/no_return_in_memoization" -require "rubocop/cop/style/proc_case_when" +RuboCop::Cop::Lint.register_cop :NoReturnInMemoization, "#{__dir__}/rubocop/cop/lint/no_return_in_memoization" +RuboCop::Cop::Style.register_cop :ProcCaseWhen, "#{__dir__}/rubocop/cop/style/proc_case_when" diff --git a/lib/tasks/config.rake b/lib/tasks/config.rake index ace7badd..f294f45b 100644 --- a/lib/tasks/config.rake +++ b/lib/tasks/config.rake @@ -8,6 +8,16 @@ namespace :config do file = "rubocop.yml" target = args.fetch(:target, "test/fixtures/full_config.yml") + # Reset the default configuration and loaded plugins so that plugins loaded + # as side effects of running tests (e.g. rubocop-minitest's + # AssertOffense#integrate_plugins!) do not leak into the dump. Without this, + # integrate_plugins! injects all installed lint_roller plugins into the + # global default_configuration, and a prior load_file("rubocop.yml") marks + # rubocop-shopify as already loaded so resolve_plugins skips re-injecting it + # after the reset. Both are lazily rebuilt on the next access. + RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, nil) + RuboCop::ConfigLoader.loaded_plugins.clear + file_config = RuboCop::ConfigLoader.load_file(file) config = RuboCop::ConfigLoader.merge_with_default(file_config, file) output = config.to_h.to_yaml.gsub(config.base_dir_for_path_parameters, "") diff --git a/rubocop-shopify.gemspec b/rubocop-shopify.gemspec index 4586b145..5da37f56 100644 --- a/rubocop-shopify.gemspec +++ b/rubocop-shopify.gemspec @@ -29,6 +29,6 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 3.3.0" - s.add_dependency("rubocop", "~> 1.72", ">= 1.72.1") + s.add_dependency("rubocop", "~> 1.89") s.add_dependency("lint_roller") end diff --git a/rubocop.yml b/rubocop.yml index 9106c728..6cbb9a70 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -23,10 +23,8 @@ Bundler/OrderedGems: Gemspec/AddRuntimeDependency: Enabled: false -<% if rubocop_version >= '1.77' %> Gemspec/AttributeAssignment: Enabled: true -<% end %> Gemspec/DeprecatedAttributeAssignment: Enabled: true @@ -79,10 +77,8 @@ Layout/EmptyLineAfterGuardClause: Layout/EmptyLines: Enabled: false -<% if rubocop_version >= '1.79' %> Layout/EmptyLinesAfterModuleInclusion: Enabled: false -<% end %> Layout/EndAlignment: Enabled: false @@ -210,14 +206,15 @@ Lint/ConstantReassignment: Lint/CopDirectiveSyntax: Enabled: true -<% if rubocop_version >= "1.85" %> Lint/DataDefineOverride: Enabled: true -<% end %> Lint/DeprecatedConstants: Enabled: false +Lint/DeprecatedReference: + Enabled: false + Lint/DuplicateBranch: Enabled: false @@ -302,6 +299,9 @@ Lint/MixedCaseRange: Lint/MixedRegexpCaptureTypes: Enabled: false +Lint/NameTypo: + Enabled: false + Lint/NoReturnInBeginEndBlocks: Enabled: false @@ -392,11 +392,6 @@ Lint/ShadowedArgument: Lint/ShadowedException: Enabled: false -<% if rubocop_version < "1.76" %> -Lint/ShadowingOuterLocalVariable: - Enabled: false -<% end %> - Lint/SharedMutableDefault: Enabled: false @@ -445,10 +440,8 @@ Lint/UnreachableCode: Lint/UnreachableLoop: Enabled: false -<% if rubocop_version >= "1.85" %> Lint/UnreachablePatternBranch: Enabled: true -<% end %> Lint/UnusedBlockArgument: Enabled: false @@ -471,10 +464,8 @@ Lint/UselessAssignment: Lint/UselessConstantScoping: Enabled: false -<% if rubocop_version >= "1.76" %> Lint/UselessDefaultValueArgument: Enabled: true -<% end %> Lint/UselessDefined: Enabled: false @@ -488,10 +479,8 @@ Lint/UselessMethodDefinition: Lint/UselessNumericOperation: Enabled: false -<% if rubocop_version >= "1.76" %> Lint/UselessOr: Enabled: true -<% end %> Lint/UselessRescue: Enabled: false @@ -563,16 +552,10 @@ Naming/MemoizedInstanceVariableName: Naming/MethodParameterName: MinNameLength: 1 -<% if rubocop_version >= "1.76" %> Naming/PredicateMethod: Enabled: false -<% end %> -<% if rubocop_version >= "1.76" %> Naming/PredicatePrefix: -<% else %> -Naming/PredicateName: -<% end %> Enabled: false NamePrefix: - is_ @@ -632,10 +615,8 @@ Style/ArrayCoercion: Style/ArrayIntersect: Enabled: false -<% if rubocop_version >= '1.81' %> Style/ArrayIntersectWithSingleElement: Enabled: false -<% end %> Style/ArrayJoin: Enabled: false @@ -679,10 +660,8 @@ Style/ClassMethodsDefinitions: Style/CollectionCompact: Enabled: false -<% if rubocop_version >= '1.77' %> Style/CollectionQuerying: Enabled: false -<% end %> Style/CombinableDefined: Enabled: true @@ -700,10 +679,8 @@ Style/CommentAnnotation: Style/CommentedKeyword: Enabled: false -<% if rubocop_version >= "1.74" %> Style/ComparableBetween: Enabled: false -<% end %> Style/ComparableClamp: Enabled: false @@ -750,10 +727,8 @@ Style/EmptyBlockParameter: Style/EmptyCaseCondition: Enabled: false -<% if rubocop_version >= "1.84" %> Style/EmptyClassDefinition: Enabled: false -<% end %> Style/EmptyElse: Enabled: false @@ -771,10 +746,8 @@ Style/EmptyLiteral: Style/EmptyMethod: Enabled: false -<% if rubocop_version >= "1.76" %> Style/EmptyStringInsideInterpolation: Enabled: false -<% end %> Style/Encoding: Enabled: false @@ -815,10 +788,8 @@ Style/FileEmpty: Style/FileNull: Enabled: false -<% if rubocop_version >= "1.85" %> Style/FileOpen: Enabled: false -<% end %> Style/FileRead: Enabled: false @@ -866,10 +837,8 @@ Style/HashEachMethods: Style/HashExcept: Enabled: false -<% if rubocop_version >= "1.75" %> Style/HashFetchChain: Enabled: false -<% end %> Style/HashLikeCase: Enabled: false @@ -913,10 +882,8 @@ Style/InverseMethods: Style/ItAssignment: Enabled: false -<% if rubocop_version >= "1.75" %> Style/ItBlockParameter: Enabled: false -<% end %> Style/KeywordArgumentsMerging: Enabled: false @@ -943,10 +910,8 @@ Style/MapCompactWithConditionalBlock: Style/MapIntoArray: Enabled: false -<% if rubocop_version >= "1.85" %> Style/MapJoin: Enabled: true -<% end %> Style/MapToHash: Enabled: false @@ -987,10 +952,8 @@ Style/ModuleFunction: Enabled: false EnforcedStyle: extend_self -<% if rubocop_version >= "1.82" %> Style/ModuleMemberExistenceCheck: Enabled: true -<% end %> Style/MultilineBlockChain: Enabled: false @@ -1028,10 +991,8 @@ Style/NegatedUnless: Style/NegatedWhile: Enabled: false -<% if rubocop_version >= "1.84" %> Style/NegativeArrayIndex: Enabled: true -<% end %> Style/NestedFileDirname: Enabled: false @@ -1078,10 +1039,8 @@ Style/NumericPredicate: Style/ObjectThen: Enabled: false -<% if rubocop_version >= "1.85" %> Style/OneClassPerFile: Enabled: false -<% end %> Style/OneLineConditional: Enabled: false @@ -1107,10 +1066,8 @@ Style/ParallelAssignment: Style/ParenthesesAroundCondition: Enabled: false -<% if rubocop_version >= "1.85" %> Style/PartitionInsteadOfDoubleSelect: Enabled: false -<% end %> Style/PercentLiteralDelimiters: Enabled: false @@ -1121,10 +1078,8 @@ Style/PercentQLiterals: Style/PerlBackrefs: Enabled: false -<% if rubocop_version >= "1.85" %> Style/PredicateWithKind: Enabled: false -<% end %> Style/PreferredHashMethods: Enabled: false @@ -1141,10 +1096,8 @@ Style/RaiseArgs: Style/RandomWithOffset: Enabled: false -<% if rubocop_version >= "1.85" %> Style/ReduceToHash: Enabled: true -<% end %> Style/RedundantArgument: Enabled: false @@ -1152,10 +1105,8 @@ Style/RedundantArgument: Style/RedundantArrayConstructor: Enabled: false -<% if rubocop_version >= "1.76" %> Style/RedundantArrayFlatten: Enabled: true -<% end %> Style/RedundantAssignment: Enabled: false @@ -1211,10 +1162,8 @@ Style/RedundantInterpolationUnfreeze: Style/RedundantLineContinuation: Enabled: false -<% if rubocop_version >= "1.85" %> Style/RedundantMinMaxBy: Enabled: true -<% end %> Style/RedundantParentheses: Enabled: false @@ -1265,10 +1214,8 @@ Style/RescueStandardError: Style/ReturnNilInPredicateMethodDefinition: Enabled: false -<% if rubocop_version >= "1.84" %> Style/ReverseFind: Enabled: false -<% end %> Style/SafeNavigation: Enabled: false @@ -1279,15 +1226,11 @@ Style/SafeNavigationChainLength: Style/Sample: Enabled: false -<% if rubocop_version >= "1.85" %> Style/SelectByKind: Enabled: true -<% end %> -<% if rubocop_version >= "1.85" %> Style/SelectByRange: Enabled: true -<% end %> Style/SelectByRegexp: Enabled: false @@ -1359,10 +1302,8 @@ Style/SymbolArray: Style/SymbolProc: Enabled: false -<% if rubocop_version >= "1.85" %> Style/TallyMethod: Enabled: true -<% end %> Style/TernaryParentheses: Enabled: false diff --git a/test/fixtures/full_config.yml b/test/fixtures/full_config.yml index f1eb27ee..f8f042b1 100644 --- a/test/fixtures/full_config.yml +++ b/test/fixtures/full_config.yml @@ -68,6 +68,7 @@ AllCops: DisabledByDefault: false NewCops: disable UseProjectIndex: false + ProjectIndexIncludesGems: false UseCache: true MaxFilesInCache: 20000 CacheRootDirectory: @@ -95,6 +96,9 @@ AllCops: - factory_bot_rails rubocop-rspec_rails: - rspec-rails + rubocop-i18n: + - i18n + - gettext ActiveSupportExtensionsEnabled: false StringLiteralsFrozenByDefault: Bundler/DuplicatedGem: @@ -352,7 +356,7 @@ Layout/ClassStructure: Enabled: false SafeAutoCorrect: false VersionAdded: '0.52' - VersionChanged: '1.53' + VersionChanged: '1.89' Categories: module_inclusion: - include @@ -365,6 +369,7 @@ Layout/ClassStructure: - initializer - public_methods - protected_methods + - private_class_methods - private_methods Layout/ClosingHeredocIndentation: Description: Checks the indentation of here document closings. @@ -711,6 +716,7 @@ Layout/LeadingCommentSpace: AllowGemfileRubyComment: false AllowRBSInlineAnnotation: true AllowSteepAnnotation: false + AllowYARDCommentBlockSeparator: false Layout/LeadingEmptyLines: Description: Checks for unnecessary blank lines at the beginning of a file. Enabled: true @@ -1117,7 +1123,7 @@ Lint/AmbiguousBlockAssociation: without parentheses. Enabled: false VersionAdded: '0.48' - VersionChanged: '1.13' + VersionChanged: '1.89' AllowedMethods: [] AllowedPatterns: [] Lint/AmbiguousOperator: @@ -1198,6 +1204,7 @@ Lint/ConstantReassignment: VersionChanged: '1.87' Lint/ConstantResolution: Description: Checks that constants are fully qualified with `::`. + VersionChanged: '1.89' Enabled: false VersionAdded: '0.86' Only: [] @@ -1293,6 +1300,11 @@ Lint/DeprecatedOpenSSLConstant: Description: Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`. Enabled: true VersionAdded: '0.84' +Lint/DeprecatedReference: + Description: Checks for references to methods and constants documented as deprecated + with a YARD `@deprecated` tag. Requires `AllCops/UseProjectIndex` to be enabled. + Enabled: false + VersionAdded: '1.89' Lint/DisjunctiveAssignmentInConstructor: Description: In constructor, plain assignment is preferred over disjunctive. Enabled: true @@ -1333,6 +1345,9 @@ Lint/DuplicateMethods: Description: Checks for duplicate method definitions. Enabled: true VersionAdded: '0.29' + VersionChanged: '1.89' + DelegatingMethods: + - delegate Lint/DuplicateRegexpCharacterClassElement: Description: Checks for duplicate elements in Regexp character classes. Enabled: true @@ -1485,7 +1500,7 @@ Lint/InheritException: Enabled: false SafeAutoCorrect: false VersionAdded: '0.41' - VersionChanged: '1.26' + VersionChanged: '1.89' EnforcedStyle: standard_error SupportedStyles: - standard_error @@ -1539,7 +1554,7 @@ Lint/MissingSuper: calls to `super`. Enabled: false VersionAdded: '0.89' - VersionChanged: '1.4' + VersionChanged: '1.89' AllowedParentClasses: [] Lint/MixedCaseRange: Description: Checks for mixed-case character ranges since they include likely unintended @@ -1556,6 +1571,14 @@ Lint/MultipleComparison: Enabled: true VersionAdded: '0.47' VersionChanged: '1.1' +Lint/NameTypo: + Description: Checks for probable typos in constant and method names, using the project + index. + Enabled: false + CheckConstants: true + CheckMethods: true + AllowedNames: [] + VersionAdded: '1.89' Lint/NestedMethodDefinition: Description: Do not use nested method definitions. StyleGuide: "#no-nested-methods" @@ -1772,8 +1795,9 @@ Lint/ReturnInVoidContext: Lint/SafeNavigationChain: Description: Do not chain ordinary method call after safe navigation operator. Enabled: true + SafeAutoCorrect: false VersionAdded: '0.47' - VersionChanged: '0.77' + VersionChanged: '1.89' AllowedMethods: - present? - blank? @@ -1963,6 +1987,11 @@ Lint/UnusedMethodArgument: IgnoreNotImplementedMethods: true NotImplementedExceptions: - NotImplementedError +Lint/UnusedPrivateMethod: + Description: Checks for private instance methods that are not referenced anywhere + in the project. Requires `AllCops/UseProjectIndex` to be enabled. + Enabled: false + VersionAdded: '1.89' Lint/UriEscapeUnescape: Description: "`URI.escape` method is obsolete and should not be used. Instead, use `CGI.escape`, `URI.encode_www_form` or `URI.encode_www_form_component` depending @@ -2160,6 +2189,7 @@ Migration/DepartmentName: Naming/AccessorMethodName: Description: Checks the naming of accessor methods for get_/set_. StyleGuide: "#accessor_mutator_method_names" + VersionChanged: '1.89' Enabled: false VersionAdded: '0.50' Naming/AsciiIdentifiers: @@ -2384,7 +2414,7 @@ Naming/PredicatePrefix: StyleGuide: "#bool-methods-qmark" Enabled: false VersionAdded: '0.50' - VersionChanged: '1.75' + VersionChanged: '1.89' NamePrefix: - is_ ForbiddenPrefixes: @@ -2703,7 +2733,7 @@ Style/ClassAndModuleChildren: SafeAutoCorrect: false Enabled: false VersionAdded: '0.19' - VersionChanged: '1.74' + VersionChanged: '1.89' EnforcedStyle: nested SupportedStyles: - nested @@ -2929,8 +2959,9 @@ Style/DisableCopsWithinSourceCodeDirective: Description: Forbids disabling/enabling cops within source code. Enabled: false VersionAdded: '0.82' - VersionChanged: '1.9' + VersionChanged: '1.89' AllowedCops: [] + DisallowedCops: [] Style/DocumentDynamicEvalDefinition: Description: When using `class_eval` (or other `eval`) with string interpolation, add a comment block showing its appearance if interpolated. @@ -2942,6 +2973,7 @@ Style/Documentation: Description: Document classes and non-namespace modules. Enabled: false VersionAdded: '0.9' + VersionChanged: '1.89' AllowedConstants: [] Exclude: - "/spec/**/*" @@ -3622,6 +3654,7 @@ Style/MissingRespondToMissing: StyleGuide: "#no-method-missing" Enabled: false VersionAdded: '0.56' + VersionChanged: '1.89' Style/MixinGrouping: Description: Checks for grouping of mixins in `class` and `module` bodies. StyleGuide: "#mixin-grouping" @@ -4112,6 +4145,7 @@ Style/RedundantConditional: VersionAdded: '0.50' Style/RedundantConstantBase: Description: Avoid redundant `::` prefix on constant. + VersionChanged: '1.89' Enabled: false VersionAdded: '1.40' Style/RedundantCurrentDirectoryInPath: @@ -4473,6 +4507,7 @@ Style/StabbyLambdaParentheses: Style/StaticClass: Description: Prefer modules to classes with only class methods. StyleGuide: "#modules-vs-classes" + VersionChanged: '1.89' Enabled: false Safe: false VersionAdded: '1.3' diff --git a/test/rubocop/cop/lint/no_return_in_memoization_test.rb b/test/rubocop/cop/lint/no_return_in_memoization_test.rb index 5b87b434..e04135fe 100644 --- a/test/rubocop/cop/lint/no_return_in_memoization_test.rb +++ b/test/rubocop/cop/lint/no_return_in_memoization_test.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true require "test_helper" -require "rubocop/minitest/assert_offense" +require "rubocop/test_case" module RuboCop module Cop module Lint - class NoReturnInMemoizationTest < ::Minitest::Test - include ::RuboCop::Minitest::AssertOffense - + class NoReturnInMemoizationTest < TestCase def setup @cop = NoReturnInMemoization.new end diff --git a/test/rubocop/cop/style/proc_case_when_test.rb b/test/rubocop/cop/style/proc_case_when_test.rb index 9c1cb767..39ce497e 100644 --- a/test/rubocop/cop/style/proc_case_when_test.rb +++ b/test/rubocop/cop/style/proc_case_when_test.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true require "test_helper" -require "rubocop/minitest/assert_offense" +require "rubocop/test_case" module RuboCop module Cop module Style - class ProcCaseWhenTest < ::Minitest::Test - include ::RuboCop::Minitest::AssertOffense - + class ProcCaseWhenTest < TestCase MESSAGE = "Avoid a `case`/`when` where every `when` is a proc or value " \ "literal: each proc literal allocates a new `Proc` every time the " \ "`case` is evaluated and adds `Proc#call` overhead, and the whole " \