yaml-lint 0.0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/yaml-lint +29 -0
  3. data/lib/yaml-lint.rb +82 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2b67729cb48d53e71145f812507b730219140ed
4
+ data.tar.gz: 84bdf134e0acae707050f7ad89e73df8c4b2cfcc
5
+ SHA512:
6
+ metadata.gz: be399913ebc9af60c94c9d1dcafdc75b67872cf385a7c202574d843a7f029608b54fb9a1c07b084f008f49d6fcd204216ebaf17f9f9d4d3f50c928c5bec04b0b
7
+ data.tar.gz: f2c3916a0a2a0fa6344a700f4f6da413967d435654fd56fcf840accce7ad5aedf765cd60ba25301e5f30db1b65ab6896e8e66cb52ab1ce0ee4c28a4318c04418
data/bin/yaml-lint ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+
5
+ begin
6
+ require 'yaml-lint'
7
+ rescue LoadError
8
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ require 'yaml-lint'
10
+ end
11
+
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
17
+
18
+ puts "Checking the content of #{ARGV}"
19
+
20
+ bad_result = false
21
+
22
+ ARGV.each do|file|
23
+ lint = YamlLint.new(file)
24
+ result = lint.do_lint
25
+ bad_result = true unless result and bad_result
26
+ end
27
+
28
+ puts 'Done.'
29
+ exit bad_result ? 1 : 0
data/lib/yaml-lint.rb ADDED
@@ -0,0 +1,82 @@
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)
13
+ end
14
+
15
+ def warn(message)
16
+ emit(:message => message, :color => :yellow)
17
+ end
18
+
19
+ def error(message)
20
+ emit(:message => message, :color => :red)
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)
37
+ @file = file
38
+ @error = false
39
+ end
40
+
41
+ def do_lint
42
+ unless File.exists? @file
43
+ error "File #{@file} does not exist"
44
+ @error = true
45
+ return
46
+ end
47
+ if File.directory? @file
48
+ self.parse_directory @file
49
+ else
50
+ self.parse_file @file
51
+ end
52
+ @error
53
+ end
54
+
55
+ def parse_directory(directory)
56
+ return nil if ['.', '..'].include? directory
57
+ Dir.glob("#{directory}/*").each do |fdir|
58
+ if File.directory? fdir
59
+ self.parse_directory fdir
60
+ else
61
+ self.parse_file fdir
62
+ end
63
+ end
64
+ nil
65
+ end
66
+
67
+ def parse_file(file)
68
+ unless File.extname(file) == ".yaml"
69
+ error "The extension of the file #{file} should be .yaml"
70
+ return
71
+ end
72
+ begin
73
+ YAML.load_file(file)
74
+ rescue Exception => err
75
+ error "File : #{file}, error: #{err}"
76
+ @error = true
77
+ else
78
+ info "File : #{file}, Syntax OK"
79
+ end
80
+ nil
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml-lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julien Fabre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Check if your YAML files can be loaded.
14
+ email: ju.pryz@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/yaml-lint.rb
20
+ - bin/yaml-lint
21
+ homepage:
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Really simple YAML lint
45
+ test_files: []