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

Layout/IndentationConsistency confused with public methods declaration at the top level #9606

Closed
trambui09 opened this issue Mar 16, 2021 · 0 comments
Labels

Comments

@trambui09
Copy link

@trambui09 trambui09 commented Mar 16, 2021


Defined public on the top level, without being inside a class. But rubocop gives an error. Though if the file only has the one line that says "public" it doesn't error out.

error appears when:

public

def create_key_asymmetric_decrypt project_id:, location_id:, key_ring_id:, id:
  # [START kms_create_key_asymmetric_decrypt]
  # TODO(developer): uncomment these values before running the sample.
  # project_id  = "my-project"
  # location_id = "us-east1"
  # key_ring_id = "my-key-ring"
  # id          = "my-asymmetric-decrypt-key"

  # Require the library.
  require "google/cloud/kms"

  # Create the client.
  client = Google::Cloud::Kms.key_management_service

  # Build the parent key ring name.
  key_ring_name = client.key_ring_path project: project_id, location: location_id, key_ring: key_ring_id

  # Build the key.
  key = {
    purpose:          :ASYMMETRIC_DECRYPT,
    version_template: {
      algorithm: :RSA_DECRYPT_OAEP_2048_SHA256
    }
  }

  # Call the API.
  created_key = client.create_crypto_key parent: key_ring_name, crypto_key_id: id, crypto_key: key
  puts "Created asymmetric decryption key: #{created_key.name}"
  # [END kms_create_key_asymmetric_decrypt]

  created_key
end

no errors:

public

error:

public 

def test_method 
  puts "testing if it errors out"
end

Steps to reproduce the problem

file and code can be found here: https://github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-kms/samples/snippets.rb

RuboCop version

1.11.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.6.5 x86_64-darwin19)
@koic koic added the bug label Mar 16, 2021
koic added a commit to koic/rubocop that referenced this issue Mar 16, 2021
Fixes rubocop#9606.

This PR fixes the following error for `Layout/IndentationConsistency`
when using access modifier at the top level.

```console
% cat example.rb
public

def foo
end

% bundle exec rubocop --only Layout/IndentationConsistency example.rb -d
(snip)

Scanning /Users/koic/src/github.com/koic/rubocop-issues/9606/example.rb
An error occurred while Layout/IndentationConsistency cop was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/9606/example.rb:1:0.
undefined method `source_range' for nil:NilClass
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:165:in
`base_column_for_normal_style'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:181:in
`check_normal_style'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:174:in
`check'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:129:in
`on_begin'
```
bbatsov added a commit that referenced this issue Mar 17, 2021
Fixes #9606.

This PR fixes the following error for `Layout/IndentationConsistency`
when using access modifier at the top level.

```console
% cat example.rb
public

def foo
end

% bundle exec rubocop --only Layout/IndentationConsistency example.rb -d
(snip)

Scanning /Users/koic/src/github.com/koic/rubocop-issues/9606/example.rb
An error occurred while Layout/IndentationConsistency cop was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/9606/example.rb:1:0.
undefined method `source_range' for nil:NilClass
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:165:in
`base_column_for_normal_style'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:181:in
`check_normal_style'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:174:in
`check'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/layout/indentation_consistency.rb:129:in
`on_begin'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants