yaml-lint-ng 0.0.5

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/yaml-lint +45 -0
  3. data/lib/yaml-lint.rb +80 -0
  4. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cde07a167f133b51a52f98fd9a07b15c1169642e
4
+ data.tar.gz: 58540d60e078614533834dea7e261a9adf838875
5
+ SHA512:
6
+ metadata.gz: 0ecbce10999947527e1bb56387f311b1f57f4febed2de46b2fc41ba10014498456980b53dba960e4bb6f714e1acc566576c4d19e2d332a0e0b390e2c5c1158b4
7
+ data.tar.gz: 6e3280772dd5112945c75713791b9fcddfe172b24315135492b5b8f5a1ba2b737d0307529f486f91c67cb4eaf86cd4504ff82244a1d204166082c8502f1d625e
data/bin/yaml-lint ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+ require 'optparse'
5
+
6
+ begin
7
+ require 'yaml-lint'
8
+ rescue LoadError
9
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ require 'yaml-lint'
11
+ end
12
+
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!
34
+
35
+ puts "Checking the content of #{ARGV}" unless options[:quiet]
36
+
37
+ failed = 0
38
+
39
+ ARGV.each do|file|
40
+ lint = YamlLint.new(file, options)
41
+ failed = failed + lint.do_lint
42
+ end
43
+
44
+ puts 'Done.' unless options[:quiet]
45
+ exit failed
data/lib/yaml-lint.rb ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+
5
+ module Logging
6
+ ESCAPES = { :green => "\033[32m",
7
+ :yellow => "\033[33m",
8
+ :red => "\033[31m",
9
+ :reset => "\033[0m" }
10
+
11
+ def info(message)
12
+ emit(:message => message, :color => :green) unless @config[:quiet]
13
+ end
14
+
15
+ def warn(message)
16
+ emit(:message => message, :color => :yellow) unless @config[:veryquiet]
17
+ end
18
+
19
+ def error(message)
20
+ emit(:message => message, :color => :red) unless @config[:veryquiet]
21
+ end
22
+
23
+ def emit(opts={})
24
+ color = opts[:color]
25
+ message = opts[:message]
26
+ print ESCAPES[color]
27
+ print message
28
+ print ESCAPES[:reset]
29
+ print "\n"
30
+ end
31
+ end
32
+
33
+ class YamlLint
34
+ include Logging
35
+
36
+ def initialize(file, config={})
37
+ @file = file
38
+ @config = config
39
+ @config[:quiet] = true if @config[:veryquiet]
40
+ @config[:nocheckfileext] ||= false
41
+ end
42
+
43
+ def do_lint
44
+ unless File.exists? @file
45
+ error "File #{@file} does not exist"
46
+ else
47
+ if File.directory? @file
48
+ return self.parse_directory @file
49
+ else
50
+ return self.parse_file @file
51
+ end
52
+ end
53
+ end
54
+
55
+ def parse_directory(directory)
56
+ Dir.glob("#{directory}/*").inject(0) do |mem, fdir|
57
+ if File.directory? fdir
58
+ mem + parse_directory(fdir)
59
+ else
60
+ mem + parse_file(fdir)
61
+ end
62
+ end
63
+ end
64
+
65
+ def parse_file(file)
66
+ if (not File.extname(file) =~ /.(yaml|yml)$/) && (not @config[:nocheckfileext])
67
+ error "The extension of the file #{file} should be .yaml or .yml"
68
+ return 1
69
+ end
70
+ begin
71
+ YAML.load_file(file)
72
+ rescue Exception => err
73
+ error "File : #{file}, error: #{err}"
74
+ return 1
75
+ else
76
+ info "File : #{file}, Syntax OK"
77
+ return 0
78
+ end
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml-lint-ng
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Julien Fabre
8
+ - Marvin Frick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Check if your YAML files can be loaded.
15
+ email:
16
+ - ju.pryz@gmail.com
17
+ - marvin.frick@sinnerschrader.com
18
+ executables:
19
+ - yaml-lint
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/yaml-lint
24
+ - lib/yaml-lint.rb
25
+ homepage: https://github.com/MrMarvin/yaml-lint
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Really simple YAML lint. Next interation.
49
+ test_files: []