[PDK-654] `pdk validate ruby` ignores .rubocop.yml and includes files in `spec/fixtures` Created: 2017/11/04  Updated: 2019/02/25  Resolved: 2018/11/15

Status: Closed
Project: Puppet Development Kit
Component/s: None
Affects Version/s: PDK 1.2.1
Fix Version/s: PDK 1.8.0

Type: Bug Priority: Major
Reporter: Bryan Wyatt Assignee: Tim Sharpe
Resolution: Fixed Votes: 0
Labels: resolved-issue-added, rubocop, ruby, validate
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

PDK Version: 1.2.1
OS: Ubuntu 16.04.3 LTS


Issue Links:
Duplicate
is duplicated by PDK-1201 pdk validate's rubocop check does not... Closed
Relates
relates to PDK-925 pdk validate should skip spec/fixture... Closed
relates to PDK-1070 PDK validate doesn't seem to honor ru... Closed
Template:
Method Found: Needs Assessment
Release Notes: Bug Fix
Release Notes Summary: Prior to this fix, running pdk validate without any targets caused the subsequent rubocop call to ignore the rubycop.yml excludes due to the fact that we passed in a list of files from a globbed list. This has been fixed and the ruby validator will now honor the excludes in the rubocop.yml.
QA Risk Assessment: Needs Assessment

 Description   

Fixtures downloaded as part of the unit tests (in `spec/fixtures/`) are getting caught up in the Ruby validation tests. It seems that the PDK call to `rubocop` is passing in a full list of all .rb files, instead of using the generated `.rubocop.yml` file, which correctly excludes files from `spec/fixtures`. I've tested that this works on fresh modules created with PDK as well as one I've converted to use the PDK.

This is especially annoying as it is picking up the numerous violations from the `puppetlabs/apt` module.

For now, I can just nuke `spec/fixtures` as a work around when running validation tests, but that's definitely a workaround and likely not the intended workflow.

Snippet from the debug output from `pdk validate ruby --debug`:

pdk (DEBUG): Execution of '[MODULE_ROOT]/bin/rubocop --format json [MODULE_ROOT]/lib/puppet/type/EXAMPLE_TYPE.rb [MODULE_ROOT]/spec/fixtures/modules/apt/lib/puppet_x/apt_key/patch_openuri.rb [MODULE_ROOT]/spec/fixtures/modules/apt/lib/puppet/type/apt_key.rb [MODULE_ROOT]/spec/fixtures/modules/apt/lib/puppet/provider/apt_key/apt_key.rb [MODULE_ROOT]/spec/fixtures/modules/apt/lib/facter/apt_update_last_success.rb [MODULE_ROOT]/spec/fixtures/modules/apt/lib/facter/apt_reboot_required.rb [MODULE_ROOT]/spec/fixtures/modules/apt/lib/facter/apt_updates.rb [MODULE_ROOT]/spec/fixtures/modules/apt/tasks/init.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/spec_helper_acceptance.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/spec_helper.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/puppet/type/apt_key_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_updates_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_has_updates_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_package_updates_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_security_updates_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/unit/facter/apt_package_security_updates_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/key_compat_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/source_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/setting_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/ppa_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/source_compat_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/key_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/pin_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/defines/conf_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/classes/apt_backports_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/classes/apt_update_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/classes/apt_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/acceptance/apt_key_provider_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/acceptance/init_task_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/acceptance/apt_spec.rb [MODULE_ROOT]/spec/fixtures/modules/apt/spec/acceptance/class_spec.rb [MODULE_ROOT]/spec/spec_helper.rb [MODULE_ROOT]/spec/classes/init_spec.rb complete (duration: 0.687284496s; exit code: 1)
convention: rubocop: spec/fixtures/modules/apt/lib/puppet_x/apt_key/patch_openuri.rb:5:8: Use compact module/class definition instead of nested style.
warning: rubocop: spec/fixtures/modules/apt/lib/puppet_x/apt_key/patch_openuri.rb:19:23: Assignment in condition - you probably meant to use `==`.
convention: rubocop: spec/fixtures/modules/apt/lib/puppet/type/apt_key.rb:51:15: Use `%r` around regular expression.

Relevant section from `.rubocop.yml`:

AllCops:
  TargetRubyVersion: '2.1'
  Include:
  - "./**/*.rb"
  Exclude:
  - bin/*
  - ".vendor/**/*"
  - Gemfile
  - Rakefile
  - pkg/**/*
  - spec/fixtures/**/*
  - vendor/**/*



 Comments   
Comment by Bryan Jen [ 2018/10/18 ]

When not providing a list of files to validate, PDK should be allowing the underlying validation tools to detect the files to scan and validate based on the config.

Generated at Thu Dec 12 02:32:35 PST 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.