puppet-cleaner 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.1.1 2013-04-26
2
+ -----------------
3
+ Bug fix:
4
+ * uninitialized constant Puppet::Cleaner::Worker (NameError) runtime error fixed
5
+
1
6
  0.1.0 2013-04-16
2
7
  -----------------
3
8
  Features:
data/README.md CHANGED
@@ -20,8 +20,27 @@ Utilities
20
20
  ### puppet-clean
21
21
 
22
22
  Receives a puppet manifest file as input and outputs the result of
23
- applying a set of transformation rules that makes it comply with
24
- a subset of the current puppet style guide.
23
+ applying the set of transformation rules that you select. If no options
24
+ are selected all of them are applied, which currently is a subset of the
25
+ puppet style guide.
26
+
27
+ Usage:
28
+
29
+ puppet-clean [-h] [-t n] [-abedlmovw ] file.pp [file2.pp...]
30
+
31
+ Options:
32
+ -h, --help this help message
33
+ -d, --debug prints tokens before and after the transformation
34
+
35
+ -a, --alignfarrow aligns fat arrow (=>)
36
+ -b, --quotedbooleans removes unneeded quotes around boolean literals
37
+ -e, --ensurefirst moves 'ensure' parameter to the top
38
+ -l, --link uses ensure => link and target for symbolic links
39
+ -m, --mlcomments converts /* */ style comments into #
40
+ -o, --octalmode uses a 4 digit string for file modes
41
+ -t n, --softtabs n indents by n spaces
42
+ -v, --quotedvariables removes unneeded quotes around variables
43
+ -w, --trailingws removes trailing white space
25
44
 
26
45
  ### puppet-diff
27
46
 
@@ -0,0 +1,32 @@
1
+ module Puppet::Cleaner
2
+ class UnquotedTitles < Worker
3
+ def part_names
4
+ [:COLON]
5
+ end
6
+
7
+ def operate(line)
8
+ pos = line.position - 1
9
+ pos -= 1 while [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name)
10
+ return if line.parts[pos].name == :STRING
11
+
12
+ ####
13
+ =begin
14
+ start, pos = get_param(line, 'ensure', line.position)
15
+ return if start.nil?
16
+
17
+ ensure_param = line.parts.slice!(start..pos)
18
+ ensure_param += [Part.create([:COMMA, {:value => ","}])] unless ensure_param[-1].name == :COMMA
19
+
20
+ pos = start
21
+ if line.parts[pos].name == :SEMIC
22
+ commapos = start - 1
23
+ commapos -= 1 while [:RETURN, :BLANK].include?(line.parts[commapos])
24
+ line.parts.delete_at(commapos)
25
+ end
26
+
27
+ line.append(line.position, ensure_param)
28
+ =end
29
+ ####
30
+ end
31
+ end
32
+ end
@@ -1,2 +1,62 @@
1
+ module Puppet::Cleaner
2
+ class Worker
3
+ def part_names
4
+ raise "Must be implemented in subclass"
5
+ end
6
+
7
+ def operate
8
+ raise "Must be implemented in subclass"
9
+ end
10
+
11
+ def get_param(line, param_name, pos)
12
+ depth = 1
13
+
14
+ loop do
15
+ pos += 1
16
+ break if depth == 0 || pos >= line.parts.size
17
+ case line.parts[pos].name
18
+ when :LBRACE, :COLON
19
+ depth += 1
20
+ when :RBRACE
21
+ depth -= 1
22
+ when :SEMIC
23
+ depth -= 1
24
+ when :FARROW
25
+ next if depth != 1
26
+
27
+ parampos = pos - 1
28
+ parampos -= 1 while [:BLANK, :RETURN].include?(line.parts[parampos].name)
29
+ next unless line.parts[parampos].name == :NAME && line.parts[parampos].value == param_name
30
+ start = parampos - 1
31
+ start -= 1 while [:BLANK, :RETURN].include?(line.parts[start].name)
32
+ start += 1
33
+
34
+ loop do
35
+ pos += 1
36
+ break if depth < 0 || pos >= line.parts.size
37
+ case line.parts[pos].name
38
+ when :LBRACE
39
+ depth += 1
40
+ when :COMMA, :SEMIC, :RBRACE
41
+ depth -= 1 if line.parts[pos].name == :RBRACE
42
+ next if depth > 1
43
+ pos += 1 if line.parts[pos].name == :RBRACE && depth == 1
44
+ pos += 1 while pos < line.parts.size && ![:COMMA, :SEMIC, :RBRACE].include?(line.parts[pos].name)
45
+ break
46
+ end
47
+ end
48
+
49
+ return nil if pos >= line.parts.size
50
+ pos -= 1 unless line.parts[pos].name == :COMMA
51
+ pos -= 1 while [:BLANK, :RETURN].include?(line.parts[pos].name)
52
+
53
+ return [start, pos]
54
+ end
55
+ end
56
+ nil
57
+ end
58
+ end
59
+ end # module
60
+
1
61
  workersglob = File.join(File.dirname(__FILE__), "workers", "*.rb")
2
62
  Dir[workersglob].each {|worker| require worker }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerardo Santana Gomez Garrido
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-18 00:00:00 Z
18
+ date: 2013-04-26 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Cleans puppet source code
@@ -35,12 +35,12 @@ files:
35
35
  - lib/puppet-cleaner/inspect.rb
36
36
  - lib/puppet-cleaner/workers.rb
37
37
  - lib/puppet-cleaner/workers/quotedbooleans.rb
38
- - lib/puppet-cleaner/workers/worker.rb
39
38
  - lib/puppet-cleaner/workers/unneededquotes.rb
40
39
  - lib/puppet-cleaner/workers/multilinecomments.rb
41
40
  - lib/puppet-cleaner/workers/trailingwhitespaceincomments.rb
42
41
  - lib/puppet-cleaner/workers/trailingwhitespace.rb
43
42
  - lib/puppet-cleaner/workers/symlink.rb
43
+ - lib/puppet-cleaner/workers/unquotedtitles.rb
44
44
  - lib/puppet-cleaner/workers/alignfarrow.rb
45
45
  - lib/puppet-cleaner/workers/ensurefirst.rb
46
46
  - lib/puppet-cleaner/workers/octalmode.rb
@@ -1,59 +0,0 @@
1
- module Puppet::Cleaner
2
- class Worker
3
- def part_names
4
- raise "Must be implemented in subclass"
5
- end
6
-
7
- def operate
8
- raise "Must be implemented in subclass"
9
- end
10
-
11
- def get_param(line, param_name, pos)
12
- depth = 1
13
-
14
- loop do
15
- pos += 1
16
- break if depth == 0 || pos >= line.parts.size
17
- case line.parts[pos].name
18
- when :LBRACE, :COLON
19
- depth += 1
20
- when :RBRACE
21
- depth -= 1
22
- when :SEMIC
23
- depth -= 1
24
- when :FARROW
25
- next if depth != 1
26
-
27
- parampos = pos - 1
28
- parampos -= 1 while [:BLANK, :RETURN].include?(line.parts[parampos].name)
29
- next unless line.parts[parampos].name == :NAME && line.parts[parampos].value == param_name
30
- start = parampos - 1
31
- start -= 1 while [:BLANK, :RETURN].include?(line.parts[start].name)
32
- start += 1
33
-
34
- loop do
35
- pos += 1
36
- break if depth < 0 || pos >= line.parts.size
37
- case line.parts[pos].name
38
- when :LBRACE
39
- depth += 1
40
- when :COMMA, :SEMIC, :RBRACE
41
- depth -= 1 if line.parts[pos].name == :RBRACE
42
- next if depth > 1
43
- pos += 1 if line.parts[pos].name == :RBRACE && depth == 1
44
- pos += 1 while pos < line.parts.size && ![:COMMA, :SEMIC, :RBRACE].include?(line.parts[pos].name)
45
- break
46
- end
47
- end
48
-
49
- return nil if pos >= line.parts.size
50
- pos -= 1 unless line.parts[pos].name == :COMMA
51
- pos -= 1 while [:BLANK, :RETURN].include?(line.parts[pos].name)
52
-
53
- return [start, pos]
54
- end
55
- end
56
- nil
57
- end
58
- end
59
- end # module