mini_yaml 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fa30f1798b3119df42e4be52f6ca36619d032cf191d6eb1e50160f71de8bbff
4
- data.tar.gz: eef3d0553e5e81cb2ff7f69c59dc88e0b1104062f146afd342b32809693295a7
3
+ metadata.gz: af9cb20015b87c2bdb276d606ec4c6ab05900ea52e54dfa2c639400e2ca791d6
4
+ data.tar.gz: e01087aebc3b3ae185d7069a07f69653dea91d8d52bb1e076b2d8c7e9ba7676e
5
5
  SHA512:
6
- metadata.gz: b76adc1db8c66c704ae91384686ea930fa723a4c85c06adc1eaeed324c9987933755989113e817f24c85096b882e72ab39560e797ad310dd0171034109c66097
7
- data.tar.gz: 70ad69d46711d73f698e7e0ca347fdeb7ebe9ad913cfac9d4e0a14eba552048a06067902a27a7b95656fab4897c5ec7c461c53f9c0d1a92a16b3bcca0de39128
6
+ metadata.gz: c87b291289805c9079b58606dfff79e425c01f975ab3c3c774995389f7c75335301405b789d918b8d7e66945593e26d16561a7d0a1b73cddcac7ce4d5a92378c
7
+ data.tar.gz: a564898b9bc356ed39426ce82f7a80948ce7318688a29bfe208db16165cc44adb846781fd858e7a1aec42dcca68c9db80b3f9e6b6d8bf5a865a0cdbcc8f973d9
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
data/README.md CHANGED
@@ -25,7 +25,48 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- TODO: Write usage instructions here
28
+
29
+ To lint an indevidual file use:
30
+
31
+ ```ruby
32
+ lint-yaml FILENAME
33
+ ```
34
+
35
+ To amend an existing YAML file use:
36
+
37
+ ```ruby
38
+ yaml = <<~YAML
39
+ # comment
40
+ - "a"
41
+ - b
42
+ YAML
43
+
44
+ linter = MiniYaml::Linter.new(yaml)
45
+ linter.contents << "c"
46
+
47
+ puts linter.dump
48
+
49
+ ```
50
+
51
+ This will output:
52
+
53
+ ```
54
+ ---
55
+ # comment
56
+ - a
57
+ - b
58
+ - c
59
+ ```
60
+
61
+ ## Why not use prettier or some other tool?
62
+
63
+ mini_yaml is deliberately opinionated. It enforces line length, chooses quoting styles and maintains comments.
64
+
65
+ Prettier unfortunately is not as opinionated, it will not enforce quoting styles, line length and styles for multiple line strings and so on. This means that you can not rely on it to force consistent styling of YAML in your project.
66
+
67
+ ## Why not use mini-yaml?
68
+
69
+ MiniYaml is extremely experimental, it includes a "paranoid" mode by default which makes it impossible that it will corrupt YAML, that said, it certainly may have bugs and may fail to handle all sorts of YAML files.
29
70
 
30
71
  ## Development
31
72
 
data/bin/lint-yaml ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5
+
6
+ require "mini_yaml"
7
+
8
+ def usage
9
+ STDERR.puts "Usage: yaml-lint FILENAME"
10
+ exit 1
11
+ end
12
+
13
+ if !ARGV[0] || !File.exist?(ARGV[0])
14
+ usage
15
+ end
16
+
17
+ puts MiniYaml::Linter.new(File.read(ARGV[0])).dump
18
+
@@ -3,9 +3,10 @@ require 'yaml'
3
3
 
4
4
  module MiniYaml
5
5
  class Linter
6
- def initialize(yaml, paranoid: true)
6
+ def initialize(yaml, paranoid: true, columns: 80)
7
7
  @comment_map = nil
8
8
  @parsed = parse(yaml)
9
+ @columns = columns
9
10
 
10
11
  if paranoid
11
12
  before, before_e, after, after_e = nil
@@ -88,7 +89,7 @@ module MiniYaml
88
89
  prev_char = line[index - 1]
89
90
  next_char = line[index + 1]
90
91
 
91
- if col > 80 && char == " " && prev_char.match?(/\S/) && next_char.match?(/\S/)
92
+ if col > @columns && char == " " && prev_char.match?(/\S/) && next_char.match?(/\S/)
92
93
  buf << "\n"
93
94
  col = 0
94
95
  else
@@ -124,9 +125,9 @@ module MiniYaml
124
125
 
125
126
  val = val.to_s
126
127
 
127
- if val.include?("\n") || val.length > 80
128
+ if val.include?("\n") || val.length > @columns
128
129
  lines = val.split("\n")
129
- force_short = lines.map(&:length).max > 80
130
+ force_short = lines.map(&:length).max > @columns
130
131
  strip_trailing_newline = val[-1] != "\n"
131
132
 
132
133
  if force_short
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniYaml
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/mini_yaml.gemspec CHANGED
@@ -21,10 +21,9 @@ Gem::Specification.new do |spec|
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
23
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test)/}) }
25
25
  end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.executables = "lint-yaml"
28
27
  spec.require_paths = ["lib"]
29
28
 
30
29
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
@@ -84,7 +84,8 @@ description: YAML editor that preserves comments and formats YAML using opiniona
84
84
  rules
85
85
  email:
86
86
  - sam.saffron@gmail.com
87
- executables: []
87
+ executables:
88
+ - lint-yaml
88
89
  extensions: []
89
90
  extra_rdoc_files: []
90
91
  files:
@@ -94,13 +95,11 @@ files:
94
95
  - CHANGELOG.md
95
96
  - CODE_OF_CONDUCT.md
96
97
  - Gemfile
97
- - Gemfile.lock
98
98
  - Guardfile
99
99
  - LICENSE.txt
100
100
  - README.md
101
101
  - Rakefile
102
- - bin/console
103
- - bin/setup
102
+ - bin/lint-yaml
104
103
  - lib/mini_yaml.rb
105
104
  - lib/mini_yaml/linter.rb
106
105
  - lib/mini_yaml/version.rb
data/Gemfile.lock DELETED
@@ -1,77 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mini_yaml (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.2)
10
- coderay (1.1.3)
11
- ffi (1.15.0)
12
- formatador (0.2.5)
13
- guard (2.16.2)
14
- formatador (>= 0.2.4)
15
- listen (>= 2.7, < 4.0)
16
- lumberjack (>= 1.0.12, < 2.0)
17
- nenv (~> 0.1)
18
- notiffany (~> 0.0)
19
- pry (>= 0.9.12)
20
- shellany (~> 0.0)
21
- thor (>= 0.18.1)
22
- guard-compat (1.2.1)
23
- guard-minitest (2.4.6)
24
- guard-compat (~> 1.2)
25
- minitest (>= 3.0)
26
- listen (3.5.1)
27
- rb-fsevent (~> 0.10, >= 0.10.3)
28
- rb-inotify (~> 0.9, >= 0.9.10)
29
- lumberjack (1.2.8)
30
- method_source (1.0.0)
31
- minitest (5.14.4)
32
- nenv (0.3.0)
33
- notiffany (0.1.3)
34
- nenv (~> 0.1)
35
- shellany (~> 0.0)
36
- parallel (1.20.1)
37
- parser (3.0.1.1)
38
- ast (~> 2.4.1)
39
- pry (0.14.1)
40
- coderay (~> 1.1)
41
- method_source (~> 1.0)
42
- rainbow (3.0.0)
43
- rake (13.0.3)
44
- rb-fsevent (0.11.0)
45
- rb-inotify (0.10.1)
46
- ffi (~> 1.0)
47
- regexp_parser (2.1.1)
48
- rexml (3.2.5)
49
- rubocop (1.14.0)
50
- parallel (~> 1.10)
51
- parser (>= 3.0.0.0)
52
- rainbow (>= 2.2.2, < 4.0)
53
- regexp_parser (>= 1.8, < 3.0)
54
- rexml
55
- rubocop-ast (>= 1.5.0, < 2.0)
56
- ruby-progressbar (~> 1.7)
57
- unicode-display_width (>= 1.4.0, < 3.0)
58
- rubocop-ast (1.5.0)
59
- parser (>= 3.0.1.1)
60
- ruby-progressbar (1.11.0)
61
- shellany (0.0.1)
62
- thor (1.1.0)
63
- unicode-display_width (2.0.0)
64
-
65
- PLATFORMS
66
- x86_64-linux
67
-
68
- DEPENDENCIES
69
- guard
70
- guard-minitest
71
- mini_yaml!
72
- minitest
73
- rake
74
- rubocop
75
-
76
- BUNDLED WITH
77
- 2.2.17
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "mini_yaml"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here