xcop 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/actionlint.yml +1 -1
- data/.github/workflows/copyrights.yml +1 -0
- data/.github/workflows/pdd.yml +2 -1
- data/.github/workflows/rake.yml +1 -0
- data/.github/workflows/xcop.yml +1 -0
- data/.github/workflows/yamllint.yml +1 -0
- data/README.md +1 -8
- data/bin/xcop +3 -12
- data/features/cli.feature +0 -39
- data/lib/xcop/cli.rb +2 -10
- data/lib/xcop/document.rb +1 -16
- data/lib/xcop/rake_task.rb +2 -3
- data/lib/xcop/version.rb +1 -1
- data/logo.svg +1 -1
- data/test/test_document.rb +1 -53
- data/test/test_rake_task.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 621974a384c1f03cc98fbadc4faa33c68221c0c003bfdbdabdd6b8f8a5434e01
|
4
|
+
data.tar.gz: ae1523185af93addef82ef161f8d0c807cecfb0f6a9c7597907b31edad19c035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c34c3ce482c004d16ae4b6dee2ca731cfe1791ff219d2667de59d398e2281b7ec73a45fe59bf8f9466bd9ad32cda2e6fd596e47d5753e13c848e198d495e57
|
7
|
+
data.tar.gz: f86b27b0e738e26180d06f04079273d77b48b2f339d339ce11e42b4d968f9e094caaca361544201096ec2501a5702149298b5edc6260c727e5bce362ec33e2eb
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
---
|
23
|
+
# yamllint disable rule:line-length
|
23
24
|
name: actionlint
|
24
25
|
'on':
|
25
26
|
push:
|
@@ -36,7 +37,6 @@ jobs:
|
|
36
37
|
- uses: actions/checkout@v4
|
37
38
|
- name: Download actionlint
|
38
39
|
id: get_actionlint
|
39
|
-
# yamllint disable-line rule:line-length
|
40
40
|
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
|
41
41
|
shell: bash
|
42
42
|
- name: Check workflow files
|
data/.github/workflows/pdd.yml
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
---
|
23
|
+
# yamllint disable rule:line-length
|
23
24
|
name: pdd
|
24
25
|
on:
|
25
26
|
push:
|
@@ -30,4 +31,4 @@ jobs:
|
|
30
31
|
runs-on: ubuntu-24.04
|
31
32
|
steps:
|
32
33
|
- uses: actions/checkout@v4
|
33
|
-
- uses:
|
34
|
+
- uses: volodya-lombrozo/pdd-action@master
|
data/.github/workflows/rake.yml
CHANGED
data/.github/workflows/xcop.yml
CHANGED
data/README.md
CHANGED
@@ -64,7 +64,6 @@ They all will be _added_ to the list of options you specify. For example,
|
|
64
64
|
as it was suggested in [this blog post](https://www.yegor256.com/2022/07/20/command-line-defaults.html):
|
65
65
|
|
66
66
|
```
|
67
|
-
--license=LICENSE.txt
|
68
67
|
--nocolor
|
69
68
|
--quiet
|
70
69
|
--include=**/*
|
@@ -83,7 +82,6 @@ This is what you need there:
|
|
83
82
|
require 'xcop/rake_task'
|
84
83
|
desc 'Run XCop on all XML/XSL files in all directories'
|
85
84
|
Xcop::RakeTask.new(:xcop) do |task|
|
86
|
-
task.license = 'LICENSE.txt' # no license by default
|
87
85
|
task.quiet = true # FALSE by default
|
88
86
|
task.includes = ['**/*.xml', '**/*.xsl'] # xml|xsd|xhtml|xsl|html by default
|
89
87
|
task.excludes = ['target/**/*'] # empty by default
|
@@ -114,12 +112,11 @@ jobs:
|
|
114
112
|
- uses: g4s8/xcop-action@master
|
115
113
|
```
|
116
114
|
|
117
|
-
To customize
|
115
|
+
To customize files pattern use `files`:
|
118
116
|
|
119
117
|
```yaml
|
120
118
|
- uses: g4s8/xcop-action@master
|
121
119
|
with:
|
122
|
-
license: MY_LICENSE.txt
|
123
120
|
files: "src/*.xml"
|
124
121
|
```
|
125
122
|
|
@@ -144,8 +141,6 @@ You can integrate it with the help of
|
|
144
141
|
<configuration>
|
145
142
|
<target>
|
146
143
|
<apply executable="xcop" failonerror="true">
|
147
|
-
<arg value="--license"/>
|
148
|
-
<arg value="LICENSE.txt"/>
|
149
144
|
<fileset dir=".">
|
150
145
|
<include name="**/*.xml"/>
|
151
146
|
<include name="**/*.xsd"/>
|
@@ -175,8 +170,6 @@ Something like this should work:
|
|
175
170
|
[...]
|
176
171
|
<target name="xcop">
|
177
172
|
<apply executable="xcop" failonerror="true">
|
178
|
-
<arg value="--license"/>
|
179
|
-
<arg value="LICENSE.txt"/>
|
180
173
|
<fileset dir=".">
|
181
174
|
<include name="**/*.xml"/>
|
182
175
|
<include name="**/*.xsd"/>
|
data/bin/xcop
CHANGED
@@ -47,7 +47,7 @@ opts = Slop.parse(args, strict: true, help: true) do |o|
|
|
47
47
|
o.bool '--version', 'Show current version'
|
48
48
|
o.bool '--fix', 'Fix all files instead of reporting their problems'
|
49
49
|
o.bool '--nocolor', 'Suppress colored output'
|
50
|
-
o.string '--license', '
|
50
|
+
o.string '--license', 'This option is deprecated'
|
51
51
|
o.array '--include', 'Glob pattern(s) to include'
|
52
52
|
o.array '--exclude', 'Glob pattern(s) to exclude'
|
53
53
|
end
|
@@ -65,15 +65,6 @@ end
|
|
65
65
|
Encoding.default_external = Encoding::UTF_8
|
66
66
|
Encoding.default_internal = Encoding::UTF_8
|
67
67
|
|
68
|
-
license = ''
|
69
|
-
if opts.license?
|
70
|
-
unless File.exist?(opts[:license])
|
71
|
-
puts "License file is absent: #{opts[:license]}"
|
72
|
-
exit -1
|
73
|
-
end
|
74
|
-
license = File.read(opts[:license])
|
75
|
-
end
|
76
|
-
|
77
68
|
files = Set.new
|
78
69
|
|
79
70
|
if opts[:include]
|
@@ -91,12 +82,12 @@ if opts[:exclude]
|
|
91
82
|
end
|
92
83
|
|
93
84
|
if opts.fix?
|
94
|
-
Xcop::CLI.new(files
|
85
|
+
Xcop::CLI.new(files).fix do |f|
|
95
86
|
puts "#{f} fixed" unless opts.quiet?
|
96
87
|
end
|
97
88
|
else
|
98
89
|
begin
|
99
|
-
Xcop::CLI.new(files,
|
90
|
+
Xcop::CLI.new(files, nocolor: opts.nocolor?).run do |f|
|
100
91
|
puts "#{f} looks good" unless opts.quiet?
|
101
92
|
end
|
102
93
|
rescue StandardError => e
|
data/features/cli.feature
CHANGED
@@ -22,26 +22,6 @@ Feature: Command Line Processing
|
|
22
22
|
Then Stdout contains "test.xml looks good"
|
23
23
|
And Exit code is zero
|
24
24
|
|
25
|
-
Scenario: Validating correct XML file with license
|
26
|
-
Given I have a "licensed.xml" file with content:
|
27
|
-
"""
|
28
|
-
<?xml version="1.0"?>
|
29
|
-
<!--
|
30
|
-
This is the license,
|
31
|
-
which is very very strict!
|
32
|
-
-->
|
33
|
-
<hello>Hello, world!</hello>
|
34
|
-
|
35
|
-
"""
|
36
|
-
And I have a "LICENSE" file with content:
|
37
|
-
"""
|
38
|
-
This is the license,
|
39
|
-
which is very very strict!
|
40
|
-
"""
|
41
|
-
When I run bin/xcop with "--quiet --license LICENSE licensed.xml"
|
42
|
-
Then Stdout is empty
|
43
|
-
And Exit code is zero
|
44
|
-
|
45
25
|
Scenario: Validating incorrect XML file
|
46
26
|
Given I have a "abc.xml" file with content:
|
47
27
|
"""
|
@@ -51,24 +31,6 @@ Feature: Command Line Processing
|
|
51
31
|
When I run bin/xcop with "abc.xml"
|
52
32
|
Then Exit code is not zero
|
53
33
|
|
54
|
-
Scenario: Validating correct XML file with broken license
|
55
|
-
Given I have a "licensed.xml" file with content:
|
56
|
-
"""
|
57
|
-
<?xml version="1.0"?>
|
58
|
-
<!--
|
59
|
-
This is the wrong license!
|
60
|
-
-->
|
61
|
-
<hello>Hello, world!</hello>
|
62
|
-
|
63
|
-
"""
|
64
|
-
And I have a "LICENSE" file with content:
|
65
|
-
"""
|
66
|
-
This is the right license.
|
67
|
-
"""
|
68
|
-
When I run bin/xcop with "--license LICENSE licensed.xml"
|
69
|
-
And Stdout contains "Broken license"
|
70
|
-
And Exit code is not zero
|
71
|
-
|
72
34
|
Scenario: Fixing incorrect XML file
|
73
35
|
Given I have a "broken.xml" file with content:
|
74
36
|
"""
|
@@ -79,4 +41,3 @@ Feature: Command Line Processing
|
|
79
41
|
Then Exit code is zero
|
80
42
|
Then I run bin/xcop with "broken.xml"
|
81
43
|
Then Exit code is zero
|
82
|
-
|
data/lib/xcop/cli.rb
CHANGED
@@ -29,9 +29,8 @@ require_relative 'document'
|
|
29
29
|
# Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
|
30
30
|
# License:: MIT
|
31
31
|
class Xcop::CLI
|
32
|
-
def initialize(files,
|
32
|
+
def initialize(files, nocolor: false)
|
33
33
|
@files = files
|
34
|
-
@license = license
|
35
34
|
@nocolor = nocolor
|
36
35
|
end
|
37
36
|
|
@@ -43,13 +42,6 @@ class Xcop::CLI
|
|
43
42
|
puts diff
|
44
43
|
raise "Invalid XML formatting in #{f}"
|
45
44
|
end
|
46
|
-
unless @license.empty?
|
47
|
-
ldiff = doc.ldiff(@license)
|
48
|
-
unless ldiff.empty?
|
49
|
-
puts ldiff
|
50
|
-
raise "Broken license in #{f}"
|
51
|
-
end
|
52
|
-
end
|
53
45
|
yield(f) if block_given?
|
54
46
|
end
|
55
47
|
end
|
@@ -57,7 +49,7 @@ class Xcop::CLI
|
|
57
49
|
# Fix them all.
|
58
50
|
def fix
|
59
51
|
@files.each do |f|
|
60
|
-
Xcop::Document.new(f).fix
|
52
|
+
Xcop::Document.new(f).fix
|
61
53
|
yield(f) if block_given?
|
62
54
|
end
|
63
55
|
end
|
data/lib/xcop/document.rb
CHANGED
@@ -42,24 +42,9 @@ class Xcop::Document
|
|
42
42
|
differ(ideal, now, nocolor: nocolor)
|
43
43
|
end
|
44
44
|
|
45
|
-
# Return the difference for the license.
|
46
|
-
def ldiff(license)
|
47
|
-
xml = Nokogiri::XML(File.open(@path), &:noblanks)
|
48
|
-
comment = xml.xpath('/comment()')[0]
|
49
|
-
now = comment.nil? ? '' : comment.text.to_s.strip
|
50
|
-
ideal = license.strip
|
51
|
-
differ(ideal, now)
|
52
|
-
end
|
53
|
-
|
54
45
|
# Fixes the document.
|
55
|
-
def fix
|
46
|
+
def fix
|
56
47
|
xml = Nokogiri::XML(File.open(@path), &:noblanks)
|
57
|
-
unless license.empty?
|
58
|
-
xml.xpath('/comment()').remove
|
59
|
-
xml.children.before(
|
60
|
-
Nokogiri::XML::Comment.new(xml, "\n#{license.strip}\n")
|
61
|
-
)
|
62
|
-
end
|
63
48
|
ideal = xml.to_xml(indent: 2)
|
64
49
|
File.write(@path, ideal)
|
65
50
|
end
|
data/lib/xcop/rake_task.rb
CHANGED
@@ -27,14 +27,13 @@ require_relative '../xcop/cli'
|
|
27
27
|
# Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
|
28
28
|
# License:: MIT
|
29
29
|
class Xcop::RakeTask < Rake::TaskLib
|
30
|
-
attr_accessor :name, :fail_on_error, :excludes, :includes, :
|
30
|
+
attr_accessor :name, :fail_on_error, :excludes, :includes, :quiet
|
31
31
|
|
32
32
|
def initialize(*args, &task_block)
|
33
33
|
super()
|
34
34
|
@name = args.shift || :xcop
|
35
35
|
@includes = %w[xml xsd xhtml xsl html].map { |e| "**/*.#{e}" }
|
36
36
|
@excludes = []
|
37
|
-
@license = nil
|
38
37
|
@quiet = false
|
39
38
|
desc 'Run Xcop' unless ::Rake.application.last_description
|
40
39
|
task(name, *args) do |_, task_args|
|
@@ -53,7 +52,7 @@ class Xcop::RakeTask < Rake::TaskLib
|
|
53
52
|
good = Dir.glob(@includes).reject { |f| bad.include?(f) }
|
54
53
|
puts "Inspecting #{pluralize(good.length, 'file')}..." unless @quiet
|
55
54
|
begin
|
56
|
-
Xcop::CLI.new(good
|
55
|
+
Xcop::CLI.new(good).run do
|
57
56
|
print Rainbow('.').green unless @quiet
|
58
57
|
end
|
59
58
|
rescue StandardError => e
|
data/lib/xcop/version.rb
CHANGED
data/logo.svg
CHANGED
data/test/test_document.rb
CHANGED
@@ -47,64 +47,12 @@ class TestXcop < Minitest::Test
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def test_license_presence
|
51
|
-
Dir.mktmpdir 'test2' do |dir|
|
52
|
-
f = File.join(dir, 'a.xml')
|
53
|
-
license = " Copyright (c) All Good People\n Don't touch it!\n\n"
|
54
|
-
File.write(
|
55
|
-
f,
|
56
|
-
[
|
57
|
-
'<?xml version="1.0"?>',
|
58
|
-
'<!--',
|
59
|
-
' Copyright (c) All Good People',
|
60
|
-
' Don\'t touch it!',
|
61
|
-
'-->',
|
62
|
-
'<hello>Dude!</hello>',
|
63
|
-
''
|
64
|
-
].join("\n")
|
65
|
-
)
|
66
|
-
assert_equal(Xcop::Document.new(f).ldiff(license), '')
|
67
|
-
File.delete(f)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_license_absence
|
72
|
-
Dir.mktmpdir 'test3' do |dir|
|
73
|
-
f = File.join(dir, 'a.xml')
|
74
|
-
license = "Copyright (c) All Good People\nTouch me!\n\n"
|
75
|
-
File.write(
|
76
|
-
f,
|
77
|
-
[
|
78
|
-
'<?xml version="1.0"?>',
|
79
|
-
'<hello>My dear friend!</hello>',
|
80
|
-
''
|
81
|
-
].join("\n")
|
82
|
-
)
|
83
|
-
assert(Xcop::Document.new(f).ldiff(license) != '')
|
84
|
-
File.delete(f)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
50
|
def test_fixes_document
|
89
51
|
Dir.mktmpdir 'test3' do |dir|
|
90
52
|
f = File.join(dir, 'bad.xml')
|
91
|
-
license = " Copyright (c) Me, Myself, and I\n Like it?\n\n"
|
92
53
|
File.write(f, '<hello>My friend!</hello>')
|
93
|
-
Xcop::Document.new(f).fix
|
54
|
+
Xcop::Document.new(f).fix
|
94
55
|
assert_equal(Xcop::Document.new(f).diff, '')
|
95
|
-
assert_equal(Xcop::Document.new(f).ldiff(license), '')
|
96
|
-
File.delete(f)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_removes_previous_license
|
101
|
-
Dir.mktmpdir 'test4' do |dir|
|
102
|
-
f = File.join(dir, 'bad.xml')
|
103
|
-
license = "the license to add\n\n\nhey"
|
104
|
-
File.write(f, '<hello>how do you do?</hello>')
|
105
|
-
Xcop::Document.new(f).fix(license)
|
106
|
-
Xcop::Document.new(f).fix(license)
|
107
|
-
assert_equal(Nokogiri::XML(File.read(f)).xpath('/comment()').length, 1)
|
108
56
|
File.delete(f)
|
109
57
|
end
|
110
58
|
end
|
data/test/test_rake_task.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: differ
|