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

[!] Invalid Dangerfile file: undefined method `captures' for nil:NilClass #63

Open
ssoulless opened this issue Sep 11, 2023 · 1 comment

Comments

@ssoulless
Copy link

If you pass the files you want to lint to the rubocop.lint method you could have this error because if you moved files to a new path when linting them they will have the old path, why only perform the mapping if you don't pass the files?

In my case I need to filter my changed files by file extension:

changed_files = (git.modified_files + git.added_files)
 valid_types   = ['.rb', '.rake']

files_to_lint = changed_files.select { |file| valid_types.any? { |type| file.include?(type) } }

lint_config   = {
  files:                    files_to_lint,
  report_danger:            true,
  inline_comment:           true,
  force_exclusion:          true,
  only_report_new_offenses: true
}

rubocop.lint(lint_config) if files_to_lint.length > 0

https://github.com/ashfurrow/danger-rubocop/blob/60621dcd390bb64d444f297e77054be7d3fa3fbe/lib/danger_plugin.rb#L149C2-L149C2

I would suggest adding the config to exclude file extensions, that would solve my issue, for now I have to map old paths with new paths in changed files manually before sending them to rubocop.lint

@ashfurrow
Copy link
Owner

Hi, thanks for your patience while I respond.

I'm not sure I understand the issue properly. The tool should handle renamed files already with the default files:

# when files are renamed, git.modified_files contains the old name not the new one, so we need to do the convertion
renaming_map = (git.renamed_files || []).map { |e| [e[:before], e[:after]] }.to_h
(git.modified_files.map { |f| renaming_map[f] || f }) + git.added_files

Are you suggesting that we should also apply this mapping to the files that are passed in by the user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants