Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occurred while Style/Next cop was inspecting #10939

Closed
Zopolis4 opened this issue Aug 19, 2022 · 3 comments · Fixed by #10942
Closed

An error occurred while Style/Next cop was inspecting #10939

Zopolis4 opened this issue Aug 19, 2022 · 3 comments · Fixed by #10942
Labels

Comments

@Zopolis4
Copy link

An error occurred while Style/Next cop was inspecting /home/zopolis4/chromebrew/lib/package.rb:88:19.
Parser::Source::TreeRewriter detected clobbering
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter.rb:427:in `trigger_policy'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter.rb:414:in `enforce_policy'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:233:in `call'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:233:in `swallow'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:97:in `with'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:124:in `place_in_hierarchy'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:106:in `do_combine'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:117:in `place_in_hierarchy'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:106:in `do_combine'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:117:in `place_in_hierarchy'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:106:in `do_combine'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter/action.rb:30:in `combine'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter.rb:400:in `combine'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter.rb:207:in `wrap'
/var/lib/gems/3.0.0/gems/parser-3.1.2.1/lib/parser/source/tree_rewriter.rb:231:in `insert_before'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:231:in `reindent_line'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:210:in `block in reindent'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:210:in `each'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:210:in `reindent'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:167:in `autocorrect_block'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:93:in `block in check'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/base.rb:346:in `correct'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/base.rb:127:in `add_offense'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:89:in `check'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/style/next.rb:71:in `on_block'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:98:in `each'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:69:in `on_block'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:158:in `block in on_send'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:155:in `each'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:155:in `each_with_index'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:155:in `on_send'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:134:in `on_lvasgn'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_lvasgn'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `each'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:160:in `on_defs'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_defs'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `each'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:153:in `on_class'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `each'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/var/lib/gems/3.0.0/gems/rubocop-ast-1.21.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cop/team.rb:83:in `investigate'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:311:in `inspect_file'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:255:in `block in do_inspection_loop'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:289:in `block in iterate_until_no_changes'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:282:in `loop'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:282:in `iterate_until_no_changes'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:251:in `do_inspection_loop'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:134:in `block in file_offenses'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:159:in `file_offense_cache'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:133:in `file_offenses'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:69:in `block in warm_cache'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:587:in `call_with_index'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:557:in `process_incoming_jobs'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:537:in `block in worker'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:528:in `fork'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:528:in `worker'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:519:in `block in create_workers'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:518:in `each'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:518:in `each_with_index'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:518:in `create_workers'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:457:in `work_in_processes'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:294:in `map'
/var/lib/gems/3.0.0/gems/parallel-1.22.1/lib/parallel.rb:238:in `each'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:69:in `warm_cache'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/runner.rb:46:in `run'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli/command.rb:11:in `run'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli/environment.rb:18:in `run'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli.rb:72:in `run_command'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli.rb:79:in `execute_runners'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/lib/rubocop/cli.rb:48:in `run'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/exe/rubocop:19:in `block in <top (required)>'
/var/lib/gems/3.0.0/gems/benchmark-0.2.0/lib/benchmark.rb:311:in `realtime'
/var/lib/gems/3.0.0/gems/rubocop-1.35.0/exe/rubocop:19:in `<top (required)>'
/usr/local/bin/rubocop:25:in `load'
/usr/local/bin/rubocop:25:in `<main>'

The aforementioned line of code:

expandedDeps = deps.uniq.map do |dep, depTags|

RuboCop version

1.35.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.0.4 x86_64-linux-gnu)
@koic
Copy link
Member

koic commented Aug 19, 2022

It seems that part of the reproduction code is missing. Can you provide a complete parseable reproduction code?

@Zopolis4
Copy link
Author

 def self.get_deps_list(pkgName = name, hash: false, include_build_deps: 'auto', include_self: false,
                         pkgTags: [], highlight_build_deps: true, exclude_buildessential: false, top_level: true)
    # get_deps_list: get dependencies list of pkgName (current package by default)
    #
    #                pkgName: package to check dependencies, current package by default
    #                   hash: return result in nested hash, used by `print_deps_tree` (`bin/crew`)
    #
    #     include_build_deps: if set to true, force all build dependencies to be returned.
    #                         if set to false, all build dependencies will not be returned
    #                         if set to "auto" (default), return build dependencies if pre-built binaries not available
    #
    #           include_self: include #{pkgName} itself in returned result, only used in recursive calls (see `expandedDeps` below)
    #   highlight_build_deps: include corresponding symbols in return value, you can convert it to actual ascii color codes later
    # exclude_buildessential: do not insert `buildessential` dependency automatically
    #
    #              top_level: if set to true, return satisfied dependencies
    #                         (dependencies that might be a sub-dependency of a dependency that checked before),
    #                         always set to false if this function is called in recursive loop (see `expandedDeps` below)
    #
    @checked_list ||= {} # create @checked_list placeholder if not exist

    # add current package to @checked_list for preventing extra checks
    @checked_list.merge!({ pkgName => pkgTags })

    pkgObj = load_package("#{CREW_PACKAGES_PATH}/#{pkgName}.rb")
    is_source = pkgObj.is_source?(ARCH.to_sym) or pkgObj.build_from_source
    deps = pkgObj.dependencies

    # append buildessential to deps if building from source is needed/specified
    if ((include_build_deps == true) || ((include_build_deps == 'auto') && is_source)) && \
       !pkgObj.no_compile_needed? && \
       !exclude_buildessential && \
       !@checked_list.keys.include?('buildessential')

      deps = { 'buildessential' => [:build] }.merge(deps)
    end

    # parse dependencies recursively
    expandedDeps = deps.uniq.map do |dep, depTags|
      # check build dependencies only if building from source is needed/specified
      if (include_build_deps == true) || \
         ((include_build_deps == 'auto') && is_source) || \
         !depTags.include?(:build)

        # overwrite tags if parent dependency is a build dependency
        # (for build dependencies highlighting)
        tags = pkgTags.include?(:build) ? pkgTags : depTags

        if @checked_list.keys.none?(dep)
          # check dependency by calling this function recursively
          next send(__method__, dep,
                    hash: hash,
                 pkgTags: tags,
      include_build_deps: include_build_deps,
    highlight_build_deps: highlight_build_deps,
  exclude_buildessential: exclude_buildessential,
            include_self: true,
               top_level: false)

        elsif hash && top_level
          # will be dropped here if current dependency is already checked and #{top_level} is set to true
          #
          # the '+' symbol tell `print_deps_tree` (`bin/crew`) to color this package as "satisfied dependency"
          # the '*' symbol tell `print_deps_tree` (`bin/crew`) to color this package as "build dependency"
          if highlight_build_deps && tags.include?(:build)
            next { "+*#{dep}*+" => [] }
          elsif highlight_build_deps
            next { "+#{dep}+" => [] }
          else
            next { dep => [] }
          end
        end
      end
    end.compact

    if hash
      # the '*' symbol tell `print_deps_tree` (`bin/crew`) to color this package as "build dependency"
      if highlight_build_deps && pkgTags.include?(:build)
        return { "*#{pkgName}*" => expandedDeps }
      else
        return { pkgName => expandedDeps }
      end
    elsif include_self
      # return pkgName itself if this function is called as a recursive loop (see `expandedDeps`)
      return [expandedDeps, pkgName].flatten
    else
      # if this function is called outside of this function, return parsed dependencies only
      return expandedDeps.flatten
    end
  end

  boolean_property.each do |prop|
    self.class.__send__(:attr_reader, prop.to_s)
    class_eval <<~EOT, __FILE__, __LINE__ + 1
      def self.#{prop} (#{prop} = nil)
        @#{prop} = true if #{prop}
        !!@#{prop}
      end
    EOT
    instance_eval <<~EOY, __FILE__, __LINE__ + 1
      def self.#{prop}
        @#{prop} = true
      end
    EOY
    # Adds the symbol? method
    define_singleton_method("#{prop}?") do
      @prop = instance_variable_get("@#{prop}")
      !!@prop
    end
  end

@koic koic added the bug label Aug 19, 2022
@Zopolis4
Copy link
Author

I've narrowed it down to this:

foo = map do |dep|
  if ((true == true) || \
     !frob.include?) && @test.keys?
    next send(dep,
              hash: hash,
test: test)
  end
end.compact

koic added a commit to koic/rubocop that referenced this issue Aug 21, 2022
Fixes rubocop#10939.

This PR fixes an error for `Style/Next` when line break before condition.
The removed indentation logic can be delegated to `Layout/IndentationConsistency`.
bbatsov pushed a commit that referenced this issue Aug 22, 2022
Fixes #10939.

This PR fixes an error for `Style/Next` when line break before condition.
The removed indentation logic can be delegated to `Layout/IndentationConsistency`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants