yaml-lint 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/bin/yaml-lint +28 -12
  3. data/lib/yaml-lint.rb +17 -18
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTYxMmQzMTYwNDM0ZmQ5NjM1MGY2MjVjYmU1MmIxYzUwNzVkY2ZmNA==
4
+ NzBkMTg3YjFhODU5YjllMWYwY2U2NDM2NTgxMDgzNWRjNjY1YjlmZQ==
5
5
  data.tar.gz: !binary |-
6
- NGVhNGE4MTQ5ZTAxNDEzNDRhNTQ5ZTJhNjgzYWJiZjUzZjZjMWQzNg==
6
+ OGI5OTk3Mjg5YjU1ZDNmMzNiYmMxODRkNDAzZWUyMzEwNzE3Njk1NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmVjNGI5Y2RiZDEwMjQyN2Q4YjEyYzkyN2QzNDk0ZTQyZjM4ZTg1N2NkMjQx
10
- ZjMwZGEwNmI0ZDcwNjZmYTYxNDNkODg2NjNlMDJjZjNlZTY4Yzk5YjE3YzZk
11
- NmQ5MTllYTJmOGFjMGZiNDYwMWI0MGQ3ZTFiMGM2Nzg2YjM4MmE=
9
+ NzEyODNmYTNkMWQ5ODk1YmZhYjFhNDUxZGY3MWEyM2NkOTExZmE2M2Q1ZWNh
10
+ ZTcyYWI4NTJjYzFkYmVhNGI1YjQ1ZTIyMmE3OGJmMjhmNThmYWY3MTk5ZDNk
11
+ YzFhODNhNzc1MjUxMjAwOGQ1NmQwNTI0YTI3NjQzMjM0NmE1YTM=
12
12
  data.tar.gz: !binary |-
13
- YzYyOWFjNjY5NjkyMmI3ZjI4MmM5NTBiNmJiMmYyOTZkOTdkOWVhMzAxYTE4
14
- MmIzZjQ3ZjhjZDY2NDVhZjBlZTQ1ZTZkN2JkOTg5NDJjOWFmOWFlM2RmNjg1
15
- YzAyNzVkMjhjOGYzMzhjN2Q5ODBjYzUwNjA2MmY4ZjQxY2QzMmE=
13
+ MTgwZjY5M2Y2OGY1NTQ0NzFhYWMwMGNkYWQ2MzE4ZDg1YmIxYjI1OTk4NWI1
14
+ ZmE3OTBjNWY5NmZlMTQ2NjM4ZjliZTAwNDQwOGZmZjFmN2UxYjliYTY5ZTE3
15
+ MWU4MTIxZTU2ZGFhMGUzZjU2OGJmM2E1NTViMDMwM2JiYzI0YjU=
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'yaml'
4
+ require 'optparse'
4
5
 
5
6
  begin
6
7
  require 'yaml-lint'
@@ -9,21 +10,36 @@ rescue LoadError
9
10
  require 'yaml-lint'
10
11
  end
11
12
 
12
- if ARGV.any? {|arg| arg =~ /^help$|^--help|^-h|^-/} or ARGV.empty?
13
- puts 'yaml-lint is a tool to check the syntax of your YAML files'
14
- puts 'Usage: yaml-lint <file(s) or folder(s)>'
15
- exit 1
16
- end
13
+ options = {}
14
+ OptionParser.new do |opts|
15
+ opts.banner = "Usage: yaml-lint <file(s) or folder(s)>"
16
+
17
+ opts.on("-q", "--quiet", "Run quiet. Only log failing files.") do |q|
18
+ options[:quiet] = q
19
+ end
20
+ opts.on("-Q", "--very-quiet", "Run more quiet. Return code is the number of failed files.") do |q|
21
+ options[:veryquiet] = q
22
+ end
23
+
24
+ opts.on("-n", "--no-check-file-ext", "Do not check the file extension to match known yaml files.") do |n|
25
+ options[:nocheckfileext] = true
26
+ end
27
+
28
+ opts.on_tail("-h", "--help") do |q|
29
+ puts 'yaml-lint is a tool to check the syntax of your YAML files'
30
+ puts 'Usage: yaml-lint <file(s) or folder(s)>'
31
+ exit -1
32
+ end
33
+ end.parse!
17
34
 
18
- puts "Checking the content of #{ARGV}"
35
+ puts "Checking the content of #{ARGV}" unless options[:quiet]
19
36
 
20
- bad_result = false
37
+ failed = 0
21
38
 
22
39
  ARGV.each do|file|
23
- lint = YamlLint.new(file)
24
- result = lint.do_lint
25
- bad_result = true unless result
40
+ lint = YamlLint.new(file, options)
41
+ failed = failed + lint.do_lint
26
42
  end
27
43
 
28
- puts 'Done.'
29
- exit bad_result ? 1 : 0
44
+ puts 'Done.' unless options[:quiet]
45
+ exit failed
@@ -9,15 +9,15 @@ module Logging
9
9
  :reset => "\033[0m" }
10
10
 
11
11
  def info(message)
12
- emit(:message => message, :color => :green)
12
+ emit(:message => message, :color => :green) unless @config[:quiet]
13
13
  end
14
14
 
15
15
  def warn(message)
16
- emit(:message => message, :color => :yellow)
16
+ emit(:message => message, :color => :yellow) unless @config[:veryquiet]
17
17
  end
18
18
 
19
19
  def error(message)
20
- emit(:message => message, :color => :red)
20
+ emit(:message => message, :color => :red) unless @config[:veryquiet]
21
21
  end
22
22
 
23
23
  def emit(opts={})
@@ -33,50 +33,49 @@ end
33
33
  class YamlLint
34
34
  include Logging
35
35
 
36
- def initialize(file)
36
+ def initialize(file, config={})
37
37
  @file = file
38
- @error = false
38
+ @config = config
39
+ @config[:quiet] = true if @config[:veryquiet]
40
+ @config[:nocheckfileext] ||= false
39
41
  end
40
42
 
41
43
  def do_lint
42
44
  unless File.exists? @file
43
45
  error "File #{@file} does not exist"
44
- @error = true
46
+ return 0
45
47
  else
46
48
  if File.directory? @file
47
- self.parse_directory @file
49
+ return self.parse_directory @file
48
50
  else
49
- self.parse_file @file
51
+ return self.parse_file @file
50
52
  end
51
53
  end
52
- @error ? false : true
53
54
  end
54
55
 
55
56
  def parse_directory(directory)
56
- Dir.glob("#{directory}/*").each do |fdir|
57
+ Dir.glob("#{directory}/*").inject(0) do |mem, fdir|
57
58
  if File.directory? fdir
58
- self.parse_directory fdir
59
+ mem + parse_directory(fdir)
59
60
  else
60
- self.parse_file fdir
61
+ mem + parse_file(fdir)
61
62
  end
62
63
  end
63
- nil
64
64
  end
65
65
 
66
66
  def parse_file(file)
67
- unless File.extname(file) =~ /.(yaml|yml)$/
67
+ if (not File.extname(file) =~ /.(yaml|yml)$/) && (not @config[:nocheckfileext])
68
68
  error "The extension of the file #{file} should be .yaml or .yml"
69
- @error = true
70
- return
69
+ return 1
71
70
  end
72
71
  begin
73
72
  YAML.load_file(file)
74
73
  rescue Exception => err
75
74
  error "File : #{file}, error: #{err}"
76
- @error = true
75
+ return 1
77
76
  else
78
77
  info "File : #{file}, Syntax OK"
78
+ return 0
79
79
  end
80
- nil
81
80
  end
82
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Fabre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Check if your YAML files can be loaded.
14
14
  email: ju.pryz@gmail.com
@@ -19,7 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/yaml-lint
21
21
  - lib/yaml-lint.rb
22
- homepage:
22
+ homepage: https://github.com/Pryz/yaml-lint
23
23
  licenses:
24
24
  - MIT
25
25
  metadata: {}