Skip to content

Commit a45bf5c

Browse files
authored
Merge pull request #738 from rodjek/rubocop
Rubocop compliance
2 parents e25b36a + 84883d8 commit a45bf5c

File tree

101 files changed

+3155
-2525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3155
-2525
lines changed

.rubocop.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
inherit_from: './.rubocop_todo.yml'
3+
AllCops:
4+
TargetRubyVersion: 1.9
5+
6+
Style/HashSyntax:
7+
EnforcedStyle: hash_rockets
8+
9+
Layout/FirstArrayElementLineBreak:
10+
Enabled: true
11+
Layout/FirstHashElementLineBreak:
12+
Enabled: true
13+
Layout/FirstMethodArgumentLineBreak:
14+
Enabled: true
15+
Layout/FirstMethodParameterLineBreak:
16+
Enabled: true
17+
Layout/IndentArray:
18+
EnforcedStyle: consistent
19+
Layout/MultilineArrayBraceLayout:
20+
EnforcedStyle: new_line
21+
Layout/MultilineAssignmentLayout:
22+
Enabled: true
23+
EnforcedStyle: same_line
24+
Layout/MultilineHashBraceLayout:
25+
EnforcedStyle: new_line
26+
Layout/MultilineMethodDefinitionBraceLayout:
27+
EnforcedStyle: new_line
28+
29+
Style/AutoResourceCleanup:
30+
Enabled: true
31+
Style/BlockDelimiters:
32+
EnforcedStyle: braces_for_chaining
33+
Style/BracesAroundHashParameters:
34+
EnforcedStyle: context_dependent
35+
Style/Encoding:
36+
Enabled: false
37+
Style/MethodCallWithArgsParentheses:
38+
Enabled: true
39+
IgnoreMacros: true
40+
IgnoredMethods:
41+
- puts
42+
- require
43+
- include
44+
- it
45+
- context
46+
- describe
47+
- to
48+
- to_not
49+
- raise
50+
- desc
51+
- task
52+
- exit
53+
- should
54+
- gem
55+
- group
56+
- attr_reader
57+
- attr_accessor
58+
- attr_writer
59+
- source
60+
Style/MethodCalledOnDoEndBlock:
61+
Enabled: true
62+
Style/RegexpLiteral:
63+
EnforcedStyle: percent_r
64+
Style/TrailingCommaInArguments:
65+
EnforcedStyleForMultiline: comma
66+
Style/TrailingCommaInLiteral:
67+
EnforcedStyleForMultiline: comma
68+
Style/FormatStringToken:
69+
Enabled: false
70+
Style/FileName:
71+
Exclude:
72+
- 'lib/puppet-lint.rb'
73+
- 'lib/puppet-lint/tasks/puppet-lint.rb'
74+
- 'spec/puppet-lint_spec.rb'

.rubocop_todo.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2017-08-28 12:57:58 +1000 using RuboCop version 0.49.1.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 3
10+
# Configuration parameters: Include.
11+
# Include: **/Gemfile, **/gems.rb
12+
Bundler/DuplicatedGem:
13+
Exclude:
14+
- 'Gemfile'
15+
16+
# Offense count: 2
17+
# Cop supports --auto-correct.
18+
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
19+
# Include: **/Gemfile, **/gems.rb
20+
Bundler/OrderedGems:
21+
Exclude:
22+
- 'Gemfile'
23+
24+
# Offense count: 9
25+
# Configuration parameters: AllowSafeAssignment.
26+
Lint/AssignmentInCondition:
27+
Exclude:
28+
- 'lib/puppet-lint/lexer.rb'
29+
- 'lib/puppet-lint/plugins/check_classes/variable_scope.rb'
30+
31+
# Offense count: 52
32+
Metrics/AbcSize:
33+
Max: 153
34+
35+
# Offense count: 121
36+
# Configuration parameters: CountComments, ExcludedMethods.
37+
Metrics/BlockLength:
38+
Max: 1136
39+
40+
# Offense count: 8
41+
# Configuration parameters: CountBlocks.
42+
Metrics/BlockNesting:
43+
Max: 5
44+
45+
# Offense count: 2
46+
# Configuration parameters: CountComments.
47+
Metrics/ClassLength:
48+
Max: 383
49+
50+
# Offense count: 20
51+
Metrics/CyclomaticComplexity:
52+
Max: 26
53+
54+
# Offense count: 238
55+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
56+
# URISchemes: http, https
57+
Metrics/LineLength:
58+
Max: 223
59+
60+
# Offense count: 65
61+
# Configuration parameters: CountComments.
62+
Metrics/MethodLength:
63+
Max: 94
64+
65+
# Offense count: 18
66+
Metrics/PerceivedComplexity:
67+
Max: 25
68+
69+
# Offense count: 1
70+
# Cop supports --auto-correct.
71+
Performance/RedundantBlockCall:
72+
Exclude:
73+
- 'lib/puppet-lint/tasks/puppet-lint.rb'
74+
75+
# Offense count: 7
76+
# Configuration parameters: EnforcedStyle, SupportedStyles.
77+
# SupportedStyles: nested, compact
78+
Style/ClassAndModuleChildren:
79+
Exclude:
80+
- 'lib/puppet-lint.rb'
81+
- 'lib/puppet-lint/bin.rb'
82+
- 'lib/puppet-lint/checkplugin.rb'
83+
- 'lib/puppet-lint/checks.rb'
84+
- 'lib/puppet-lint/data.rb'
85+
- 'lib/puppet-lint/optparser.rb'
86+
87+
# Offense count: 20
88+
Style/MultilineBlockChain:
89+
Enabled: false

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ branches:
66
only:
77
- master
88
bundler_args: --without development system_tests
9+
script:
10+
- bundle exec rake $CHECK
11+
env:
12+
- CHECK=test
913
rvm:
1014
- 1.9.3
1115
- 2.0.0
1216
- 2.1.10
1317
- 2.2.7
1418
- 2.3.4
1519
- 2.4.1
20+
matrix:
21+
include:
22+
- rvm: 2.4.1
23+
env: CHECK=rubocop

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ group :test do
2525
# requires ruby 1.9+, on 1.8 we'll fall back to the old regex parsing
2626
gem 'rspec-json_expectations', '~> 1.4'
2727
end
28+
29+
gem 'rubocop', '0.49.1' if RUBY_VERSION > '2.0'
2830
end
2931

3032
group :development do

Rakefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ RSpec::Core::RakeTask.new(:test)
88

99
begin
1010
require 'github_changelog_generator/task'
11-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
11+
GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
1212
version = PuppetLint::VERSION
13-
config.future_release = "#{version}"
14-
config.exclude_labels = %w{duplicate question invalid wontfix release-pr}
13+
config.future_release = version.to_s
14+
config.exclude_labels = %w[duplicate question invalid wontfix release-pr]
1515
end
1616
rescue LoadError
17+
$stderr.puts 'Changelog generation requires Ruby 2.0 or higher'
18+
end
19+
20+
begin
21+
require 'rubocop/rake_task'
22+
23+
RuboCop::RakeTask.new(:rubocop) do |task|
24+
task.options = %w[-D -E]
25+
end
26+
rescue LoadError
27+
$stderr.puts 'Rubocop is not available for this version of Ruby.'
1728
end
1829

1930
# vim: syntax=ruby

bin/puppet-lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22

3-
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
44

55
require 'puppet-lint'
66

lib/puppet-lint.rb

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
23
require 'set'
34
require 'json'
45
require 'puppet-lint/version'
@@ -48,7 +49,7 @@ class PuppetLint
4849
# Public: Initialise a new PuppetLint object.
4950
def initialize
5051
@code = nil
51-
@statistics = {:error => 0, :warning => 0, :fixed => 0, :ignored => 0}
52+
@statistics = { :error => 0, :warning => 0, :fixed => 0, :ignored => 0 }
5253
@manifest = ''
5354
end
5455

@@ -71,14 +72,16 @@ def configuration
7172
#
7273
# Returns nothing.
7374
def file=(path)
74-
if File.exist? path
75-
@path = path
76-
@code = File.open(path, 'r:UTF-8').read
75+
return unless File.exist?(path)
7776

78-
# Check if the input is an SE Linux policy package file (which also use
79-
# the .pp extension), which all have the first 4 bytes 0xf97cff8f.
80-
@code = '' if @code[0..3].unpack('V').first == 0xf97cff8f
77+
@path = path
78+
File.open(path, 'r:UTF-8') do |f|
79+
@code = f.read
8180
end
81+
82+
# Check if the input is an SE Linux policy package file (which also use
83+
# the .pp extension), which all have the first 4 bytes 0xf97cff8f.
84+
@code = '' if @code[0..3].unpack('V').first == 0xf97cff8f
8285
end
8386

8487
# Internal: Retrieve the format string to be used when writing problems to
@@ -90,12 +93,11 @@ def log_format
9093
if configuration.log_format == ''
9194
## recreate previous old log format as far as thats possible.
9295
format = '%{KIND}: %{message} on line %{line}'
93-
if configuration.with_filename
94-
format.prepend '%{path} - '
95-
end
96+
format.prepend('%{path} - ') if configuration.with_filename
9697
configuration.log_format = format
9798
end
98-
return configuration.log_format
99+
100+
configuration.log_format
99101
end
100102

101103
# Internal: Format a problem message and print it to STDOUT.
@@ -106,9 +108,8 @@ def log_format
106108
def format_message(message)
107109
format = log_format
108110
puts format % message
109-
if message[:kind] == :ignored && !message[:reason].nil?
110-
puts " #{message[:reason]}"
111-
end
111+
112+
puts " #{message[:reason]}" if message[:kind] == :ignored && !message[:reason].nil?
112113
end
113114

114115
# Internal: Get the line of the manifest on which the problem was found
@@ -117,8 +118,7 @@ def format_message(message)
117118
#
118119
# Returns the problematic line as a string.
119120
def get_context(message)
120-
line = PuppetLint::Data.manifest_lines[message[:line] - 1]
121-
return line.strip
121+
PuppetLint::Data.manifest_lines[message[:line] - 1].strip
122122
end
123123

124124
# Internal: Print out the line of the manifest on which the problem was found
@@ -131,9 +131,9 @@ def print_context(message)
131131
return if message[:check] == 'documentation'
132132
return if message[:kind] == :fixed
133133
line = get_context(message)
134-
offset = line.index(/\S/) || 1
134+
offset = line.index(%r{\S}) || 1
135135
puts "\n #{line.strip}"
136-
printf "%#{message[:column] + 2 - offset}s\n\n", '^'
136+
printf("%#{message[:column] + 2 - offset}s\n\n", '^')
137137
end
138138

139139
# Internal: Print the reported problems with a manifest to stdout.
@@ -154,16 +154,14 @@ def report(problems)
154154
message['context'] = get_context(message) if configuration.with_context
155155
json << message
156156
else
157-
format_message message
157+
format_message(message)
158158
print_context(message) if configuration.with_context
159159
end
160160
end
161161
end
162162
puts JSON.pretty_generate(json) if configuration.json
163163

164-
if problems.any? { |p| p[:check] == :syntax }
165-
$stderr.puts "Try running `puppet parser validate <file>`"
166-
end
164+
$stderr.puts 'Try running `puppet parser validate <file>`' if problems.any? { |p| p[:check] == :syntax }
167165
end
168166

169167
# Public: Determine if PuppetLint found any errors in the manifest.
@@ -186,9 +184,7 @@ def warnings?
186184
# Returns nothing.
187185
# Raises PuppetLint::NoCodeError if no manifest code has been loaded.
188186
def run
189-
if @code.nil?
190-
raise PuppetLint::NoCodeError
191-
end
187+
raise PuppetLint::NoCodeError if @code.nil?
192188

193189
if @code.empty?
194190
@problems = []
@@ -207,7 +203,7 @@ def run
207203
#
208204
# Returns nothing.
209205
def print_problems
210-
report @problems
206+
report(@problems)
211207
end
212208

213209
# Public: Define a new check.

0 commit comments

Comments
 (0)