Disabling rubocop and upgrading to PDK 1.6.0 | rnelson0
source link: https://rnelson0.com/2018/06/26/disabling-rubocop-and-upgrading-to-pdk-1-6-0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Disabling rubocop and upgrading to PDK 1.6.0
As I lamented in my article on converting to the PDK, I really do not like Rubocop and was disappointed I could not turn it off. Thankfully, that was addressed in PDK-998 and the fix was included in time for PDK 1.6.0! Disabling it is pretty simple and though it’s strictly a fix to pdk-templates, updating the PDK won’t hurt.
First, update to PDK 1.6.0. As I use CentOS 7 and the RPM packaging, it’s as simple as sudo yum update pdk -y
; follow the directions that match system. Next, we need to add the following lines to .sync.yml
:
.rubocop.yml: selected_profile: off
Finally, run pdk update
, or if you weren’t already using pdk-templates, run pdk convert --template-url=https://github.com/puppetlabs/pdk-templates
(I will assume the former to keep it simple). You can add --noop
(or say n) and review update.txt|convert.txt
to see the differences before applying, or, because you are using version control, just run a diff afterward to see the changes.
[rnelson0@build03 domain_join:pdk160]$ pdk update pdk (INFO): Updating rnelson0-domain_join using the template at https://github.com/puppetlabs/pdk-templates, from master@041eeb2 to 1.6.0 ----------Files to be modified---------- metadata.json .pdkignore spec/spec_helper.rb .gitignore Rakefile .rubocop.yml Gemfile ---------------------------------------- You can find a report of differences in update_report.txt. Do you want to continue and make these changes to your module? Yes [] Installing missing Gemfile dependencies. ------------Update completed------------ 7 files modified.
That’s it! Check the contents of .rubocop.yml
and you will notice everything is false (just a snippet because it’s loooong):
--- require: rubocop-rspec AllCops: DisplayCopNames: true TargetRubyVersion: '2.1' Include: - "./**/*.rb" Exclude: - bin/* - ".vendor/**/*" - "**/Gemfile" - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" Bundler/DuplicatedGem: Enabled: false Bundler/OrderedGems: Enabled: false Layout/AccessModifierIndentation: Enabled: false Layout/AlignArray: Enabled: false Layout/AlignHash: Enabled: false Layout/AlignParameters: Enabled: false Layout/BlockEndNewline: Enabled: false Layout/CaseIndentation: Enabled: false Layout/ClosingParenthesisIndentation: Enabled: false Layout/CommentIndentation: Enabled: false
Running validation now finds no issues with ruby syntax no matter how much you ignore style guides:
# master, prior to updating [rnelson0@build03 domain_join:master]$ pdk validate ... [] Checking Ruby code style (**/**.rb). info: task-metadata-lint: ./: Target does not contain any files to validate (tasks/*.json). convention: rubocop: spec/spec_helper_acceptance.rb:17:27: Style/HashSyntax: Use the new Ruby 1.9 hash syntax. convention: rubocop: spec/spec_helper_acceptance.rb:17:49: Style/HashSyntax: Use the new Ruby 1.9 hash syntax. convention: rubocop: spec/spec_helper_acceptance.rb:19:66: Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter. convention: rubocop: spec/spec_helper_acceptance.rb:19:68: Style/HashSyntax: Use the new Ruby 1.9 hash syntax. convention: rubocop: spec/spec_helper_acceptance.rb:19:96: Layout/SpaceAfterComma: Space missing after comma. convention: rubocop: spec/acceptance/class_spec.rb:6:9: RSpec/ExampleWording: Do not use should when describing your tests. convention: rubocop: spec/acceptance/class_spec.rb:12:26: Style/HashSyntax: Use the new Ruby 1.9 hash syntax. convention: rubocop: spec/acceptance/class_spec.rb:13:26: Style/HashSyntax: Use the new Ruby 1.9 hash syntax. convention: rubocop: spec/classes/domain_join_spec.rb:2:25: Style/HashSyntax: Use the new Ruby 1.9 hash syntax. # pdk160, after updating, no code changes
[rnelson0@build03 domain_join:pdk160]$ pdk validate pdk (INFO): Running all available validators... pdk (INFO): Using Ruby 2.4.4 pdk (INFO): Using Puppet 5.5.2 [] Checking metadata syntax (metadata.json tasks/*.json). [] Checking module metadata style (metadata.json). [] Checking Puppet manifest syntax (**/**.pp). [] Checking Puppet manifest style (**/*.pp). [] Checking Ruby code style (**/**.rb). info: task-metadata-lint: ./: Target does not contain any files to validate (tasks/*.json).
You may have noticed there are quite a few other files updated. The other significant change is that a :changelog task via github_changelog_generator is now included, so you can remove that from your .sync.yml
if you added it and replace it with the recommended config (via the Rakefile):
--- Gemfile: optional: ':development': - gem: 'github_changelog_generator' git: 'https://github.com/skywinder/github-changelog-generator' ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
The other changes are pretty minor, in some cases cosmetic, but of course review them to make sure they’re OK. Submit a PR or equivalent and make sure the tests pass before merging. You can follow along with today’s blog post in domain_join PR35, too.
Enjoy!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK