pdd 0.21.3 → 0.22.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: d1f5d5ae8d72ca3e758c6757c3a18daacf4f24f841561ab0dc75ba5b0e14893a
4
- data.tar.gz: 5325be41bd8e0b42a67fb235172a87dbd1f00492dd8311ec684806f5710c2465
3
+ metadata.gz: 1c97d7f2451c60abeae2fa0374b8578c852b6c2e42a78568c5fff8c7b5c3acc1
4
+ data.tar.gz: 5353eec5dea5875dc31a7655e694fc41c3585ff176f849db8122b777ee38a25a
5
5
  SHA512:
6
- metadata.gz: a09ef466837dd362e530c354ab21ee5e7c26b349cefaebc4ebfb8d47e8c81a12d0ea0252244133e596847a34837238eeeb2478ad956f9eb81dcf09535f31b167
7
- data.tar.gz: cf8f5a5748f822b69e46a08bd344370f2918127ec9e69050550907a6f5aa5efd8fd34405d5c6e203ef71080e4897d95d8e831e5a62bd0339cbcca2b1ff5e2c43
6
+ metadata.gz: ecded4d1f191fb5ab36eb237add8d46ca48430371a8c6ab9758a159ebfc796ac276a7327c4f9b33a3186ebd104c95e0255af12def22ccbcfaf0e3239decb67d7
7
+ data.tar.gz: 0fe7422e26da6f53561a3e51c597cb779f39f39828b9af55f8b2cd0fc8b1b359c919a0b82f3d39f26d487f5ac31a50020494f5fc1048cedf7b64545096847b22
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: pdd
3
+ "on":
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ pdd:
12
+ runs-on: ubuntu-20.04
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: g4s8/pdd-action@master
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: xcop
3
+ "on":
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ xcop:
12
+ runs-on: ubuntu-20.04
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: g4s8/xcop-action@master
data/.pdd CHANGED
@@ -9,6 +9,7 @@
9
9
  --exclude features/cli.feature
10
10
  --exclude features/parsing.feature
11
11
  --exclude features/catches_broken_puzzles.feature
12
+ --exclude features/remove.feature
12
13
  --exclude features/uses_config.feature
13
14
  --exclude features/html_output.feature
14
15
  --exclude features/avoiding_duplicates.feature
data/bin/pdd CHANGED
@@ -50,6 +50,7 @@ begin
50
50
  o.bool '-h', '--help', 'Show these instructions'
51
51
  o.bool '-v', '--verbose', 'Enable verbose mode (a lot of logging)'
52
52
  o.bool '-q', '--quiet', 'Enable quiet mode (almost no logging)'
53
+ o.bool '--remove', 'Remove all found puzzles from the source code'
53
54
  o.bool '--skip-gitignore', 'Don\'t look into .gitignore for excludes'
54
55
  o.bool '--skip-errors', 'Suppress error as warning and skip badly
55
56
  formatted puzzles'
@@ -89,31 +90,52 @@ https://github.com/cqfn/pdd/blob/master/README.md"
89
90
  body = File.read(cfg)
90
91
  extra = body.split(/\s+/).map(&:strip)
91
92
  opts['skip-gitignore'] = extra
92
- puts "Found #{body.split(/\n/).length} lines in #{File.absolute_path(cfg)}"
93
+ PDD.log.info "Found #{body.split(/\n/).length} lines in #{File.absolute_path(cfg)}"
93
94
  end
94
95
 
95
96
  Encoding.default_external = Encoding::UTF_8
96
97
  Encoding.default_internal = Encoding::UTF_8
97
98
  file = opts.file? ? File.new(opts[:file], 'w') : $stdout
98
- output = PDD::Base.new(opts).xml
99
+ xml = PDD::Base.new(opts).xml
100
+ output = xml
99
101
  if opts[:format]
100
102
  if opts[:format] == 'html'
101
103
  xslt = File.join(
102
104
  File.dirname(File.dirname(__FILE__)),
103
105
  'assets', 'puzzles.xsl'
104
106
  )
105
- output = Nokogiri::XSLT(File.read(xslt)).transform(Nokogiri::XML(output))
107
+ output = Nokogiri::XSLT(File.read(xslt)).transform(Nokogiri::XML(xml))
106
108
  elsif opts[:format] != 'xml'
107
109
  raise 'Invalid format, use html or xml'
108
110
  end
109
111
  end
110
112
  file << output
113
+ if opts.remove?
114
+ home = opts[:source] || Dir.pwd
115
+ PDD.log.info "Removing puzzles from #{home}..."
116
+ files = {}
117
+ Nokogiri::XML(xml).xpath('/puzzles/puzzle').each do |p|
118
+ file = p.xpath('file/text()').to_s
119
+ files[file] = [] if files[file].nil?
120
+ files[file] << p.xpath('lines/text()').to_s.split('-').map(&:to_i)
121
+ end
122
+ files.each do |src, all|
123
+ f = File.join(home, src)
124
+ File.write(
125
+ f,
126
+ File.readlines(f).reject.each_with_index do |_t, i|
127
+ all.any? { |pair| i + 1 >= pair[0] && i + 1 <= pair[1] }
128
+ end.join
129
+ )
130
+ PDD.log.info "#{all.count} puzzles removed from #{src}"
131
+ end
132
+ end
111
133
  rescue SystemExit => e
112
134
  puts e.message unless e.success?
113
135
  PDD.log.info "Exit code is #{e.status}"
114
136
  exit(e.status)
115
137
  rescue PDD::Error => e
116
- puts "#{Rainbow('ERROR').red}: #{e.message}
138
+ PDD.log.error "#{Rainbow('ERROR').red}: #{e.message}
117
139
  If you can't understand the cause of this issue or you don't know \
118
140
  how to fix it, please submit a GitHub issue, we will try to help you: \
119
141
  https://github.com/cqfn/pdd/issues. This tool is still in its beta \
@@ -122,7 +144,7 @@ more documentation: https://github.com/cqfn/pdd/blob/master/README.md."
122
144
  PDD.log.info 'Exit code is 1'
123
145
  exit(1)
124
146
  rescue StandardError => e
125
- puts "#{Rainbow('ERROR').red} (#{e.class.name}): #{e.message}"
147
+ PDD.log.error "#{Rainbow('ERROR').red} (#{e.class.name}): #{e.message}"
126
148
  PDD.log.info 'Exit code is 255'
127
149
  exit(255)
128
150
  end
@@ -0,0 +1,15 @@
1
+ Feature: Removing Puzzles
2
+ As a source code writer I want to be able to
3
+ remove PDD puzzles from source code
4
+
5
+ Scenario: Removing puzzles from code
6
+ Given I have a "a/test.txt" file with content:
7
+ """
8
+ Hello,
9
+ # @todo #42 Bye!
10
+ # Bye!
11
+ The End.
12
+ """
13
+ When I run bin/pdd with "-v --remove -f /dev/null"
14
+ Then Exit code is zero
15
+ And Stdout contains "1 puzzles removed from a/test.txt"
@@ -79,6 +79,7 @@ When(%r{^I run bin/pdd with "([^"]*)"$}) do |arg|
79
79
  end
80
80
 
81
81
  Then(/^Stdout contains "([^"]*)"$/) do |txt|
82
+ raise 'STDOUT is empty!' if @stdout.empty?
82
83
  raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt)
83
84
  end
84
85
 
data/lib/pdd/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module PDD
26
- VERSION = '0.21.3'.freeze
26
+ VERSION = '0.22.0'.freeze
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.3
4
+ version: 0.22.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: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -231,10 +231,10 @@ extra_rdoc_files:
231
231
  files:
232
232
  - ".0pdd.yml"
233
233
  - ".gitattributes"
234
- - ".github/ISSUE_TEMPLATE.md"
235
- - ".github/PULL_REQUEST_TEMPLATE.md"
236
234
  - ".github/workflows/codecov.yml"
235
+ - ".github/workflows/pdd.yml"
237
236
  - ".github/workflows/rake.yml"
237
+ - ".github/workflows/xcop.yml"
238
238
  - ".gitignore"
239
239
  - ".overcommit.yml"
240
240
  - ".pdd"
@@ -258,6 +258,7 @@ files:
258
258
  - features/html_output.feature
259
259
  - features/parsing.feature
260
260
  - features/rake.feature
261
+ - features/remove.feature
261
262
  - features/step_definitions/steps.rb
262
263
  - features/support/env.rb
263
264
  - features/unicode.feature
@@ -1,12 +0,0 @@
1
- Make sure the title of the issue explains the problem you are having. Also, the description of the issue must clearly explain what is broken, not what you want us to implement. Go through this checklist and make sure you answer "YES" to all points:
2
-
3
- - You have all pre-requisites listed in README.md installed
4
- - You are sure that you are not reporting a duplicate (search all issues)
5
- - You say "is broken" or "doesn't work" in the title
6
- - You tell us what you are trying to do
7
- - You explain the results you are getting
8
- - You suggest an alternative result you would like to see
9
-
10
- This article will help you understand what we are looking for: http://www.yegor256.com/2014/11/24/principles-of-bug-tracking.html
11
-
12
- Thank you for your contribution!
@@ -1,11 +0,0 @@
1
- Many thanks for your contribution, we truly appreciate it. We will appreciate it even more, if you make sure that you can say "YES" to each point in this short checklist:
2
-
3
- - You made a small amount of changes (less than 100 lines, less than 10 files)
4
- - You made changes related to only one bug (create separate PRs for separate problems)
5
- - You are ready to defend your changes (there will be a code review)
6
- - You don't touch what you don't understand
7
- - You ran the build locally and it passed
8
-
9
- This article will help you understand what we are looking for: http://www.yegor256.com/2015/02/09/serious-code-reviewer.html
10
-
11
- Thank you for your contribution!