xcop 0.11.0 → 0.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a0ba2b99c4feae8645eadd69e10c5c0f7c8de8d4340156e0da8a4d6d8786149
4
- data.tar.gz: bc7fec4a7cdf91bcdf90347b971f02c909cf0ff29b9fe1e2199855b27ab58cc8
3
+ metadata.gz: 682e51f3798d3495937a198b772be9a23be624990096e179575318285873761c
4
+ data.tar.gz: 9f4002c4337e4a2f90bea041a43c6eed471049694a78220855b02b31a1bd672c
5
5
  SHA512:
6
- metadata.gz: 817b6d81d029e5206a86ec914be5c1023bae23b1b31a7f6f4c3712e75ee45ca1220f35e10f91f85af3310b51fb00013d79e9846f41f45f2b0b45d1018f755cf3
7
- data.tar.gz: 0d78d15db07ec2cdb7009e45408721ff3fc66d2bd8ade2ed566689ebc7bedbdf26ea428b0adef6256f1e71d5c74c74d0b301487eac189a68386c21699f9e36b3
6
+ metadata.gz: 13b1cb456fb7d0aabd5e5d1222af05ff1ac4c50c080e31c63a7085c48a4ad248c421fe2736dee02e2bcb574e74dc4634a77e30637ac37a7f441212a4ed4d8b20
7
+ data.tar.gz: 7a8d17f560e2b635eab9b63319d4c7bdcd34cd658ae22a45c102269575486ca4704952f17ba7320cd5fbc170cd322a2e06e0e3157983bf3c70314de88bc7a5b0
data/Gemfile.lock CHANGED
@@ -91,7 +91,7 @@ GEM
91
91
  racc (~> 1.4)
92
92
  nokogiri (1.19.3-x86_64-linux-musl)
93
93
  racc (~> 1.4)
94
- parallel (1.28.0)
94
+ parallel (2.1.0)
95
95
  parser (3.3.12.0)
96
96
  ast (~> 2.4.1)
97
97
  racc
data/REUSE.toml CHANGED
@@ -8,6 +8,7 @@ path = [
8
8
  ".gitattributes",
9
9
  ".gitignore",
10
10
  ".pdd",
11
+ "fixtures/**",
11
12
  "**.json",
12
13
  "**.md",
13
14
  "**.png",
data/bin/xcop CHANGED
@@ -68,7 +68,11 @@ end
68
68
 
69
69
  if opts.fix?
70
70
  Xcop::CLI.new(files).fix do |f, status|
71
- puts "#{f} #{status}" unless opts.quiet?
71
+ if status == :malformed
72
+ puts "#{f} is not a well-formed XML, cannot fix it"
73
+ elsif !opts.quiet?
74
+ puts "#{f} #{status}"
75
+ end
72
76
  end
73
77
  else
74
78
  begin
data/features/cli.feature CHANGED
@@ -44,6 +44,16 @@ Feature: Command Line Processing
44
44
  Then I run bin/xcop with "broken.xml"
45
45
  Then Exit code is zero
46
46
 
47
+ Scenario: Refusing to fix a non-well-formed XML file
48
+ Given I have a "garbage.xml" file with content:
49
+ """
50
+ this is not XML
51
+ """
52
+ When I run bin/xcop with "--fix garbage.xml"
53
+ Then Stdout contains "is not a well-formed XML"
54
+ And Exit code is zero
55
+ And The file "garbage.xml" contains "this is not XML"
56
+
47
57
  Scenario: Validating all files in the current directory by default
48
58
  Given I have a "auto.xml" file with content:
49
59
  """
@@ -38,6 +38,11 @@ Then(/^Stdout contains "([^"]*)"$/) do |txt|
38
38
  raise(StandardError, "STDOUT doesn't contain '#{txt}':\n#{@stdout}") unless @stdout.include?(txt)
39
39
  end
40
40
 
41
+ Then(/^The file "([^"]*)" contains "([^"]*)"$/) do |file, txt|
42
+ body = File.read(file)
43
+ raise(StandardError, "File '#{file}' doesn't contain '#{txt}':\n#{body}") unless body.include?(txt)
44
+ end
45
+
41
46
  Then(/^Stdout is empty$/) do
42
47
  raise(StandardError, "STDOUT is not empty:\n#{@stdout}") unless @stdout == ''
43
48
  end
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0"?>
2
+ <config debug="true" level="5">
3
+ <item name="alpha" value="1"/>
4
+ <item name="beta" value="2"/>
5
+ </config>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <script><![CDATA[if (a < b) { return; }]]></script>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0"?>
2
+ <a>
3
+ <!--
4
+ line1
5
+ line2
6
+ -->
7
+ </a>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <a>
3
+ <!-- text -->
4
+ </a>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0"?>
2
+ <a>
3
+ <b>
4
+ <c>
5
+ <d>deep</d>
6
+ </c>
7
+ </b>
8
+ </a>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <gallery>
3
+ <image src="a.png"/>
4
+ <image src="b.png"/>
5
+ <break/>
6
+ </gallery>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <text>a &lt; b &amp; c &gt; d</text>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+ </project>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <p>Hello <b>bold</b> world</p>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <root xmlns:x="urn:x">
3
+ <x:child>value</x:child>
4
+ </root>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <root>
3
+ <parent>
4
+ <child>text</child>
5
+ </parent>
6
+ </root>
@@ -0,0 +1 @@
1
+ hello world
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <hello>Hello, world!</hello>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
3
+ <xsl:variable name="n" as="xs:integer" select="1"/>
4
+ </xsl:stylesheet>
data/lib/xcop/document.rb CHANGED
@@ -24,9 +24,11 @@ class Xcop::Document
24
24
  end
25
25
 
26
26
  # Fixes the document, returning +:fixed+ when the file content
27
- # changed on disk and +:untouched+ when the file was already
28
- # canonical.
27
+ # changed on disk, +:untouched+ when the file was already canonical,
28
+ # and +:malformed+ when the file is not well-formed XML and thus
29
+ # left on disk exactly as it was.
29
30
  def fix
31
+ return :malformed unless wellformed?
30
32
  canonical = ideal
31
33
  return :untouched if canonical == File.read(@path)
32
34
  File.write(@path, canonical)
@@ -50,6 +52,14 @@ class Xcop::Document
50
52
 
51
53
  private
52
54
 
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
+
53
63
  # The canonical, well-formatted version of the document.
54
64
  def ideal
55
65
  xml = Nokogiri::XML(File.read(@path), &:noblanks)
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.0'.freeze
9
+ VERSION = '0.11.1'.freeze
10
10
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-07-22 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: differ
@@ -72,8 +71,8 @@ executables:
72
71
  - xcop
73
72
  extensions: []
74
73
  extra_rdoc_files:
75
- - README.md
76
74
  - LICENSE.txt
75
+ - README.md
77
76
  files:
78
77
  - Gemfile
79
78
  - Gemfile.lock
@@ -90,6 +89,20 @@ files:
90
89
  - features/rake.feature
91
90
  - features/step_definitions/steps.rb
92
91
  - features/support/env.rb
92
+ - fixtures/idempotent/attributes.xml
93
+ - fixtures/idempotent/cdata.xml
94
+ - fixtures/idempotent/comment-multi-line.xml
95
+ - fixtures/idempotent/comment-single-line.xml
96
+ - fixtures/idempotent/deep-nesting.xml
97
+ - fixtures/idempotent/empty-elements.xml
98
+ - fixtures/idempotent/entities.xml
99
+ - fixtures/idempotent/maven-pom.xml
100
+ - fixtures/idempotent/mixed-content.xml
101
+ - fixtures/idempotent/namespace-used.xml
102
+ - fixtures/idempotent/nested.xml
103
+ - fixtures/idempotent/non-xml.txt
104
+ - fixtures/idempotent/simple.xml
105
+ - fixtures/idempotent/xslt-xpath-namespace.xml
93
106
  - lib/xcop/cli.rb
94
107
  - lib/xcop/document.rb
95
108
  - lib/xcop/rake_task.rb
@@ -101,7 +114,6 @@ licenses:
101
114
  - MIT
102
115
  metadata:
103
116
  rubygems_mfa_required: 'true'
104
- post_install_message:
105
117
  rdoc_options:
106
118
  - "--charset=UTF-8"
107
119
  require_paths:
@@ -117,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
129
  - !ruby/object:Gem::Version
118
130
  version: '0'
119
131
  requirements: []
120
- rubygems_version: 3.4.10
121
- signing_key:
132
+ rubygems_version: 3.6.9
122
133
  specification_version: 4
123
134
  summary: XML Formatting Static Validator
124
135
  test_files: []