pdd 0.20.8 → 0.21.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: e3ff37e6f0ac2629e0b31888df2b56f7024512b04b07bd58c29a0525186a40f0
4
- data.tar.gz: 61076844123f2eda0b32734b2c917ed6eb033956177197626219bda878add5b5
3
+ metadata.gz: 61cbd66550df0bd17c8916fa490a6e85f8c3991475c609a013b73db2e5891f16
4
+ data.tar.gz: 015351fbd2e277409faf706ccd1a590d5a962e49f6fdfb4c6318e371f658c96a
5
5
  SHA512:
6
- metadata.gz: e9b46c3238588062c781b1b3705cf343d1ca0e70481b2546ffc407b9a5be6534d45b3c8d0d4ebaab0ac39630ebfc6652feb8c69a8dd8d787bf33eae1a9cb0935
7
- data.tar.gz: 790b7d73f1b7ea5d2666864b238dfdde211572186d3d84c29a6d6448936b54ef87a567473b83fccfad83ec945ad6f9677a739b0730fde5199618dc79f6cc9ead
6
+ metadata.gz: fbb82db1bbb0d5246caa98cc376a7a2ea32aefc217d567191f03fd3dc346d833d55cca141430b6b6f12dec1e5580faa5b83d28da3156b88ef3a0cdfd70fbbdf5
7
+ data.tar.gz: 81f23444974fd4d1359d9bbf2bd07adc370d05302369be00ee67c210c12c1c3d83648b9dcfd8e454d161781b06cef9430b72a774fa9ddcc3508493cb52540f45
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: codecov
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ jobs:
8
+ codecov:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - uses: actions/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ - run: bundle update
16
+ - run: bundle exec rake
17
+ - uses: codecov/codecov-action@v1
18
+ with:
19
+ file: coverage/.resultset.json
20
+ fail_ci_if_error: true
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: rake
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ test:
12
+ name: test
13
+ strategy:
14
+ matrix:
15
+ os: [ubuntu-latest]
16
+ ruby: [2.7]
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: actions/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - run: bundle update
24
+ - run: bundle exec rake
data/.pdd CHANGED
@@ -1,8 +1,5 @@
1
1
  --source=.
2
2
  --verbose
3
- --skip-errors
4
- --skip-gitignore
5
- --include lib/pdd/sources.rb
6
3
  --exclude .idea/**/*
7
4
  --exclude .bundle/**/*
8
5
  --exclude target/**/*
@@ -25,3 +22,4 @@
25
22
  --rule min-words:20
26
23
  --rule min-estimate:15
27
24
  --rule max-estimate:90
25
+
data/.rubocop.yml CHANGED
@@ -8,8 +8,10 @@ Layout/EndOfLine:
8
8
  EnforcedStyle: lf
9
9
  Metrics/ClassLength:
10
10
  Max: 300
11
+ Metrics/LineLength:
12
+ Max: 90
11
13
  Metrics/MethodLength:
12
- Max: 30
14
+ Max: 35
13
15
  Metrics/AbcSize:
14
16
  Max: 40
15
17
  Style/MultilineBlockChain:
data/.rultor.yml CHANGED
@@ -1,32 +1,25 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.9.0
1
3
  assets:
2
4
  rubygems.yml: yegor256/home#assets/rubygems.yml
3
- s3cfg: yegor256/home#assets/s3cfg
4
5
  install: |
5
- export GEM_HOME=~/.ruby
6
- export GEM_PATH=$GEM_HOME:$GEM_PATH
7
- sudo gem install pdd -v 0.20.5
8
- sudo gem install xcop -v 0.6
9
- bundle install
6
+ pdd -f /dev/null
7
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
10
8
  release:
11
9
  script: |-
12
- pdd -f /dev/null
13
- LC_ALL=US-ASCII bundle exec rake
10
+ [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
11
+ bundle exec rake
14
12
  rm -rf *.gem
15
- sed -i "s/1\.0\.snapshot/${tag}/g" lib/pdd/version.rb
13
+ sed -i "s/0\.0\.0/${tag}/g" lib/pdd/version.rb
16
14
  git add lib/pdd/version.rb
17
15
  git commit -m "version set to ${tag}"
18
16
  gem build pdd.gemspec
19
17
  chmod 0600 ../rubygems.yml
20
18
  gem push *.gem --config-file ../rubygems.yml
21
- pdd --source=$(pwd) --verbose --file=pdd.xml -e=test/** -e=features/** -e=coverage/**/* -e=README.md
22
- s3cmd --no-progress put pdd.xml --config=../s3cfg s3://pdd.teamed.io/pdd.xml
23
- s3cmd --no-progress put assets/puzzles.xsd --acl-public --config=../s3cfg s3://pdd-xsd.teamed.io/${tag}.xsd
24
- s3cmd --no-progress put assets/puzzles.xsl --acl-public --config=../s3cfg s3://pdd-xsl.teamed.io/${tag}.xsl
25
19
  merge:
26
20
  script: |-
27
- pdd -f /dev/null
28
21
  LC_ALL=US-ASCII bundle exec rake
29
22
  deploy:
30
23
  script: |-
31
- echo 'Nothing to deploy'
24
+ echo "There is nothing to deploy"
32
25
  exit -1
data/.simplecov CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2014-2021 Yegor Bugayenko
3
+ Copyright (c) 2014-2022 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/README.md CHANGED
@@ -1,16 +1,12 @@
1
- <img src="https://avatars2.githubusercontent.com/u/24456188" width="64px" height="64px"/>
2
-
3
- [![Donate via Zerocracy](https://www.0crat.com/contrib-badge/C3T46CUJJ.svg)](https://www.0crat.com/contrib/C3T46CUJJ)
1
+ <img alt="pdd logo" src="https://avatars2.githubusercontent.com/u/24456188" width="64px" height="64px"/>
4
2
 
5
3
  [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
6
- [![Managed by Zerocracy](https://www.0crat.com/badge/C3T46CUJJ.svg)](https://www.0crat.com/p/C3T46CUJJ)
7
4
  [![DevOps By Rultor.com](http://www.rultor.com/b/cqfn/pdd)](http://www.rultor.com/p/cqfn/pdd)
8
5
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
9
6
 
10
- [![Build Status](https://travis-ci.org/cqfn/pdd.svg)](https://travis-ci.org/cqfn/pdd)
11
- [![Build status](https://ci.appveyor.com/api/projects/status/b59sdhuu0gcku15b?svg=true)](https://ci.appveyor.com/project/cqfn/pdd)
12
7
  [![PDD status](http://www.0pdd.com/svg?name=cqfn/pdd)](http://www.0pdd.com/p?name=cqfn/pdd)
13
- [![Test Coverage](https://img.shields.io/codecov/c/github/cqfn/pdd.svg)](https://codecov.io/github/cqfn/pdd?branch=master)
8
+ [![codecov](https://codecov.io/gh/cqfn/pdd/branch/master/graph/badge.svg)](https://codecov.io/gh/cqfn/pdd)
9
+ ![Lines of code](https://img.shields.io/tokei/lines/github/cqfn/pdd)
14
10
  [![Hits-of-Code](https://hitsofcode.com/github/cqfn/pdd)](https://hitsofcode.com/view/github/cqfn/pdd)
15
11
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cqfn/pdd/blob/master/LICENSE.txt)
16
12
 
@@ -41,7 +37,6 @@ Run it locally and read its output:
41
37
  $ pdd --help
42
38
  ```
43
39
 
44
- ### File and Directory Selection
45
40
  You can exclude & include certain number of files from the search via these options:
46
41
 
47
42
  `` --exclude=glob ``
@@ -78,8 +73,9 @@ to the leading space in every consecutive line):
78
73
  [related code]
79
74
  ```
80
75
 
81
- \[\] - Replace with apropriate data (see text enclosed in brackets)
82
- <> - Omitable (enclosed data can be left out)
76
+ `[]` - Replace with apropriate data (see text enclosed in brackets)
77
+
78
+ `<>` - Omitable (enclosed data can be left out)
83
79
 
84
80
  Example:
85
81
 
@@ -101,6 +97,9 @@ The specified markers will be included in the issues body
101
97
  along with some predefined text. If your comment is longer
102
98
  than 40 characters, it will be truncated in the title.
103
99
 
100
+ Note: if you create several puzzle duplicates (same text after puzzle keyword),
101
+ pdd will fail to parse puzzles and produce an error with duplicates list.
102
+
104
103
  There are 3 supported keywords, one of which must precede the mandatory
105
104
  puzzle marker. They are `@todo`, `TODO` and `TODO:`.
106
105
 
@@ -212,7 +211,7 @@ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2
212
211
  [Bundler](https://bundler.io/) installed. Then:
213
212
 
214
213
  ```
215
- $ bundle install --path .bundle
214
+ $ bundle install
216
215
  $ bundle exec rake
217
216
  ```
218
217
 
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/assets/puzzles.xsd CHANGED
@@ -2,7 +2,7 @@
2
2
  <!--
3
3
  (The MIT License)
4
4
 
5
- Copyright (c) 2014-2021 Yegor Bugayenko
5
+ Copyright (c) 2014-2022 Yegor Bugayenko
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the 'Software'), to deal
data/assets/puzzles.xsl CHANGED
@@ -2,7 +2,7 @@
2
2
  <!--
3
3
  (The MIT License)
4
4
 
5
- Copyright (c) 2014-2021 Yegor Bugayenko
5
+ Copyright (c) 2014-2022 Yegor Bugayenko
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the 'Software'), to deal
data/bin/pdd CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # Copyright (c) 2014-2021 Yegor Bugayenko
2
+ # Copyright (c) 2014-2022 Yegor Bugayenko
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the 'Software'), to deal
@@ -31,6 +31,8 @@ require_relative '../lib/pdd'
31
31
  require_relative '../lib/pdd/version'
32
32
  require_relative '../lib/pdd/source'
33
33
 
34
+ Rainbow.enabled = ENV['PDD_ENV'] == 'development'
35
+
34
36
  begin
35
37
  args = []
36
38
  if File.exist?('.pdd')
@@ -11,30 +11,12 @@ Feature: Catches Broken Puzzles
11
11
  * Some other documentation
12
12
  * text that is not relevant to
13
13
  * the puzzle below.
14
- * @todo #13 This puzzle has an incorrect format
15
- * because it doesn't start with a space on
16
- * the second and the third lines
14
+ * @todo This puzzle has an incorrect format
15
+ * because it doesn't have a ticket number
17
16
  */
18
17
  public void main(String[] args) {
19
18
  // later
20
19
  }
21
20
  }
22
21
  """
23
- When I run pdd it fails with "Space expected"
24
22
  When I run pdd it fails with "Sample.java:6"
25
-
26
- Scenario: Throwing exception on yet another broken puzzle
27
- Given I have a "Sample.java" file with content:
28
- """
29
- public class Main {
30
- //
31
- // @todo #13 This puzzle has an incorrect format
32
- // because there is no space character in the
33
- // second and third lines
34
- //
35
- public void main(String[] args) {
36
- // later
37
- }
38
- }
39
- """
40
- When I run pdd it fails with "Space expected"
@@ -25,6 +25,32 @@ Feature: Parsing
25
25
  And XML matches "//puzzle[role='DEV']"
26
26
  And XML matches "//puzzle[estimate='0']"
27
27
 
28
+ Scenario: Simple puzzle within comment block
29
+ Given I have a "test/a/b/Sample.java" file with content:
30
+ """
31
+ public class Main {
32
+ /**
33
+ * Some other documentation
34
+ * text that is not relevant to
35
+ * the puzzle below.
36
+ * @todo #13 This puzzle has a correct format
37
+ * It doesn't start with a space on
38
+ * the second and the third lines
39
+ */
40
+ public void main(String[] args) {
41
+ // later
42
+ }
43
+ }
44
+ """
45
+ When I run pdd
46
+ Then XML matches "/puzzles[count(puzzle)=1]"
47
+ And XML matches "//puzzle[file='test/a/b/Sample.java']"
48
+ And XML matches "//puzzle[ticket='13']"
49
+ And XML matches "//puzzle[lines='6-8']"
50
+ And XML matches "//puzzle[starts-with(body,'This')]"
51
+ And XML matches "//puzzle[role='DEV']"
52
+ And XML matches "//puzzle[estimate='0']"
53
+
28
54
  Scenario: Multiple puzzles in one file
29
55
  Given I have a "test/a/b/c/Sample.java" file with content:
30
56
  """
@@ -34,6 +60,9 @@ Feature: Parsing
34
60
  * @todo #ABC-67:15min And this one ever later
35
61
  * @todo #F-78-3:2h/DEV This is for a developer
36
62
  * who will join us later
63
+ * @todo #44 This puzzle has a correct format
64
+ * even though it doesn't start with a space on
65
+ * the second and the third lines
37
66
  */
38
67
  public void main(String[] args) {
39
68
  // later
@@ -41,10 +70,11 @@ Feature: Parsing
41
70
  }
42
71
  """
43
72
  When I run pdd
44
- Then XML matches "/puzzles[count(puzzle)=3]"
73
+ Then XML matches "/puzzles[count(puzzle)=4]"
45
74
  And XML matches "//puzzle[ticket='13' and lines='3-3']"
46
75
  And XML matches "//puzzle[ticket='13' and body='This one later']"
47
76
  And XML matches "//puzzle[ticket='ABC-67' and lines='4-4']"
48
77
  And XML matches "//puzzle[ticket='F-78-3' and lines='5-6']"
49
78
  And XML matches "//puzzle[ticket='ABC-67' and estimate='15']"
50
79
  And XML matches "//puzzle[ticket='F-78-3' and estimate='120']"
80
+ And XML matches "//puzzle[ticket='44' and lines='7-9']"
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -79,9 +79,7 @@ When(%r{^I run bin/pdd with "([^"]*)"$}) do |arg|
79
79
  end
80
80
 
81
81
  Then(/^Stdout contains "([^"]*)"$/) do |txt|
82
- unless @stdout.include?(txt)
83
- raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}"
84
- end
82
+ raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt)
85
83
  end
86
84
 
87
85
  Then(/^Stdout is empty$/) do
@@ -93,9 +91,7 @@ Then(/^XML file "([^"]+)" matches "([^"]+)"$/) do |file, xpath|
93
91
 
94
92
  xml = Nokogiri::XML.parse(File.read(file))
95
93
  xml.remove_namespaces!
96
- if xml.xpath(xpath).empty?
97
- raise "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}"
98
- end
94
+ raise "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}" if xml.xpath(xpath).empty?
99
95
  end
100
96
 
101
97
  Then(/^Exit code is zero$/) do
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/pdd/puzzle.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/pdd/rake_task.rb CHANGED
@@ -22,18 +22,8 @@ module PDD
22
22
  task(name, *args) do |_, task_args|
23
23
  RakeFileUtils.send(:verbose, true) do
24
24
  yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
25
- run
26
25
  end
27
26
  end
28
27
  end
29
-
30
- private
31
-
32
- def run
33
- # @todo #125:30m need to implement this method.
34
- # For now, it's just a task,
35
- # that prints a simple Running pdd... message to user
36
- puts 'Running pdd...' unless @quiet
37
- end
38
28
  end
39
29
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/pdd/rule/text.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/pdd/source.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -37,10 +37,31 @@ module PDD
37
37
  @path = path
38
38
  end
39
39
 
40
- def match_markers(line)
41
- MARKERS.map do |mkr|
42
- %r{(.*(?:^|\s))#{mkr}\s+#([\w\-.:/]+)\s+(.+)}.match(line)
43
- end.compact
40
+ def match_markers(l)
41
+ if l.downcase.include? 'todo'
42
+ /[^\s]\x40todo/.match(l) do |_|
43
+ raise Error, get_no_leading_space_error("\x40todo")
44
+ end
45
+ /\x40todo(?!\s+#)/.match(l) do |_|
46
+ raise Error, get_no_puzzle_marker_error("\x40todo")
47
+ end
48
+ /\x40todo\s+#\s/.match(l) do |_|
49
+ raise Error, get_space_after_hash_error("\x40todo")
50
+ end
51
+ /[^\s]TODO:?/.match(l) do |_|
52
+ raise Error, get_no_leading_space_error('TODO')
53
+ end
54
+ /TODO(?!:?\s+#)/.match(l) do |_|
55
+ raise Error, get_no_puzzle_marker_error('TODO')
56
+ end
57
+ /TODO:?\s+#\s/.match(l) do |_|
58
+ raise Error, get_space_after_hash_error('TODO')
59
+ end
60
+ a = [%r{(.*(?:^|\s))(?:\x40todo|TODO:|TODO)\s+#([\w\-.:/]+)\s+(.+)}.match(l)]
61
+ a.compact
62
+ else
63
+ []
64
+ end
44
65
  end
45
66
 
46
67
  # Fetch all puzzles.
@@ -50,7 +71,6 @@ module PDD
50
71
  lines = File.readlines(@file, encoding: 'UTF-8')
51
72
  lines.each_with_index do |line, idx|
52
73
  begin
53
- check_rules(line)
54
74
  match_markers(line).each do |m|
55
75
  puzzles << puzzle(lines.drop(idx + 1), m, idx)
56
76
  end
@@ -82,30 +102,9 @@ after the hash sign, it should not be there, \
82
102
  see https://github.com/cqfn/pdd#how-to-format"
83
103
  end
84
104
 
85
- def check_rules(line)
86
- /[^\s]\x40todo/.match(line) do |_|
87
- raise Error, get_no_leading_space_error("\x40todo")
88
- end
89
- /\x40todo(?!\s+#)/.match(line) do |_|
90
- raise Error, get_no_puzzle_marker_error("\x40todo")
91
- end
92
- /\x40todo\s+#\s/.match(line) do |_|
93
- raise Error, get_space_after_hash_error("\x40todo")
94
- end
95
- /[^\s]TODO:?/.match(line) do |_|
96
- raise Error, get_no_leading_space_error('TODO')
97
- end
98
- /TODO(?!:?\s+#)/.match(line) do |_|
99
- raise Error, get_no_puzzle_marker_error('TODO')
100
- end
101
- /TODO:?\s+#\s/.match(line) do |_|
102
- raise Error, get_space_after_hash_error('TODO')
103
- end
104
- end
105
-
106
105
  # Fetch puzzle
107
106
  def puzzle(lines, match, idx)
108
- tail = tail(lines, match[1], idx)
107
+ tail = tail(lines, match[1])
109
108
  body = "#{match[3]} #{tail.join(' ')}".gsub(/\s+/, ' ').strip
110
109
  body = body.chomp('*/-->').strip
111
110
  marker = marker(match[2])
@@ -142,18 +141,17 @@ against the rules explained here: https://github.com/cqfn/pdd#how-to-format"
142
141
  end
143
142
 
144
143
  # Fetch puzzle tail (all lines after the first one)
145
- def tail(lines, prefix, start)
144
+ def tail(lines, prefix)
145
+ prefix = prefix.rstrip
146
146
  lines
147
147
  .take_while { |t| match_markers(t).none? && t.start_with?(prefix) }
148
+ .take_while do |t|
149
+ # account for carriage return in line endings
150
+ t_len = t.length - 1
151
+ t_len <= prefix.length || t_len > prefix.length + 2
152
+ end
148
153
  .map { |t| t[prefix.length, t.length] }
149
- .take_while { |t| t =~ /^[ a-zA-Z0-9]/ }
150
- .each_with_index do |t, i|
151
- next if t.start_with?(' ')
152
-
153
- raise Error, "Space expected at #{start + i + 2}:#{prefix.length}; \
154
- make sure all lines in the puzzle body have a single leading space."
155
- end
156
- .map { |t| t[1, t.length] }
154
+ .map { |t| t.start_with?(' ') ? t[1, t.length] : t }
157
155
  end
158
156
 
159
157
  # @todo #75:30min Let's make it possible to fetch Subversion data
data/lib/pdd/sources.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -19,8 +19,8 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require 'rainbow'
22
- require 'shellwords'
23
22
  require 'English'
23
+ require 'filemagic'
24
24
  require_relative 'source'
25
25
  require_relative '../../utils/glob'
26
26
 
@@ -77,20 +77,20 @@ module PDD
77
77
 
78
78
  private
79
79
 
80
- # @todo #98:30min Change the implementation of this method
81
- # to also work in Windows machines. Investigate the possibility
82
- # of use a gem for this. After that, remove the skip of the test
83
- # `test_ignores_binary_files` in `test_sources.rb`.
84
80
  def binary?(file)
85
- return false if Gem.win_platform?
86
-
87
- `grep -qI '.' #{Shellwords.escape(file)}`
88
- if $CHILD_STATUS.success?
81
+ if text_file?(file)
89
82
  false
90
83
  else
91
84
  PDD.log.info "#{file} is a binary file (#{File.size(file)} bytes)"
92
85
  true
93
86
  end
94
87
  end
88
+
89
+ def text_file?(file)
90
+ fm = FileMagic.new(FileMagic::MAGIC_MIME)
91
+ fm.file(file) =~ %r{^text/}
92
+ ensure
93
+ fm.close
94
+ end
95
95
  end
96
96
  end
data/lib/pdd/version.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -20,8 +20,8 @@
20
20
 
21
21
  # PDD main module.
22
22
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
23
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module PDD
26
- VERSION = '0.20.8'.freeze
26
+ VERSION = '0.21.0'.freeze
27
27
  end
data/lib/pdd.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -30,7 +30,7 @@ require_relative 'pdd/rule/roles'
30
30
 
31
31
  # PDD main module.
32
32
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
33
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
34
34
  # License:: MIT
35
35
  module PDD
36
36
  # If it breaks.
data/pdd.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -47,6 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
48
48
  s.add_runtime_dependency 'nokogiri', '~> 1.10'
49
49
  s.add_runtime_dependency 'rainbow', '~> 3.0'
50
+ s.add_runtime_dependency 'ruby-filemagic', '~> 0.7.2'
50
51
  s.add_runtime_dependency 'slop', '~> 4.6'
51
52
  s.add_development_dependency 'aruba', '~> 0.14.1'
52
53
  s.add_development_dependency 'codecov', '0.2.12'
data/test/test__helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -24,7 +24,7 @@ require_relative '../lib/pdd/rule/duplicates'
24
24
 
25
25
  # PDD::Rule::MaxDuplicates class test.
26
26
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
27
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
28
28
  # License:: MIT
29
29
  class TestMaxDuplicates < Minitest::Test
30
30
  def test_max_duplicates
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -24,7 +24,7 @@ require_relative '../lib/pdd/rule/estimates'
24
24
 
25
25
  # PDD::Rule::Estimate module tests.
26
26
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
27
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
28
28
  # License:: MIT
29
29
  class TestEstimates < Minitest::Test
30
30
  def test_min
data/test/test_pdd.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -26,7 +26,7 @@ require_relative '../lib/pdd'
26
26
 
27
27
  # PDD main module test.
28
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
29
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
30
30
  # License:: MIT
31
31
  class TestPDD < Minitest::Test
32
32
  def test_basic
data/test/test_roles.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -24,7 +24,7 @@ require_relative '../lib/pdd/rule/roles'
24
24
 
25
25
  # PDD::Rule::Role module tests.
26
26
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
27
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
28
28
  # License:: MIT
29
29
  class TestRoles < Minitest::Test
30
30
  def test_incorrect_role
data/test/test_source.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -25,7 +25,7 @@ require_relative '../lib/pdd/sources'
25
25
 
26
26
  # Source test.
27
27
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
28
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
29
29
  # License:: MIT
30
30
  class TestSource < Minitest::Test
31
31
  def test_parsing
@@ -46,8 +46,9 @@ class TestSource < Minitest::Test
46
46
  list = source.puzzles
47
47
  assert_equal 2, list.size
48
48
  puzzle = list.first
49
- assert_equal '2-3', puzzle.props[:lines]
50
- assert_equal 'привет, how are you doing?', puzzle.props[:body]
49
+ assert_equal '2-4', puzzle.props[:lines]
50
+ assert_equal 'привет, how are you doing? -something else', \
51
+ puzzle.props[:body]
51
52
  assert_equal '44', puzzle.props[:ticket]
52
53
  assert puzzle.props[:author].nil?
53
54
  assert puzzle.props[:email].nil?
@@ -78,20 +79,28 @@ class TestSource < Minitest::Test
78
79
  end
79
80
  end
80
81
 
81
- def test_failing_on_invalid_puzzle
82
+ def test_multiple_puzzles_single_comment_block
82
83
  Dir.mktmpdir 'test' do |dir|
83
84
  file = File.join(dir, 'a.txt')
84
85
  File.write(
85
86
  file,
86
87
  "
87
- * \x40todo #44 this is an incorrectly formatted puzzle,
88
- * with a second line without a leading space
88
+ /*
89
+ * \x40todo #1 First one with
90
+ * a few lines
91
+ * \x40todo #1 Second one also
92
+ * with a few lines
93
+ */
89
94
  "
90
95
  )
91
- error = assert_raises PDD::Error do
92
- stub_source_find_github_user(file, 'hey', &:puzzles)
96
+ stub_source_find_github_user(file, 'hey') do |source|
97
+ PDD.opts = nil
98
+ assert_equal 2, source.puzzles.size
99
+ puzzle = source.puzzles.last
100
+ assert_equal '5-6', puzzle.props[:lines]
101
+ assert_equal 'Second one also with a few lines', puzzle.props[:body]
102
+ assert_equal '1', puzzle.props[:ticket]
93
103
  end
94
- assert !error.message.index('Space expected').nil?
95
104
  end
96
105
  end
97
106
 
@@ -101,10 +110,10 @@ class TestSource < Minitest::Test
101
110
  File.write(
102
111
  file,
103
112
  "
104
- * \x40todo #44 this is an incorrectly formatted puzzle,
113
+ * \x40todo #44 this is a correctly formatted puzzle,
105
114
  * with a second line without a leading space
106
115
  Another badly formatted puzzle
107
- * \x40todo this puzzle misses ticket name/number
116
+ * \x40todo this bad puzzle misses ticket name/number
108
117
  Something else
109
118
  * \x40todo #123 This puzzle is correctly formatted
110
119
  "
@@ -113,11 +122,12 @@ class TestSource < Minitest::Test
113
122
  stub_source_find_github_user(file, 'hey') do |source|
114
123
  list = source.puzzles
115
124
  PDD.opts = nil
116
- assert_equal 1, list.size
125
+ assert_equal 2, list.size
117
126
  puzzle = list.first
118
- assert_equal '7-7', puzzle.props[:lines]
119
- assert_equal 'This puzzle is correctly formatted', puzzle.props[:body]
120
- assert_equal '123', puzzle.props[:ticket]
127
+ assert_equal '2-3', puzzle.props[:lines]
128
+ assert_equal 'this is a correctly formatted puzzle, with a second ' \
129
+ 'line without a leading space', puzzle.props[:body]
130
+ assert_equal '44', puzzle.props[:ticket]
121
131
  end
122
132
  end
123
133
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -53,7 +53,7 @@ class TestSourceTodo < Minitest::Test
53
53
  def test_todo_parsing
54
54
  check_valid_puzzle(
55
55
  "
56
- // TODO #45 task description
56
+ // @todo #45 task description
57
57
  ",
58
58
  '2-2',
59
59
  'task description',
@@ -64,7 +64,7 @@ class TestSourceTodo < Minitest::Test
64
64
  def test_todo_parsing_multi_line
65
65
  check_valid_puzzle(
66
66
  "
67
- // TODO #45 task description
67
+ // @todo #45 task description
68
68
  // second line
69
69
  ",
70
70
  '2-3',
@@ -121,24 +121,6 @@ class TestSourceTodo < Minitest::Test
121
121
  )
122
122
  end
123
123
 
124
- def test_todo_failing_no_space_on_second_line
125
- check_invalid_puzzle(
126
- "
127
- * TODO #45 this puzzle
128
- * has not space on second line",
129
- 'Space expected'
130
- )
131
- end
132
-
133
- def test_todo_colon_failing_no_space_on_second_line
134
- check_invalid_puzzle(
135
- "
136
- * TODO: #45 this puzzle
137
- * has not space on second line",
138
- 'Space expected'
139
- )
140
- end
141
-
142
124
  def test_todo_failing_no_ticket
143
125
  check_invalid_puzzle(
144
126
  "
data/test/test_sources.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -26,7 +26,7 @@ require_relative '../lib/pdd/sources'
26
26
 
27
27
  # Sources test.
28
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
29
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
30
30
  # License:: MIT
31
31
  class TestSources < Minitest::Test
32
32
  def test_iterator
@@ -37,7 +37,6 @@ class TestSources < Minitest::Test
37
37
  end
38
38
 
39
39
  def test_ignores_binary_files
40
- skip if Gem.win_platform?
41
40
  in_temp([]) do |dir|
42
41
  [
43
42
  'README.md',
data/test/test_text.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -24,7 +24,7 @@ require_relative '../lib/pdd/rule/text'
24
24
 
25
25
  # PDD::Rule::Text module tests.
26
26
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
- # Copyright:: Copyright (c) 2014-2021 Yegor Bugayenko
27
+ # Copyright:: Copyright (c) 2014-2022 Yegor Bugayenko
28
28
  # License:: MIT
29
29
  class TestText < Minitest::Test
30
30
  def test_min_words
data/utils/glob.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2021 Yegor Bugayenko
1
+ # Copyright (c) 2014-2022 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -27,7 +27,6 @@ class Glob
27
27
  end
28
28
 
29
29
  # rubocop:disable Metrics/CyclomaticComplexity
30
- # rubocop:disable Metrics/MethodLength
31
30
  def to_regexp
32
31
  chars = @glob_string.gsub(%r{(\*\*\/\*)|(\*\*)}, '*').split('')
33
32
  in_curlies = 0, escaping = false
@@ -63,5 +62,4 @@ class Glob
63
62
  end.join
64
63
  end
65
64
  # rubocop:enable Metrics/CyclomaticComplexity
66
- # rubocop:enable Metrics/MethodLength
67
65
  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.20.8
4
+ version: 0.21.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: 2021-12-17 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-filemagic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: slop
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -219,18 +233,18 @@ files:
219
233
  - ".gitattributes"
220
234
  - ".github/ISSUE_TEMPLATE.md"
221
235
  - ".github/PULL_REQUEST_TEMPLATE.md"
236
+ - ".github/workflows/codecov.yml"
237
+ - ".github/workflows/rake.yml"
222
238
  - ".gitignore"
223
239
  - ".overcommit.yml"
224
240
  - ".pdd"
225
241
  - ".rubocop.yml"
226
242
  - ".rultor.yml"
227
243
  - ".simplecov"
228
- - ".travis.yml"
229
244
  - Gemfile
230
245
  - LICENSE.txt
231
246
  - README.md
232
247
  - Rakefile
233
- - appveyor.yml
234
248
  - assets/puzzles.xsd
235
249
  - assets/puzzles.xsl
236
250
  - bin/pdd
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.0
4
- cache: bundler
5
- branches:
6
- only:
7
- - master
8
- install:
9
- - travis_retry bundle update
10
- script:
11
- - bundle exec rake
12
- after_success:
13
- - "bash <(curl -s https://codecov.io/bash)"
data/appveyor.yml DELETED
@@ -1,21 +0,0 @@
1
- version: '{build}'
2
- skip_tags: true
3
- clone_depth: 10
4
- branches:
5
- only:
6
- - master
7
- except:
8
- - gh-pages
9
- os: Windows Server 2012
10
- install:
11
- - cmd: SET PATH=C:\Ruby23-x64\bin;%PATH%
12
- - cmd: ruby --version
13
- - cmd: git --version
14
- build_script:
15
- - bundle update
16
- - bundle install
17
- test_script:
18
- - rake
19
- cache:
20
- - C:\Ruby200\bin -> pdd.gemspec
21
- - C:\Ruby200\lib\ruby\gems\2.0.0 -> pdd.gemspec