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

RSpec/VariableName: Would appreciate an 'ignore' configuration option #941

Closed
jtannas opened this issue Jun 18, 2020 · 1 comment · Fixed by #987
Closed

RSpec/VariableName: Would appreciate an 'ignore' configuration option #941

jtannas opened this issue Jun 18, 2020 · 1 comment · Fixed by #987

Comments

@jtannas
Copy link
Contributor

jtannas commented Jun 18, 2020

Feature Request
A configuration option to specify certain variables or patterns to ignore

Example

RSpec/VariableName:
  Enabled: true
  EnforcedStyle: "snake_case"
  IgnoreVariables:
    - fooBar
    - /fizzBuzz/

Context
We use an RSpec plugin called RSwag that allows the creation of specs & swagger documentation from a single DSL. One of the features is that documented parameters can be populated in tests via let statements

eg.

describe 'Blogs API - Individual Blog Endpoint' do
  path '/blogs/{id}' do
	parameter(name: :id, in: :path, required: true, type: :string)
    let(:id) { 'foo' }
	# test code ensues
  end
end

The issue arises when providing an array as a query parameter

describe 'Blogs API - Blog Collection Endpoint' do
  path '/blogs' do
    # making a request to /blogs?id[]=foo&id[]=bar&id[]=baz
    parameter(
      name: :'id[]',
      in: :query,
      required: false,
      type: :array,
      items: { type: :string },
      collectionFormat: :multi,
    )
    let(:'id[]') { ['foo', 'bar', 'baz'] } # sets off the cop
    # test code ensues
  end
end 

It's way too much of a corner case to modify the cop to ignore that specific pattern, but I think a generic option to ignore certain things by name or regex is appropriate.

@pirj
Copy link
Member

pirj commented Jun 20, 2020

That's quite a strange name for a variable defined with let, but I guess it fits RSwag's style.
With an empty default Ignore: setting it is welcome, so is a pull request.

bquorning added a commit that referenced this issue Aug 7, 2020
…onfig

[Fix #941] Add support for ignoring certain variables in RSpec/VariableName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants