xcop 0.11.1 → 0.11.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 682e51f3798d3495937a198b772be9a23be624990096e179575318285873761c
4
- data.tar.gz: 9f4002c4337e4a2f90bea041a43c6eed471049694a78220855b02b31a1bd672c
3
+ metadata.gz: eb96da46dd45869ca97de4ff90e49d286b85ce1a36e0a3ce9fefac7626788007
4
+ data.tar.gz: 9f4e402e0a8cf397494c07dcacf9f5523d18c48872c5bdefe9d7977f1b3f765e
5
5
  SHA512:
6
- metadata.gz: 13b1cb456fb7d0aabd5e5d1222af05ff1ac4c50c080e31c63a7085c48a4ad248c421fe2736dee02e2bcb574e74dc4634a77e30637ac37a7f441212a4ed4d8b20
7
- data.tar.gz: 7a8d17f560e2b635eab9b63319d4c7bdcd34cd658ae22a45c102269575486ca4704952f17ba7320cd5fbc170cd322a2e06e0e3157983bf3c70314de88bc7a5b0
6
+ metadata.gz: b482311a5a738c1d1ea16fbea987866c8962fe09b62e7c216b89b4895ec4b70133a8d9e32a036734466c722fee090eb45441f8a6f2729b8a993388d1768a0b57
7
+ data.tar.gz: 3cd551264e7b205d947e15c19f0291b7567789d497bd0af183cf1a3975d6eb2d306b6523fd25fa3cb4cf8ec34e150165f7209829e082bcfdab8b68dfec0db0fa
data/bin/xcop CHANGED
@@ -76,8 +76,12 @@ if opts.fix?
76
76
  end
77
77
  else
78
78
  begin
79
- Xcop::CLI.new(files, nocolor: opts.nocolor?).run do |f|
80
- puts "#{f} looks good" unless opts.quiet?
79
+ Xcop::CLI.new(files, nocolor: opts.nocolor?).run do |f, status|
80
+ if status == :malformed
81
+ puts "#{f} is not a well-formed XML, skipping it"
82
+ elsif !opts.quiet?
83
+ puts "#{f} looks good"
84
+ end
81
85
  end
82
86
  rescue StandardError => e
83
87
  puts e.message
data/features/cli.feature CHANGED
@@ -54,6 +54,15 @@ Feature: Command Line Processing
54
54
  And Exit code is zero
55
55
  And The file "garbage.xml" contains "this is not XML"
56
56
 
57
+ Scenario: Skipping a plain text file while checking
58
+ Given I have a "foo.txt" file with content:
59
+ """
60
+ not xml at all
61
+ """
62
+ When I run bin/xcop with "foo.txt"
63
+ Then Stdout contains "is not a well-formed XML, skipping it"
64
+ And Exit code is zero
65
+
57
66
  Scenario: Validating all files in the current directory by default
58
67
  Given I have a "auto.xml" file with content:
59
68
  """
data/lib/xcop/cli.rb CHANGED
@@ -24,9 +24,16 @@ class Xcop::CLI
24
24
  EXTENSIONS.flat_map { |ext| Dir.glob(File.join(dir, '**', "*.#{ext}")) }.sort
25
25
  end
26
26
 
27
+ # Check them all. The block, when given, receives the file path and a
28
+ # status symbol that is +:good+ when the file is clean and
29
+ # +:malformed+ when the file is not XML at all and was skipped.
27
30
  def run
28
31
  @files.each do |f|
29
32
  doc = Xcop::Document.new(f)
33
+ unless doc.wellformed?
34
+ yield(f, :malformed) if block_given?
35
+ next
36
+ end
30
37
  diff = doc.diff(nocolor: @nocolor)
31
38
  unless diff.empty?
32
39
  puts(diff)
@@ -37,7 +44,7 @@ class Xcop::CLI
37
44
  puts(errors.join("\n"))
38
45
  raise(StandardError, "XSD validation failed in #{f}")
39
46
  end
40
- yield(f) if block_given?
47
+ yield(f, :good) if block_given?
41
48
  end
42
49
  end
43
50
 
data/lib/xcop/document.rb CHANGED
@@ -18,6 +18,15 @@ class Xcop::Document
18
18
  @path = path
19
19
  end
20
20
 
21
+ # Is the document well-formed XML? Nokogiri parses in recover mode
22
+ # and never raises, so a broken file yields a rootless document that
23
+ # +to_xml+ renders as an empty declaration; a fatal parse error is
24
+ # the signal that the file is not XML and thus can neither be
25
+ # reformatted nor sensibly compared to its ideal. See #173 and #175.
26
+ def wellformed?
27
+ Nokogiri::XML(File.read(@path)).errors.none?(&:fatal?)
28
+ end
29
+
21
30
  # Return the difference, if any (empty string if everything is clean).
22
31
  def diff(nocolor: false)
23
32
  differ(ideal, File.read(@path), nocolor: nocolor)
@@ -52,14 +61,6 @@ class Xcop::Document
52
61
 
53
62
  private
54
63
 
55
- # Is the document well-formed XML? Nokogiri parses in recover mode
56
- # and never raises, so a broken file yields a rootless document that
57
- # +to_xml+ renders as an empty declaration; a fatal parse error is
58
- # the signal that the file cannot be safely reformatted. See #173.
59
- def wellformed?
60
- Nokogiri::XML(File.read(@path)).errors.none?(&:fatal?)
61
- end
62
-
63
64
  # The canonical, well-formatted version of the document.
64
65
  def ideal
65
66
  xml = Nokogiri::XML(File.read(@path), &:noblanks)
@@ -35,8 +35,8 @@ class Xcop::RakeTask < Rake::TaskLib
35
35
  good = Dir.glob(@includes).reject { |f| bad.include?(f) }
36
36
  puts("Inspecting #{pluralize(good.length, 'file')}...") unless @quiet
37
37
  begin
38
- Xcop::CLI.new(good).run do
39
- print(Rainbow('.').green) unless @quiet
38
+ Xcop::CLI.new(good).run do |_f, status|
39
+ print(status == :malformed ? Rainbow('?').yellow : Rainbow('.').green) unless @quiet
40
40
  end
41
41
  rescue StandardError => e
42
42
  puts(e.message)
data/lib/xcop/version.rb CHANGED
@@ -6,5 +6,5 @@
6
6
  # Copyright:: Copyright (c) 2017-2026 Yegor Bugayenko
7
7
  # License:: MIT
8
8
  module Xcop
9
- VERSION = '0.11.1'.freeze
9
+ VERSION = '0.11.2'.freeze
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko