puppet-lint-trailing_newline-check 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/lib/puppet-lint/plugins/check_trailing_newline.rb +17 -0
- data/spec/puppet-lint/plugins/check_trailing_newline_spec.rb +65 -0
- data/spec/spec_helper.rb +3 -0
- metadata +145 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tim Sharpe
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# puppet-lint plugin tutorial example code
|
2
|
+
|
3
|
+
**Note, this is code is part of the puppet-lint plugin development tutorial.
|
4
|
+
It should not be used as a real check and is provided as an example only.**
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
To use this plugin, add the following like to the Gemfile in your Puppet code
|
9
|
+
base and run `bundle install`.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'puppet-lint-tutorial-check'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
This plugin provides a new check to `puppet-lint`.
|
18
|
+
|
19
|
+
### trailing_newlines
|
20
|
+
|
21
|
+
**--fix support: Yes**
|
22
|
+
|
23
|
+
This check will raise a warning for any files that don't end in a trailing
|
24
|
+
newline.
|
25
|
+
|
26
|
+
```
|
27
|
+
WARNING: expected newline at the end of the file on line 56
|
28
|
+
```
|
@@ -0,0 +1,17 @@
|
|
1
|
+
PuppetLint.new_check(:trailing_newline) do
|
2
|
+
def check
|
3
|
+
last_token = tokens.last
|
4
|
+
|
5
|
+
unless last_token.type == :NEWLINE
|
6
|
+
notify :warning, {
|
7
|
+
:message => 'expected newline at the end of the file',
|
8
|
+
:line => last_token.line,
|
9
|
+
:column => manifest_lines.last.length,
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def fix(problem)
|
15
|
+
tokens << PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'trailing_newline' do
|
4
|
+
let(:msg) { 'expected newline at the end of the file' }
|
5
|
+
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'code not ending with a newline' do
|
8
|
+
let(:code) { "'test'" }
|
9
|
+
|
10
|
+
it 'should detect a single problem' do
|
11
|
+
expect(problems).to have(1).problem
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should create a warning' do
|
15
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(6)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'code ending with a newline' do
|
20
|
+
let(:code) { "'test'\n" }
|
21
|
+
|
22
|
+
it 'should not detect any problems' do
|
23
|
+
expect(problems).to have(0).problems
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with fix enabled' do
|
29
|
+
before do
|
30
|
+
PuppetLint.configuration.fix = true
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
PuppetLint.configuration.fix = false
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'code not ending in a newline' do
|
38
|
+
let(:code) { "'test'" }
|
39
|
+
|
40
|
+
it 'should only detect a single problem' do
|
41
|
+
expect(problems).to have(1).problem
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should fix the problem' do
|
45
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(6)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should add a newline to the end of the manifest' do
|
49
|
+
expect(manifest).to eq("'test'\n")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'code ending in a newline' do
|
54
|
+
let(:code) { "'test'\n" }
|
55
|
+
|
56
|
+
it 'should not detect any problems' do
|
57
|
+
expect(problems).to have(0).problems
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should not modify the manifest' do
|
61
|
+
expect(manifest).to eq(code)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-trailing_newline-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tim Sharpe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2014-08-18 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: puppet-lint
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
version: "1.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 7
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 0
|
48
|
+
version: "3.0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec-its
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 15
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 0
|
63
|
+
version: "1.0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rspec-collection_matchers
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 15
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 0
|
78
|
+
version: "1.0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
95
|
+
description: " Extends puppet-lint to ensure that your manifest files end with newlines.\n"
|
96
|
+
email: tim@sharpe.id.au
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
extra_rdoc_files: []
|
102
|
+
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- LICENSE
|
106
|
+
- lib/puppet-lint/plugins/check_trailing_newline.rb
|
107
|
+
- spec/puppet-lint/plugins/check_trailing_newline_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
has_rdoc: true
|
110
|
+
homepage: https://github.com/rodjek/puppet-lint-trailing_newline-check
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.6.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: puppet-lint trailing_newline check
|
143
|
+
test_files:
|
144
|
+
- spec/puppet-lint/plugins/check_trailing_newline_spec.rb
|
145
|
+
- spec/spec_helper.rb
|