xcop 0.11.0 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/REUSE.toml +1 -0
- data/bin/xcop +11 -3
- data/features/cli.feature +19 -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/cli.rb +8 -1
- data/lib/xcop/document.rb +13 -2
- data/lib/xcop/rake_task.rb +2 -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: eb96da46dd45869ca97de4ff90e49d286b85ce1a36e0a3ce9fefac7626788007
|
|
4
|
+
data.tar.gz: 9f4e402e0a8cf397494c07dcacf9f5523d18c48872c5bdefe9d7977f1b3f765e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b482311a5a738c1d1ea16fbea987866c8962fe09b62e7c216b89b4895ec4b70133a8d9e32a036734466c722fee090eb45441f8a6f2729b8a993388d1768a0b57
|
|
7
|
+
data.tar.gz: 3cd551264e7b205d947e15c19f0291b7567789d497bd0af183cf1a3975d6eb2d306b6523fd25fa3cb4cf8ec34e150165f7209829e082bcfdab8b68dfec0db0fa
|
data/Gemfile.lock
CHANGED
data/REUSE.toml
CHANGED
data/bin/xcop
CHANGED
|
@@ -68,12 +68,20 @@ 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
|
|
75
|
-
Xcop::CLI.new(files, nocolor: opts.nocolor?).run do |f|
|
|
76
|
-
|
|
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
|
|
77
85
|
end
|
|
78
86
|
rescue StandardError => e
|
|
79
87
|
puts e.message
|
data/features/cli.feature
CHANGED
|
@@ -44,6 +44,25 @@ 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
|
+
|
|
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
|
+
|
|
47
66
|
Scenario: Validating all files in the current directory by default
|
|
48
67
|
Given I have a "auto.xml" file with content:
|
|
49
68
|
"""
|
|
@@ -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/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,15 +18,26 @@ 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)
|
|
24
33
|
end
|
|
25
34
|
|
|
26
35
|
# Fixes the document, returning +:fixed+ when the file content
|
|
27
|
-
# changed on disk
|
|
28
|
-
#
|
|
36
|
+
# changed on disk, +:untouched+ when the file was already canonical,
|
|
37
|
+
# and +:malformed+ when the file is not well-formed XML and thus
|
|
38
|
+
# left on disk exactly as it was.
|
|
29
39
|
def fix
|
|
40
|
+
return :malformed unless wellformed?
|
|
30
41
|
canonical = ideal
|
|
31
42
|
return :untouched if canonical == File.read(@path)
|
|
32
43
|
File.write(@path, canonical)
|
data/lib/xcop/rake_task.rb
CHANGED
|
@@ -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
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.2
|
|
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: []
|