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 +4 -4
- data/Gemfile.lock +1 -1
- data/REUSE.toml +1 -0
- data/bin/xcop +5 -1
- data/features/cli.feature +10 -0
- data/features/step_definitions/steps.rb +5 -0
- data/fixtures/idempotent/attributes.xml +5 -0
- data/fixtures/idempotent/cdata.xml +2 -0
- data/fixtures/idempotent/comment-multi-line.xml +7 -0
- data/fixtures/idempotent/comment-single-line.xml +4 -0
- data/fixtures/idempotent/deep-nesting.xml +8 -0
- data/fixtures/idempotent/empty-elements.xml +6 -0
- data/fixtures/idempotent/entities.xml +2 -0
- data/fixtures/idempotent/maven-pom.xml +4 -0
- data/fixtures/idempotent/mixed-content.xml +2 -0
- data/fixtures/idempotent/namespace-used.xml +4 -0
- data/fixtures/idempotent/nested.xml +6 -0
- data/fixtures/idempotent/non-xml.txt +1 -0
- data/fixtures/idempotent/simple.xml +2 -0
- data/fixtures/idempotent/xslt-xpath-namespace.xml +4 -0
- data/lib/xcop/document.rb +12 -2
- data/lib/xcop/version.rb +1 -1
- metadata +18 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 682e51f3798d3495937a198b772be9a23be624990096e179575318285873761c
|
|
4
|
+
data.tar.gz: 9f4002c4337e4a2f90bea041a43c6eed471049694a78220855b02b31a1bd672c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13b1cb456fb7d0aabd5e5d1222af05ff1ac4c50c080e31c63a7085c48a4ad248c421fe2736dee02e2bcb574e74dc4634a77e30637ac37a7f441212a4ed4d8b20
|
|
7
|
+
data.tar.gz: 7a8d17f560e2b635eab9b63319d4c7bdcd34cd658ae22a45c102269575486ca4704952f17ba7320cd5fbc170cd322a2e06e0e3157983bf3c70314de88bc7a5b0
|
data/Gemfile.lock
CHANGED
data/REUSE.toml
CHANGED
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
|
-
|
|
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,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 @@
|
|
|
1
|
+
hello world
|
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
|
|
28
|
-
#
|
|
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
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.
|
|
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:
|
|
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.
|
|
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: []
|