Skip to content

Commit f4b3ae8

Browse files
sheenaajayscotty-c
authored andcommitted
(CLOUD-1661) Fixing rubocop error andaddingi18ngem (#120)
1 parent fb8e840 commit f4b3ae8

28 files changed

+396
-235
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ fixtures:
33
stdlib: 'puppetlabs-stdlib'
44
epel: 'stahnma-epel'
55
apt: 'puppetlabs-apt'
6+
translate: 'puppetlabs-translate'
67
symlinks:
78
docker: "#{source_dir}"

.rubocop.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
require:
3+
- rubocop-rspec
4+
- rubocop-i18n
5+
AllCops:
6+
TargetRubyVersion: '2.1'
7+
Include:
8+
- "./**/*.rb"
9+
Exclude:
10+
- bin/*
11+
- ".vendor/**/*"
12+
- Gemfile
13+
- Rakefile
14+
- pkg/**/*
15+
- spec/fixtures/**/*
16+
- vendor/**/*
17+
Metrics/LineLength:
18+
Description: People have wide screens, use them.
19+
Max: 200
20+
Enabled: false
21+
RSpec/BeforeAfterAll:
22+
Description: Beware of using after(:all) as it may cause state to leak between tests.
23+
A necessary evil in acceptance testing.
24+
Exclude:
25+
- spec/acceptance/**/*.rb
26+
RSpec/HookArgument:
27+
Description: Prefer explicit :each argument, matching existing module's style
28+
EnforcedStyle: each
29+
Style/BlockDelimiters:
30+
Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to
31+
be consistent then.
32+
EnforcedStyle: braces_for_chaining
33+
Style/ClassAndModuleChildren:
34+
Description: Compact style reduces the required amount of indentation.
35+
EnforcedStyle: compact
36+
Style/EmptyElse:
37+
Description: Enforce against empty else clauses, but allow `nil` for clarity.
38+
EnforcedStyle: empty
39+
Style/FormatString:
40+
Description: Following the main puppet project's style, prefer the % format format.
41+
EnforcedStyle: percent
42+
Exclude:
43+
- lib/puppet/provider/docker_volume/ruby.rb
44+
- lib/puppet/provider/docker_network/ruby.rb
45+
- lib/puppet/parser/functions/docker_secrets_flags.rb
46+
- lib/puppet/parser/functions/docker_run_flags.rb
47+
- lib/puppet/type/docker_network.rb
48+
- lib/puppet/type/docker_volume.rb
49+
Style/FormatStringToken:
50+
Description: Following the main puppet project's style, prefer the simpler template
51+
tokens over annotated ones.
52+
EnforcedStyle: template
53+
Style/Lambda:
54+
Description: Prefer the keyword for easier discoverability.
55+
EnforcedStyle: literal
56+
Enabled: true
57+
Exclude:
58+
- lib/puppet/provider/docker_volume/ruby.rb
59+
- lib/puppet/parser/functions/docker_secrets_flags.rb
60+
- lib/puppet/parser/functions/docker_run_flags.rb
61+
- lib/puppet/provider/docker_network/ruby.rb
62+
Style/RegexpLiteral:
63+
Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168
64+
EnforcedStyle: percent_r
65+
Style/TernaryParentheses:
66+
Description: Checks for use of parentheses around ternary conditions. Enforce parentheses
67+
on complex expressions for better readability, but seriously consider breaking
68+
it up.
69+
EnforcedStyle: require_parentheses_when_complex
70+
Style/TrailingCommaInArguments:
71+
Description: Prefer always trailing comma on multiline argument lists. This makes
72+
diffs, and re-ordering nicer.
73+
EnforcedStyleForMultiline: comma
74+
Style/TrailingCommaInLiteral:
75+
Description: Prefer always trailing comma on multiline literals. This makes diffs,
76+
and re-ordering nicer.
77+
EnforcedStyleForMultiline: comma
78+
Style/SymbolArray:
79+
Description: Using percent style obscures symbolic intent of array's contents.
80+
EnforcedStyle: brackets
81+
Style/CollectionMethods:
82+
Enabled: true
83+
Style/MethodCalledOnDoEndBlock:
84+
Enabled: true
85+
Style/StringMethods:
86+
Enabled: true
87+
Metrics/AbcSize:
88+
Enabled: false
89+
Metrics/BlockLength:
90+
Enabled: false
91+
Metrics/LineLength:
92+
Enabled: false
93+
Metrics/ClassLength:
94+
Enabled: false
95+
Metrics/CyclomaticComplexity:
96+
Enabled: false
97+
Metrics/MethodLength:
98+
Enabled: false
99+
Metrics/ModuleLength:
100+
Enabled: false
101+
Metrics/ParameterLists:
102+
Enabled: false
103+
Metrics/PerceivedComplexity:
104+
Enabled: false
105+
RSpec/DescribeClass:
106+
Enabled: false
107+
RSpec/MessageExpectation:
108+
Enabled: false
109+
Style/AsciiComments:
110+
Enabled: false
111+
Style/IfUnlessModifier:
112+
Enabled: false
113+
Style/SymbolProc:
114+
Enabled: false
115+
Style/HashSyntax:
116+
UseHashRocketsWithSymbolValues: true
117+
Style/StringLiterals:
118+
EnforcedStyle: single_quotes
119+
SupportedStyles:
120+
- single_quotes
121+
- double_quotes
122+
Exclude:
123+
- lib/puppet/provider/docker_compose/ruby.rb
124+
GetText/DecorateString:
125+
Enabled: true
126+
Exclude:
127+
- lib/puppet/type/docker_compose.rb
128+
GetText/DecorateFunctionMessage:
129+
Enabled: true
130+
Exclude:
131+
- lib/puppet/type/docker_network.rb
132+
- lib/puppet/type/docker_volume.rb
133+
- lib/puppet/provider/docker_compose/ruby.rb
134+
GetText/DecorateStringFormattingUsingInterpolation:
135+
Enabled: true
136+
GetText/DecorateStringFormattingUsingPercent:
137+
Enabled: true

Gemfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ group :test do
99
else
1010
gem "puppet"
1111
end
12-
gem "puppet-lint"
13-
gem "puppet-lint-unquoted_string-check"
12+
gem "puppet-lint", "2.3.3"
13+
gem "puppet-lint-unquoted_string-check", "0.3.0"
1414
gem "rspec-puppet"
1515
gem "puppet-syntax"
1616
gem "puppetlabs_spec_helper"
@@ -22,7 +22,11 @@ group :test do
2222
gem 'parallel_tests' # requires at least Ruby 1.9.3
2323
gem "json_pure", "<= 2.0.1" # 2.0.2 requires Ruby 2+
2424
gem 'rspec_junit_formatter', '~> 0.2.3'
25-
25+
gem "puppet-lint-i18n"
26+
gem "puppet_pot_generator"
27+
gem 'rubocop-i18n'
28+
gem 'gettext-setup'
29+
gem 'rubocop-rspec'
2630
end
2731

2832
group :system_tests do

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ require 'rubygems'
22
require 'bundler/setup'
33

44
require 'puppetlabs_spec_helper/rake_tasks'
5+
require 'puppet_pot_generator/rake_tasks'
56

67
# These gems aren't always present, for instance
78
# on Travis with --without development

lib/facter/docker.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def interfaces
2323
setcode do
2424
if Facter::Util::Resolution.which('docker')
2525
value = Facter::Core::Execution.execute(
26-
"docker version --format '{{json .}}'")
26+
"docker version --format '{{json .}}'",
27+
)
2728
val = JSON.parse(value)
2829
end
2930
val
@@ -34,22 +35,23 @@ def interfaces
3435
setcode do
3536
if Facter::Util::Resolution.which('docker')
3637
docker_json_str = Facter::Util::Resolution.exec(
37-
"docker info --format '{{json .}}'")
38+
"docker info --format '{{json .}}'",
39+
)
3840
docker = JSON.parse(docker_json_str)
39-
docker['network'] = Hash.new
41+
docker['network'] = {}
4042

41-
docker['network']['managed_interfaces'] = Hash.new
43+
docker['network']['managed_interfaces'] = {}
4244
network_list = Facter::Util::Resolution.exec('docker network ls | tail -n +2')
43-
docker_network_names = Array.new
44-
network_list.each_line {|line| docker_network_names.push line.split[1] }
45-
docker_network_ids = Array.new
46-
network_list.each_line {|line| docker_network_ids.push line.split[0] }
45+
docker_network_names = []
46+
network_list.each_line { |line| docker_network_names.push line.split[1] }
47+
docker_network_ids = []
48+
network_list.each_line { |line| docker_network_ids.push line.split[0] }
4749
docker_network_names.each do |network|
4850
inspect = JSON.parse(Facter::Util::Resolution.exec("docker network inspect #{network}"))
4951
docker['network'][network] = inspect[0]
5052
network_id = docker['network'][network]['Id'][0..11]
5153
interfaces.each do |iface|
52-
docker['network']['managed_interfaces'][iface] = network if iface =~ /#{network_id}/
54+
docker['network']['managed_interfaces'][iface] = network if iface =~ %r{#{network_id}}
5355
end
5456
end
5557
docker

lib/puppet/parser/functions/docker_exec_flags.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'shellwords'
2-
2+
#
3+
# docker_exec_flags.rb
4+
#
35
module Puppet::Parser::Functions
46
# Transforms a hash into a string of docker exec flags
57
newfunction(:docker_exec_flags, :type => :rvalue) do |args|
@@ -18,6 +20,6 @@ module Puppet::Parser::Functions
1820
flags << '--tty=true'
1921
end
2022

21-
flags.flatten.join(" ")
23+
flags.flatten.join(' ')
2224
end
2325
end

lib/puppet/parser/functions/docker_run_flags.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'shellwords'
2-
2+
#
3+
# docker_run_flags.rb
4+
#
35
module Puppet::Parser::Functions
46
# Transforms a hash into a string of docker flags
57
newfunction(:docker_run_flags, :type => :rvalue) do |args|
@@ -65,7 +67,7 @@ module Puppet::Parser::Functions
6567
['-p %s', 'ports'],
6668
['-l %s', 'labels'],
6769
['--add-host %s', 'hostentries'],
68-
['-v %s', 'volumes']
70+
['-v %s', 'volumes'],
6971
].each do |(format, key)|
7072
values = opts[key]
7173
new_flags = multi_flags.call(values, format)
@@ -76,6 +78,6 @@ module Puppet::Parser::Functions
7678
flags << param
7779
end
7880

79-
flags.flatten.join(" ")
81+
flags.flatten.join(' ')
8082
end
8183
end

lib/puppet/parser/functions/docker_secrets_flags.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'shellwords'
2-
2+
#
3+
# docker_secrets_flags.rb
4+
#
35
module Puppet::Parser::Functions
46
# Transforms a hash into a string of docker swarm init flags
57
newfunction(:docker_secrets_flags, :type => :rvalue) do |args|
@@ -23,13 +25,13 @@ module Puppet::Parser::Functions
2325
filtered.map { |val| sprintf(format + " \\\n", val) }
2426
}
2527
[
26-
['-l %s', 'label']
28+
['-l %s', 'label'],
2729
].each do |(format, key)|
2830
values = opts[key]
2931
new_flags = multi_flags.call(values, format)
3032
flags.concat(new_flags)
3133
end
3234

33-
flags.flatten.join(" ")
35+
flags.flatten.join(' ')
3436
end
3537
end

lib/puppet/parser/functions/docker_service_flags.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'shellwords'
2-
2+
#
3+
# docker_service_flags.rb
4+
#
35
module Puppet::Parser::Functions
46
# Transforms a hash into a string of docker swarm init flags
57
newfunction(:docker_service_flags, :type => :rvalue) do |args|
@@ -64,6 +66,6 @@ module Puppet::Parser::Functions
6466
flags << "--registry-mirror='#{opts['registry_mirror']}'"
6567
end
6668

67-
flags.flatten.join(" ")
69+
flags.flatten.join(' ')
6870
end
6971
end
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'shellwords'
2-
2+
#
3+
# docker_stack_flags.rb
4+
#
35
module Puppet::Parser::Functions
46
# Transforms a hash into a string of docker swarm init flags
57
newfunction(:docker_stack_flags, :type => :rvalue) do |args|
@@ -8,20 +10,20 @@ module Puppet::Parser::Functions
810

911
if opts['bundle_file'].to_s != 'undef'
1012
flags << "--bundle-file '#{opts['bundle_file']}'"
11-
end
13+
end
1214

1315
if opts['compose_file'].to_s != 'undef'
1416
flags << "--compose-file '#{opts['compose_file']}'"
15-
end
17+
end
1618

1719
if opts['prune'].to_s != 'undef'
1820
flags << "--prune '#{opts['prune']}'"
19-
end
20-
21+
end
22+
2123
if opts['with_registry_auth'].to_s != 'undef'
2224
flags << "--with-registry-auth '#{opts['with_registry_auth']}'"
23-
end
25+
end
2426

25-
flags.flatten.join(" ")
27+
flags.flatten.join(' ')
2628
end
27-
end
29+
end

0 commit comments

Comments
 (0)