Skip to content

Commit

Permalink
Merge pull request #264 from iwarapter/feature/add_sample_testing
Browse files Browse the repository at this point in the history
Feature/add sample testing
  • Loading branch information
racodond committed Mar 30, 2016
2 parents 046d489 + 9f7a757 commit 853e5ef
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 69 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ install:
- unzip sonar-scanner-2.5.zip
- ls -lar
- cd -
- gem install puppet -v 3.8.6

script:
- ./gradlew build localDeploy functionalTest -Psonar.pluginDir=$SONAR_HOME/extensions/plugins
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ subprojects {
events "failed"
exceptionFormat "full"
}
maxParallelForks 4
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>For readability reasons, the same starting token should be used for each comment. This rule checks that each comment starts with <code>#</code>.</p>
<h2>Noncompliant Code Example</h2>
<pre>
<pre skipautotest="">
// My comments...
notice('hello') // My comments...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

<h2>Noncompliant Code Example</h2>
<pre>
if $var1 > 2 and $var2 > 3 or ($var3 > $var4 and $var1 < $var3) or $var5 > 4 { ... } # Noncompliant: 4 'and' and 'or' conditions
if $var1 > 2 and $var2 > 3 or ($var3 > $var4 and $var1 < $var3) or $var5 > 4 { } # Noncompliant: 4 'and' and 'or' conditions
</pre>

<h2>Compliant Solution</h2>
<pre>
$is_position_valid = $var3 > $var4 and $var1 < $var3
if $var1 > 2 and $var2 > 3 or $is_position_valid or $var5 > 4 { ... }
if $var1 > 2 and $var2 > 3 or $is_position_valid or $var5 > 4 { }
</pre>

Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

<h2>Noncompliant Code Example</h2>
<pre>
class configuration { ... }
class configuration { }

define server() { ... }
define server() { }
</pre>

<h2>Compliant Solution</h2>
<pre>
# Some useful documentation
# ...
class configuration { ... }
class configuration { }

# Some useful documentation
# ...
define server() { ... }
</pre>
define server() { }
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ <h2>Noncompliant Code Example</h2>

<pre>
class abc {} # Noncompliant: Remove this empty class
define abc {} # Noncompliant: Remove this empty define
define def {} # Noncompliant: Remove this empty define

File {} # Noncompliant: Remove this useless resource default statement
File['/tmp/log'] {} # Noncompliant: Remove this useless resource override

if !$isValidRole {} # Noncompliant: Remove this useless 'if' statement

if $isValidRole {
$userRole = 'admin',
$userRole = 'admin'
}
else { # Noncompliant: Empty on purpose or missing piece of code? Either remove this 'else' statement or add a comment
}
Expand All @@ -54,7 +54,7 @@ <h2>Compliant Solution</h2>
}

if $isValidRole {
$userRole = 'admin',
$userRole = 'admin'
}
else {
# Do nothing because...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p>Some tools such as Git work better when files end with an empty line.</p>
<p>This rule simply generates an issue if it is missing.</p>
<p>For example, a Git diff looks like:</p>
<pre>
<pre skipautotest="">
file { '/tmp/foo':
ensure => present,
mode => '0444',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
As 99% of the time, you mean the second bullet point, remove the whitespaces to be compliant with Puppet 4 new syntax.
</p>
<h2>Noncompliant Code Example</h2>
<pre>
<pre skipautotest="">
$var [3]
</pre>
<h2>Compliant Solution</h2>
<pre>
<pre skipautotest="">
$var[3]
</pre>
<h2>See</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ <h2>Noncompliant Code Example</h2>
<pre>
if $is_virtual
{ # Noncompliant: The brace should be moved to the previous line
...
#...
}

if $is_virtual {
...
#...
}
elsif $is_linux { # Noncompliant: 'elsif' should be moved to the previous line
...
#...
}
else { # Noncompliant: 'else' should be moved to the previous line
...
#...
}

if $is_virtual {
... } # Noncompliant: The brace should be moved to the next line
} # Noncompliant: The brace should be moved to the next line
</pre>

<h2>Compliant Solution</h2>
<pre>
if $is_virtual {
...
#...
} elsif $is_linux {
...
#...
} else {
...
#...
}
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ <h2>Noncompliant Code Example</h2>

<pre>
if $is_virtual {
do_something
#do_something
}
elsif $operatingsystem == 'Windows' {
do_something_else
#do_something_else
}
</pre>

<h2>Compliant Solution</h2>
<pre>
if $is_virtual {
do_something
#do_something
}
elsif $operatingsystem == 'Windows' {
do_something_else
#do_something_else
}
else {
# Do nothing because...
}

if $is_virtual {
do_something
#do_something
}
elsif $operatingsystem == 'Windows' {
do_something_else
#do_something_else
}
else {
fail 'This case is not supported...'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>Noncompliant Code Example</h2>
class abc (
$a,
$b, # Noncompliant
) { ... }
) { }

$a = [
'a',
Expand Down Expand Up @@ -60,7 +60,7 @@ <h2>Compliant Solution</h2>
class abc (
$a,
$b,
) { ... }
) { }

$a = [
'a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

<h2>Noncompliant Code Example</h2>
<pre>
class ssh inherits server { ... }
class ssh inherits server { }

class ssh::client inherits workstation { ... }
class ssh::client inherits workstation { }

class wordpress inherits apache { ... }
class wordpress inherits apache { }
</pre>

<h2>Compliant Solution</h2>
<pre>
class ssh { ... }
class ssh { }

class ssh::client inherits ssh { ... }
class ssh::client inherits ssh { }

class ssh::server inherits ssh { ... }
class ssh::server inherits ssh { }
</pre>

<h2>See</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p>As you are now using SonarQube, <code>lint:ignore</code> and <code>lint:endignore</code> tags can be safely removed.
</p>
<h2>Noncompliant Code Example</h2>
<pre>
<pre skipautotest="">
# lint:ignore:80chars
...
# lint:endignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<h2>Noncompliant Code Example</h2>
<pre>
if $var == true { ... }
if $var == false { ... }
if $var == true { }
if $var == false { }
</pre>

<h2>Compliant Solution</h2>
<pre>
if $var { ... }
if !$var { ... }
</pre>
if $var { }
if !$var { }
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
<h2>Noncompliant Code Example</h2>
<pre>
class apache {
class ssl { ... }
class ssl { }
}

class apache {
define config() { ... }
define config() { }
}
</pre>

<h2>See</h2>
<ul>
<li><a href="http://docs.puppetlabs.com/guides/style_guide.html#nested-classes-or-defines">See Puppet Labs Puppet
Language Style Guide</a></li>
</ul>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>Noncompliant Code Example</h2>
purge => 'true',
}

if $is_virtual == 'false' { ... }
if $is_virtual == 'false' { }
</pre>

<h2>Compliant Solution</h2>
Expand All @@ -21,10 +21,10 @@ <h2>Compliant Solution</h2>
purge => true,
}

if $is_virtual == false { ... }
if $is_virtual == false { }
</pre>

<h2>See</h2>
<ul>
<li><a href="https://docs.puppetlabs.com/puppet/latest/reference/experiments_future.html#boolean-facts-are-always-real-booleans">Updating 3.x Manifests for Puppet 4.x</a></li>
</ul>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
</nobr>. If not, the catalog compilation does not fail and the resource default statement is useless because it does not match any resource type.</p>
<h2>Noncompliant Code Example</h2>
<pre>
Foo:bar {
Foo::BAR {
ensure => present,
}
</pre>
<h2>Compliant Solution</h2>
<pre>
Foo:Bar {
Foo::Bar {
ensure => present,
}
</pre>
<h2>See</h2>
<ul>
<li><a href="https://docs.puppetlabs.com/puppet/latest/reference/lang_defaults.html#syntax">Resource default
<li><a href="https://docs.puppetlabs.com/puppet/3.8/reference/lang_defaults.html#syntax">Resource default
statement syntax</a></li>
</ul>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ <h2>Noncompliant Code Example</h2>

<pre>
if $param == 1 {
...
#...
} elsif $param == 2 {
...
#...
} elsif $param == 1 { # Noncompliant
...
#...
}
</pre>

<h2>Compliant Solution</h2>

<pre>
if $param == 1 {
...
#...
} elsif $param == 2 {
...
#...
} elsif $param == 3 {
...
#...
}
</pre>

Expand All @@ -33,4 +33,4 @@ <h2>See</h2>
<ul>
<li><a href="https://www.securecoding.cert.org/confluence/x/NYA5">CERT, MSC12-C</a> - Detect and remove code that has no effect</li>
<li><a href="https://www.securecoding.cert.org/confluence/x/SIIyAQ">CERT, MSC12-CPP</a> - Detect and remove code that has no effect</li>
</ul>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

<h2>Noncompliant Code Example</h2>
<pre>
if !(a == 2) { ... } # Noncompliant
if !(a == 2) { } # Noncompliant
$b = !(i < 10) # Noncompliant
$c = !($a == 1 and $b == 2) # Noncompliant
</pre>

<h2>Compliant Solution</h2>
<pre>
if a != 2 { ... }
if a != 2 { }
$b = (i >= 10)
$c = $a != 1 or $b != 2
</pre>
</pre>
Loading

0 comments on commit 853e5ef

Please sign in to comment.