From 5ba04235bb8bb123a959d110efa4fe1601633388 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 11:42:44 +0900 Subject: [PATCH] Performance/RegexpMatch-20240219233128 (#918) * :police_car: regenerate rubocop todo * :police_car: Performance/RegexpMatch * :police_car: regenerate rubocop todo --------- Co-authored-by: Rubocop Challenger Co-authored-by: Mathieu Jobin <99191+mathieujobin@users.noreply.github.com> --- .rubocop_todo.yml | 40 +++++++++++++--------------------- lib/apipie/extractor/writer.rb | 12 +++++----- lib/apipie/helpers.rb | 2 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ae394a828..2ae339f34 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 200` -# on 2023-10-11 12:02:42 UTC using RuboCop version 1.57.0. +# `rubocop --auto-gen-config --exclude-limit 180` +# on 2024-02-19 23:31:58 UTC using RuboCop version 1.60.2. # 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 @@ -154,7 +154,7 @@ Layout/EmptyLineBetweenDefs: - 'spec/dummy/app/controllers/pets_using_auto_views_controller.rb' - 'spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb' -# Offense count: 56 +# Offense count: 55 # This cop supports safe autocorrection (--autocorrect). Layout/EmptyLines: Exclude: @@ -192,7 +192,7 @@ Layout/EmptyLinesAroundAttributeAccessor: Exclude: - 'lib/apipie/configuration.rb' -# Offense count: 92 +# Offense count: 91 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, no_empty_lines @@ -213,7 +213,6 @@ Layout/EmptyLinesAroundBlockBody: - 'spec/lib/apipie/extractor/writer_spec.rb' - 'spec/lib/apipie/file_handler_spec.rb' - 'spec/lib/apipie/generator/swagger/param_description/composite_spec.rb' - - 'spec/lib/apipie/generator/swagger/param_description/type_spec.rb' - 'spec/lib/apipie/param_description_spec.rb' - 'spec/lib/apipie/param_group_spec.rb' - 'spec/lib/apipie/validator_spec.rb' @@ -454,7 +453,7 @@ Layout/SpaceAfterColon: Exclude: - 'spec/dummy/app/controllers/included_param_group_controller.rb' -# Offense count: 42 +# Offense count: 41 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceAfterComma: Exclude: @@ -490,8 +489,9 @@ Layout/SpaceAfterNot: # Offense count: 142 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals. # SupportedStylesForExponentOperator: space, no_space +# SupportedStylesForRationalLiterals: space, no_space Layout/SpaceAroundOperators: Exclude: - 'app/controllers/apipie/apipies_controller.rb' @@ -726,21 +726,18 @@ Lint/UnderscorePrefixedVariableName: - 'lib/apipie/application.rb' - 'lib/apipie/dsl_definition.rb' -# Offense count: 26 +# Offense count: 22 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: - 'lib/apipie/configuration.rb' - - 'lib/apipie/extractor/collector.rb' - - 'lib/apipie/extractor/recorder.rb' - 'lib/apipie/param_description.rb' - 'lib/apipie/resource_description.rb' - 'lib/apipie/rspec/response_validation_helper.rb' - 'lib/tasks/apipie.rake' - 'spec/controllers/users_controller_spec.rb' - 'spec/lib/apipie/apipies_controller_spec.rb' - - 'spec/lib/apipie/extractor_spec.rb' - 'spec/lib/swagger/swagger_dsl_spec.rb' - 'spec/spec_helper.rb' @@ -802,7 +799,7 @@ Metrics/MethodLength: Metrics/ModuleLength: Max: 119 -# Offense count: 4 +# Offense count: 5 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: MaxOptionalParameters: 5 @@ -917,13 +914,6 @@ Performance/RedundantMerge: - 'lib/apipie/generator/swagger/param_description/type.rb' - 'lib/apipie/middleware/checksum_in_headers.rb' -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -Performance/RegexpMatch: - Exclude: - - 'lib/apipie/extractor/writer.rb' - - 'lib/apipie/helpers.rb' - # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). Performance/StringIdentifierArgument: @@ -974,7 +964,7 @@ RSpec/BeforeAfterAll: Exclude: - 'spec/controllers/users_controller_spec.rb' -# Offense count: 53 +# Offense count: 54 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: @@ -1141,7 +1131,7 @@ RSpec/MessageSpies: RSpec/MultipleExpectations: Max: 19 -# Offense count: 160 +# Offense count: 163 # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 15 @@ -1166,7 +1156,7 @@ RSpec/NamedSubject: - 'spec/lib/swagger/rake_swagger_spec.rb' - 'spec/lib/swagger/swagger_dsl_spec.rb' -# Offense count: 96 +# Offense count: 97 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 6 @@ -1293,7 +1283,7 @@ Rails/NegateInclude: - 'lib/apipie/extractor/writer.rb' - 'spec/spec_helper.rb' -# Offense count: 7 +# Offense count: 6 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Include. # Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb @@ -1921,7 +1911,7 @@ Style/StringConcatenation: - 'lib/apipie/application.rb' - 'lib/apipie/extractor/writer.rb' -# Offense count: 1214 +# Offense count: 1229 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -2021,7 +2011,7 @@ Style/TrailingCommaInArrayLiteral: - 'spec/controllers/users_controller_spec.rb' - 'spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb' -# Offense count: 4 +# Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma diff --git a/lib/apipie/extractor/writer.rb b/lib/apipie/extractor/writer.rb index 0583c6c0a..5affea849 100644 --- a/lib/apipie/extractor/writer.rb +++ b/lib/apipie/extractor/writer.rb @@ -324,7 +324,7 @@ def generate_apis_code(apis) desc ||= case @action.to_s when "show", "create", "update", "destroy" name = name.singularize - "#{@action.capitalize} #{name =~ /^[aeiou]/ ? 'an' : 'a'} #{name}" + "#{@action.capitalize} #{/^[aeiou]/.match?(name) ? 'an' : 'a'} #{name}" when "index" "List #{name}" end @@ -341,7 +341,7 @@ def generate_params_code(params, indent = "") params.sort_by {|n,_| n }.each do |(name, desc)| desc[:type] = (desc[:type] && desc[:type].first) || Object code << "#{indent}param" - if name =~ /\W/ + if /\W/.match?(name) code << " :'#{name}'" else code << " :#{name}" @@ -397,7 +397,7 @@ def lines_above_method lines_to_add = [] block_level = 0 ensure_line_breaks(controller_content.lines).first(action_line).reverse_each do |line| - if line =~ /\s*\bend\b\s*/ + if /\s*\bend\b\s*/.match?(line) block_level += 1 end if block_level > 0 @@ -405,10 +405,10 @@ def lines_above_method else added_lines << line end - if line =~ /\s*\b(module|class|def)\b / + if /\s*\b(module|class|def)\b /.match?(line) break end - next unless line =~ /do\s*(\|.*?\|)?\s*$/ + next unless /do\s*(\|.*?\|)?\s*$/.match?(line) block_level -= 1 if block_level == 0 added_lines.concat(lines_to_add) @@ -426,7 +426,7 @@ def lines_above_method # https://github.com/puppetlabs/puppet/blob/0dc44695/lib/puppet/util/monkey_patches.rb def ensure_line_breaks(lines) if lines.to_a.size > 1 && lines.first !~ /\n\Z/ - lines.map { |l| l !~ /\n\Z/ ? (l << "\n") : l }.to_enum + lines.map { |l| !/\n\Z/.match?(l) ? (l << "\n") : l }.to_enum else lines end diff --git a/lib/apipie/helpers.rb b/lib/apipie/helpers.rb index b5227d800..f5d8b054e 100644 --- a/lib/apipie/helpers.rb +++ b/lib/apipie/helpers.rb @@ -27,7 +27,7 @@ def full_url(path) end path = path.sub(%r{^/},"") ret = "#{@url_prefix}/#{path}" - ret.insert(0,"/") unless ret =~ %r{\A[./]} + ret.insert(0,"/") unless %r{\A[./]}.match?(ret) ret.sub!(%r{/*\Z},"") ret end