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

Error on multi-line regexp /.../x #7655

Closed
Tietew opened this issue Jan 17, 2020 · 0 comments · Fixed by #7656
Closed

Error on multi-line regexp /.../x #7655

Tietew opened this issue Jan 17, 2020 · 0 comments · Fixed by #7656
Labels

Comments

@Tietew
Copy link
Contributor

Tietew commented Jan 17, 2020

Error occurs with code below:

/(?:
  blah
)/x =~ blah

Works:

/(?:single_line)/ =~ blah
/
  no_capture
/x =~ blah

Expected behavior

No errors.

Actual behavior

An error occurred while VariableForce cop

Steps to reproduce the problem

$ ruby -vc test.rb
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
Syntax OK
$ bundle exec rubocop test.rb
For .../test/rubocop: configuration from .../test/rubocop/.rubocop.yml
Default configuration from .../gems/rubocop-0.79.0/config/default.yml
Inspecting 1 file
Scanning .../test/rubocop/test.rb
An error occurred while VariableForce cop was inspecting .../test/rubocop/test.rb.
end pattern with unmatched parenthesis: /(?:
/
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:194:in `initialize'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:194:in `new'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:194:in `regexp_captured_names'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:174:in `process_regexp_named_captures'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:86:in `process_node'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:103:in `block in process_children'
.../gems/rubocop-0.79.0/lib/rubocop/ast/node.rb:193:in `block in each_child_node'
.../gems/rubocop-0.79.0/lib/rubocop/ast/node.rb:190:in `each'
.../gems/rubocop-0.79.0/lib/rubocop/ast/node.rb:190:in `each_child_node'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:100:in `process_children'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:87:in `process_node'
.../gems/rubocop-0.79.0/lib/rubocop/cop/variable_force.rb:80:in `investigate'
.../gems/rubocop-0.79.0/lib/rubocop/cop/commissioner.rb:108:in `block (2 levels) in invoke_custom_processing'
.../gems/rubocop-0.79.0/lib/rubocop/cop/commissioner.rb:136:in `with_cop_error_handling'
.../gems/rubocop-0.79.0/lib/rubocop/cop/commissioner.rb:107:in `block in invoke_custom_processing'
.../gems/rubocop-0.79.0/lib/rubocop/cop/commissioner.rb:104:in `each'
.../gems/rubocop-0.79.0/lib/rubocop/cop/commissioner.rb:104:in `invoke_custom_processing'
.../gems/rubocop-0.79.0/lib/rubocop/cop/commissioner.rb:43:in `investigate'
.../gems/rubocop-0.79.0/lib/rubocop/cop/team.rb:124:in `investigate'
.../gems/rubocop-0.79.0/lib/rubocop/cop/team.rb:112:in `offenses'
.../gems/rubocop-0.79.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:296:in `inspect_file'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:244:in `block in do_inspection_loop'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:269:in `loop'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:240:in `do_inspection_loop'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:119:in `block in file_offenses'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:143:in `file_offense_cache'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:117:in `file_offenses'
.../gems/rubocop-0.79.0/lib/rubocop/runner.rb:108:in `process_file'
(snip)
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while VariableForce cop was inspecting .../test/rubocop/test.rb.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.79.0 (using Parser 2.7.0.2, running on ruby 2.6.5 x86_64-linux)
Finished in 0.10937485797330737 seconds

RuboCop version

$ [bundle exec] rubocop -V
0.79.0 (using Parser 2.7.0.2, running on ruby 2.6.5 x86_64-linux)
@koic koic added the bug label Jan 17, 2020
koic added a commit to koic/rubocop that referenced this issue Jan 24, 2020
Fixes rubocop#7655.

This PR fixes the following error when processing a regexp with a line
break at the start of capture parenthesis.

```console
% cat examle.rb
/(
  pattern
)/ =~ string

% bundle exec rubocop -d
(snip)

An error occurred while VariableForce cop was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/7655/examle.rb.
end pattern with unmatched parenthesis: /(
/
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:194:in
`initialize'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:194:in
`new'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:194:in
`regexp_captured_names'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:174:in
`process_regexp_named_captures'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:86:in
`process_node'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:80:in `investigate'
```
bbatsov pushed a commit that referenced this issue Jan 25, 2020
Fixes #7655.

This PR fixes the following error when processing a regexp with a line
break at the start of capture parenthesis.

```console
% cat examle.rb
/(
  pattern
)/ =~ string

% bundle exec rubocop -d
(snip)

An error occurred while VariableForce cop was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/7655/examle.rb.
end pattern with unmatched parenthesis: /(
/
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:194:in
`initialize'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:194:in
`new'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:194:in
`regexp_captured_names'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:174:in
`process_regexp_named_captures'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:86:in
`process_node'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/variable_force.rb:80:in `investigate'
```
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