xcop 0.5.4 → 0.5.5
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/.rubocop.yml +2 -0
- data/README.md +29 -4
- data/bin/xcop +7 -2
- data/features/cli.feature +3 -3
- data/lib/xcop.rb +4 -15
- data/lib/xcop/rake_task.rb +13 -1
- data/lib/xcop/version.rb +1 -1
- data/test/test_rake_task.rb +1 -0
- data/test/test_xcop.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa06bb31a6307eaf1ce56b0795be9724317f602a
|
4
|
+
data.tar.gz: 626fd201fd723fd081fc112cb40e282f3d972a95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8329081d4b7977c9be2afcca650704e5dc77370af182772538dc27bf1c8568e1bd9e29a26a85c5d1ea52af1eb0feeedbb62ebf6ae4bd592b93f8143c11b2637f
|
7
|
+
data.tar.gz: 1702c751578d7ff9ca5c6ad4b8353d9f21b7c907627d74d0d68980a535527c6481e35ab91333d163660c77c49958d77891dee22dbe24975af179bd82b79ba933
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -51,7 +51,7 @@ $ xcop --fix broken-file.xml
|
|
51
51
|
To fix all files in the directory you can do:
|
52
52
|
|
53
53
|
```bash
|
54
|
-
$ xcop $(find . -name '*.xml')
|
54
|
+
$ xcop --fix $(find . -name '*.xml')
|
55
55
|
```
|
56
56
|
|
57
57
|
## How to use in `Rakefile`?
|
@@ -62,9 +62,10 @@ This is what you need there:
|
|
62
62
|
require 'xcop/rake_task'
|
63
63
|
desc 'Run XCop on all XML/XSL files in all directories'
|
64
64
|
Xcop::RakeTask.new(:xcop) do |task|
|
65
|
-
task.license = 'LICENSE.txt'
|
66
|
-
task.
|
67
|
-
task.
|
65
|
+
task.license = 'LICENSE.txt' # no license by default
|
66
|
+
task.quiet = true # FALSE by default
|
67
|
+
task.includes = ['**/*.xml', '**/*.xsl'] # xml|xsd|xhtml|xsl|html by default
|
68
|
+
task.excludes = ['target/**/*'] # empty by default
|
68
69
|
end
|
69
70
|
```
|
70
71
|
|
@@ -89,6 +90,8 @@ You can integrate it with the help of
|
|
89
90
|
<configuration>
|
90
91
|
<target>
|
91
92
|
<apply executable="xcop" failonerror="true">
|
93
|
+
<arg value="--license"/>
|
94
|
+
<arg value="LICENSE.txt"/>
|
92
95
|
<fileset dir=".">
|
93
96
|
<include name="**/*.xml"/>
|
94
97
|
<include name="**/*.xsd"/>
|
@@ -109,6 +112,28 @@ You can integrate it with the help of
|
|
109
112
|
</project>
|
110
113
|
```
|
111
114
|
|
115
|
+
## How to use in Ant `project.xml`?
|
116
|
+
|
117
|
+
Something like this should work:
|
118
|
+
|
119
|
+
```xml
|
120
|
+
<project>
|
121
|
+
[...]
|
122
|
+
<target name="xcop">
|
123
|
+
<apply executable="xcop" failonerror="true">
|
124
|
+
<arg value="--license"/>
|
125
|
+
<arg value="LICENSE.txt"/>
|
126
|
+
<fileset dir=".">
|
127
|
+
<include name="**/*.xml"/>
|
128
|
+
<include name="**/*.xsd"/>
|
129
|
+
<exclude name="target/**/*"/>
|
130
|
+
<exclude name=".idea/**/*"/>
|
131
|
+
</fileset>
|
132
|
+
</apply>
|
133
|
+
</target>
|
134
|
+
</project>
|
135
|
+
```
|
136
|
+
|
112
137
|
## How to contribute?
|
113
138
|
|
114
139
|
Just submit a pull request. Make sure `rake` passes.
|
data/bin/xcop
CHANGED
@@ -31,6 +31,7 @@ require_relative '../lib/xcop/version'
|
|
31
31
|
opts = Slop.parse(ARGV, strict: true, help: true) do |o|
|
32
32
|
o.banner = "Usage (#{Xcop::VERSION}): xcop [options] [files...]"
|
33
33
|
o.bool '-h', '--help', 'Show these instructions'
|
34
|
+
o.bool '-q', '--quiet', 'Don\'t print anything if there are no errors'
|
34
35
|
o.bool '--version', 'Show current version'
|
35
36
|
o.bool '--fix', 'Fix all files instead of reporting their problems'
|
36
37
|
o.string '--license', 'File name of the boilerplate head license'
|
@@ -52,10 +53,14 @@ Encoding.default_internal = Encoding::UTF_8
|
|
52
53
|
license = opts.license? ? File.read(opts[:license]) : ''
|
53
54
|
|
54
55
|
if opts.fix?
|
55
|
-
Xcop::CLI.new(opts.arguments, license).fix
|
56
|
+
Xcop::CLI.new(opts.arguments, license).fix do |f|
|
57
|
+
puts "#{f} fixed" unless opts.quiet?
|
58
|
+
end
|
56
59
|
else
|
57
60
|
begin
|
58
|
-
Xcop::CLI.new(opts.arguments, license).run
|
61
|
+
Xcop::CLI.new(opts.arguments, license).run do |f|
|
62
|
+
puts "#{f} looks good" unless opts.quiet?
|
63
|
+
end
|
59
64
|
rescue StandardError => e
|
60
65
|
puts e.message
|
61
66
|
exit -1
|
data/features/cli.feature
CHANGED
@@ -19,7 +19,7 @@ Feature: Command Line Processing
|
|
19
19
|
|
20
20
|
"""
|
21
21
|
When I run bin/xcop with "test.xml"
|
22
|
-
Then Stdout contains "
|
22
|
+
Then Stdout contains "test.xml looks good"
|
23
23
|
And Exit code is zero
|
24
24
|
|
25
25
|
Scenario: Validating correct XML file with license
|
@@ -38,8 +38,8 @@ Feature: Command Line Processing
|
|
38
38
|
This is the license,
|
39
39
|
which is very very strict!
|
40
40
|
"""
|
41
|
-
When I run bin/xcop with "--license LICENSE licensed.xml"
|
42
|
-
Then Stdout
|
41
|
+
When I run bin/xcop with "--quiet --license LICENSE licensed.xml"
|
42
|
+
Then Stdout is empty
|
43
43
|
And Exit code is zero
|
44
44
|
|
45
45
|
Scenario: Validating incorrect XML file
|
data/lib/xcop.rb
CHANGED
@@ -38,8 +38,6 @@ module Xcop
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def run
|
41
|
-
puts 'Running xcop...'
|
42
|
-
puts "Inspecting #{pluralize(@files.length, 'file')}..."
|
43
41
|
@files.each do |f|
|
44
42
|
doc = Document.new(f)
|
45
43
|
diff = doc.diff
|
@@ -54,27 +52,17 @@ module Xcop
|
|
54
52
|
raise "Broken license in #{f}"
|
55
53
|
end
|
56
54
|
end
|
57
|
-
|
55
|
+
yield(f) if block_given?
|
58
56
|
end
|
59
|
-
print "\n"
|
60
|
-
puts "#{pluralize(@files.length, 'file')} checked, \
|
61
|
-
everything looks #{Rainbow('pretty').green}"
|
62
57
|
end
|
63
58
|
|
64
59
|
# Fix them all.
|
65
60
|
def fix
|
66
61
|
@files.each do |f|
|
67
|
-
print "Fixing #{f}... "
|
68
62
|
Document.new(f).fix(@license)
|
69
|
-
|
63
|
+
yield(f) if block_given?
|
70
64
|
end
|
71
65
|
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def pluralize(num, text)
|
76
|
-
"#{num} #{num == 1 ? text : text + 's'}"
|
77
|
-
end
|
78
66
|
end
|
79
67
|
|
80
68
|
# One document.
|
@@ -98,7 +86,8 @@ everything looks #{Rainbow('pretty').green}"
|
|
98
86
|
# Return the difference for the license.
|
99
87
|
def ldiff(license)
|
100
88
|
xml = Nokogiri::XML(File.open(@path), &:noblanks)
|
101
|
-
|
89
|
+
comment = xml.xpath('/comment()')[0]
|
90
|
+
now = comment.nil? ? '' : comment.text.to_s.strip
|
102
91
|
ideal = license.strip
|
103
92
|
Differ.format = :color
|
104
93
|
return Differ.diff_by_line(ideal, now).to_s unless now == ideal
|
data/lib/xcop/rake_task.rb
CHANGED
@@ -36,12 +36,14 @@ module Xcop
|
|
36
36
|
attr_accessor :excludes
|
37
37
|
attr_accessor :includes
|
38
38
|
attr_accessor :license
|
39
|
+
attr_accessor :quiet
|
39
40
|
|
40
41
|
def initialize(*args, &task_block)
|
41
42
|
@name = args.shift || :xcop
|
42
43
|
@includes = %w(xml xsd xhtml xsl html).map { |e| "**/*.#{e}" }
|
43
44
|
@excludes = []
|
44
45
|
@license = nil
|
46
|
+
@quiet = false
|
45
47
|
desc 'Run Xcop' unless ::Rake.application.last_description
|
46
48
|
task(name, *args) do |_, task_args|
|
47
49
|
RakeFileUtils.send(:verbose, true) do
|
@@ -55,13 +57,23 @@ module Xcop
|
|
55
57
|
|
56
58
|
def run
|
57
59
|
require 'xcop'
|
60
|
+
puts 'Running xcop...' unless @quiet
|
58
61
|
bad = Dir.glob(@excludes)
|
59
62
|
good = Dir.glob(@includes).reject { |f| bad.include?(f) }
|
63
|
+
puts "Inspecting #{pluralize(good.length, 'file')}..." unless @quiet
|
60
64
|
begin
|
61
|
-
Xcop::CLI.new(good, @license.nil? ? '' : File.read(@license)).run
|
65
|
+
Xcop::CLI.new(good, @license.nil? ? '' : File.read(@license)).run do
|
66
|
+
print Rainbow('.').green unless @quiet
|
67
|
+
end
|
62
68
|
rescue StandardError => e
|
63
69
|
abort(e.message)
|
64
70
|
end
|
71
|
+
puts "\n#{pluralize(good.length, 'file')} checked, \
|
72
|
+
everything looks #{Rainbow('pretty').green}" unless @quiet
|
73
|
+
end
|
74
|
+
|
75
|
+
def pluralize(num, text)
|
76
|
+
"#{num} #{num == 1 ? text : text + 's'}"
|
65
77
|
end
|
66
78
|
end
|
67
79
|
end
|
data/lib/xcop/version.rb
CHANGED
data/test/test_rake_task.rb
CHANGED
data/test/test_xcop.rb
CHANGED
@@ -59,6 +59,22 @@ class TestXcop < Minitest::Test
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
def test_license_absence
|
63
|
+
Dir.mktmpdir 'test3' do |dir|
|
64
|
+
f = File.join(dir, 'a.xml')
|
65
|
+
license = "Copyright (c) All Good People\nTouch me!\n\n"
|
66
|
+
File.write(
|
67
|
+
f,
|
68
|
+
[
|
69
|
+
'<?xml version="1.0"?>',
|
70
|
+
'<hello>My dear friend!</hello>',
|
71
|
+
''
|
72
|
+
].join("\n")
|
73
|
+
)
|
74
|
+
assert(Xcop::Document.new(f).ldiff(license) != '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
62
78
|
def test_fixes_document
|
63
79
|
Dir.mktmpdir 'test3' do |dir|
|
64
80
|
f = File.join(dir, 'bad.xml')
|
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.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|