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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cd1d77aa073a33fa549467c9140a9b29acaa7bcb5153063fec23f0e4515dd6c
4
- data.tar.gz: ea379a6c817dcd72c7b55115eba1b2e894456db388cc417bbb1de450cb260541
3
+ metadata.gz: 621974a384c1f03cc98fbadc4faa33c68221c0c003bfdbdabdd6b8f8a5434e01
4
+ data.tar.gz: ae1523185af93addef82ef161f8d0c807cecfb0f6a9c7597907b31edad19c035
5
5
  SHA512:
6
- metadata.gz: 5bd10b38f9d7d37bb1ba65b8d72641cfbd64aa9a160f03fd8cd9a136e1c336863380ce8787fdd2a941d5f754a7233cea7c8d3f1b26da4993cb48209d8a051f0f
7
- data.tar.gz: 1ccb0d23efd0ea1368ce79f63707e1cdd7e5aae6d924423ccc10e0b97778665c81bbacebd06c955dcf233e64a27b6ddfd90615439dcacd98cd0491c87a00e80d
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
@@ -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: copyrights
24
25
  'on':
25
26
  push:
@@ -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: g4s8/pdd-action@master
34
+ - uses: volodya-lombrozo/pdd-action@master
@@ -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: rake
24
25
  on:
25
26
  push:
@@ -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: xcop
24
25
  on:
25
26
  push:
@@ -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: yamllint
24
25
  'on':
25
26
  push:
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 license location or files pattern use action inputs `license` and `files`:
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', 'File name of the boilerplate head 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, license).fix do |f|
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, license, nocolor: opts.nocolor?).run do |f|
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, license, nocolor: false)
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(@license)
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(license = '')
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
@@ -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, :license, :quiet
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, @license.nil? ? '' : File.read(@license)).run do
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
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Xcop
26
- VERSION = '0.7.2'.freeze
26
+ VERSION = '0.8.0'.freeze
27
27
  end
data/logo.svg CHANGED
@@ -16,4 +16,4 @@
16
16
  </g>
17
17
  </g>
18
18
  </g>
19
- </svg>
19
+ </svg>
@@ -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(license)
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
@@ -35,7 +35,6 @@ class TestRakeTask < Minitest::Test
35
35
  File.write(f, "<?xml version=\"1.0\"?>\n<x/>\n")
36
36
  Xcop::RakeTask.new(:xcop1) do |task|
37
37
  task.quiet = true
38
- # task.license = 'LICENSE.txt'
39
38
  end
40
39
  Rake::Task['xcop1'].invoke
41
40
  File.delete(f)
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.7.2
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-16 00:00:00.000000000 Z
11
+ date: 2025-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: differ