puppet-lint-resource_outside_class-check 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33a1b5dacd70bd9c800c13d1b527bd8405a22e51
4
+ data.tar.gz: 35fccecdbf4433347f56b7d081dfea63473845d0
5
+ SHA512:
6
+ metadata.gz: f2fdd9c13adbdd8145e9bc1053def3d6c33f88c2ef86a1c236e23cee3ef4a0d5a5bc1454a5fa822902cc3faf92f040714104a2e367bbceac7efef5852aa64b0e
7
+ data.tar.gz: 3e939686068f78ebed002e073c97140ddb4d34ba58f376941e10aeb31e2a7d25ebe8a8e4c9ae526dc829697f5174f40b2a35c0cf8c3892b266da280a4297dee7
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Lee Lowder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,17 @@
1
+ # puppet-lint-resource_outside_class-check
2
+ Adds a new puppet-lint check to see if resources exist outside of a class or defined type.
3
+
4
+ ##Installation
5
+ `gem install puppet-lint-resource_outside_class-check`
6
+
7
+ ##Usage
8
+
9
+ This check will detect if resources exist outside of a class or defined types.
10
+
11
+ Conditions caught:
12
+ - resource before start of a class or defined type definiton
13
+ - resources after the close of a class or defined type definition
14
+ - resources in a manifest that do not ahve a class or defiend type definition
15
+
16
+
17
+
@@ -0,0 +1,51 @@
1
+ PuppetLint.new_check(:resource_outside_class) do
2
+ def check
3
+
4
+ first_token = tokens.first
5
+ last_token = tokens.last
6
+ resource_list = resource_indexes
7
+
8
+ if class_indexes.length > 0
9
+ # The file has at least a class in it it
10
+ class_list = class_indexes
11
+
12
+ class_list.each do |cl|
13
+ resource_list.each do |res|
14
+ unless ( res[:start] > cl[:start] ) && ( res[:end] < cl[:end] )
15
+ notify :warning, {
16
+ :message => 'resource found outside a class definition',
17
+ :line => res[:type].line,
18
+ :column => res[:type].column,
19
+ }
20
+ end
21
+ end
22
+ end
23
+
24
+ elsif defined_type_indexes.length > 0
25
+ #the file has at least a defined type in it
26
+ define_list = defined_type_indexes
27
+
28
+ define_list.each do |dl|
29
+ resource_list.each do |res|
30
+ unless ( res[:start] > dl[:start] ) && ( res[:end] < dl[:end] )
31
+ notify :warning, {
32
+ :message => 'resource found outside a defined type defintion',
33
+ :line => res[:type].line,
34
+ :column => res[:type].column,
35
+ }
36
+ end
37
+ end
38
+ end
39
+ else
40
+ #no class and no defined type
41
+ unless resource_list.length == 0
42
+ notify :warning, {
43
+ :message => 'resourcss exist but no class or defined type definition found in manifest',
44
+ :line => resource_list.first[:line],
45
+ :column => resource_list.first[:column],
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'resource_outside_class' do
4
+
5
+ let(:class_msg) { 'resource found outside a class definition' }
6
+ let(:define_msg) { 'resource found outside a defined type defintion' }
7
+ let(no_class_or_define_msg) { 'resourcss exist but no class or defined type definition found in manifest')
8
+
9
+ context 'with fix disabled' do
10
+
11
+ context 'resource inside class definition' do
12
+ let(:code) { "class foo{\nnotify{ 'resource in class': }\n}" }
13
+
14
+ it 'should not detect any problems' do
15
+ expect(problems).to have(0).problems
16
+ end
17
+ end
18
+
19
+ context 'resource inside defined type definition' do
20
+ let(:code) { "define bar{\nnotify{ 'resource in defined type': }\n}" }
21
+
22
+ it 'should not detect any problems' do
23
+ expect(problems).to have(0).problems
24
+ end
25
+ end
26
+
27
+ context 'resource outside, after of a class definition' do
28
+ let(:code) { "class foo{ }\nnotify{'badfoo': }" }
29
+
30
+ it 'should create a warning' do
31
+ expect(problems).to contain_warning(class_msg).on_line(2)
32
+ end
33
+ end
34
+
35
+ context 'resource outside of, after, a defined type' do
36
+ let(:code) { "define bar{}\nnotify{'resource after define':}\n}" }
37
+
38
+ it 'should create a warning' do
39
+ expect(problems).to contain_warning(define_msg).on_line(2)
40
+ end
41
+ end
42
+
43
+ context 'resource outside of, before, a class definition' do
44
+ let(:code) { "notify{'badfoo': }\nclass foo{ }\n" }
45
+
46
+ it 'should create a warning' do
47
+ expect(problems).to contain_warning(class_msg).on_line(1)
48
+ end
49
+ end
50
+
51
+ context 'resource outside, before, of a defined type' do
52
+ let(:code) { "notify{'resource before define':}\ndefine bar{}" }
53
+
54
+ it 'should create a warning' do
55
+ expect(problems).to contain_warning(define_msg).on_line(1)
56
+ end
57
+ end
58
+
59
+ context 'resource with no class or define present' do
60
+ let(:code) { "notify{'no classes!': }" }
61
+
62
+ it 'should create a warning' do
63
+ expect(problems).to contain_warning(no_class_or_define_msg).on_line(1)
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-resource_outside_class-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lee Lowder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-collection_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |2
84
+ A puppet-lint plugin to check that manifest files do not contain resources outside of a class or defined type definition.
85
+ email: friedbob@keepingyouhonest.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - LICENSE
92
+ - lib/puppet-lint/plugins/check_resource_outside_class.rb
93
+ - spec/puppet-lint/plugins/check_resource_outside_class_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: https://github.com/llowder/puppet-lint-resource_outside_class-check
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.14
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: A puppet-lint plugin to check for resources outside of a class or defiend
119
+ type definition.
120
+ test_files:
121
+ - spec/puppet-lint/plugins/check_resource_outside_class_spec.rb
122
+ - spec/spec_helper.rb