distincter2 1.1.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2a0b38aad8d0e98961b541dbc6bca3ca880feda0e3c6fe23fdc52f90d75ba598
4
+ data.tar.gz: 0abbe05d2e3974cdd88b256b22b8dd890e94172629aa51d8f6e48f2edb8e5d3b
5
+ SHA512:
6
+ metadata.gz: c3cf97a6ec15e1a5ab94d03cc109fbfc9266eee27b95917c639070d220e1c670306365174b113f18eb4f655dd6c4ccd6f69414f4ed89a4c2bb432977a79a4095
7
+ data.tar.gz: cd77f9422e9ef6607dfcb8657e3811eddc9806c72327203010747959e8aed3b8ff1d2403e2c1e364df9082424774e90deaaa59f9b3029f9d33b649e9b44c2992
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Artem Fomchenkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # distincter2
2
+
3
+ A tool that can check lists in Markdown files and find duplicates.
4
+
5
+ ## How to use
6
+
7
+ ```shell
8
+ $ ./bin/local_distincter2 ./path_to_directory_with_markdown_files
9
+ ```
10
+
11
+ ## Contributors
12
+
13
+ * [@fartem](https://github.com/fartem) as Artem Fomchenkov
data/bin/distincter2 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'distincter2'
4
+
5
+ distincter2 = ::Distincter2::Distincter2.new
6
+ distincter2.start(::ARGV[0])
@@ -0,0 +1,60 @@
1
+ module Distincter2
2
+ # distincter2 checker.
3
+ # Handles a file and operate them.
4
+ class D2Checker
5
+ # Mute if you don't want to see errors in output
6
+ def initialize(mute: false)
7
+ @mute = mute
8
+ end
9
+
10
+ # Check entrypoint.
11
+ def check(path)
12
+ duplicates = analyze_dir(path)
13
+ exit(duplicates.empty? ? 0 : 1)
14
+ end
15
+
16
+ # Analyze given directory with recursion.
17
+ # rubocop:disable Metrics/MethodLength
18
+ def analyze_dir(path)
19
+ duplicates = []
20
+ ::Dir.foreach(path).each do |entry|
21
+ next if entry.start_with?('.')
22
+
23
+ file = "#{::File.absolute_path(path)}/#{::File.basename(entry)}"
24
+ analyze_result = []
25
+ if ::File.directory?(file)
26
+ analyze_result = analyze_dir(file)
27
+ else
28
+ next unless entry.end_with?('.md')
29
+
30
+ analyze_result = analyze_file(file)
31
+ end
32
+ duplicates += analyze_result unless analyze_result.empty?
33
+ end
34
+ duplicates
35
+ end
36
+
37
+ # rubocop:enable Metrics/MethodLength
38
+
39
+ # Analyze given file.
40
+ # rubocop:disable Metrics/MethodLength
41
+ def analyze_file(path)
42
+ lines = []
43
+ ::File.open(path, 'r') do |file|
44
+ file.each_line do |line|
45
+ lines << line if !line.empty? && line.start_with?('-')
46
+ end
47
+ end
48
+ duplicates = lines.select { |line| lines.count(line) > 1 }
49
+ .uniq
50
+ unless @mute
51
+ duplicates.each do |duplicate|
52
+ puts("#{path} : #{duplicate}")
53
+ end
54
+ end
55
+ duplicates
56
+ end
57
+
58
+ # rubocop:enable Metrics/MethodLength
59
+ end
60
+ end
@@ -0,0 +1,13 @@
1
+ require_relative './distincter2/checker'
2
+
3
+ module Distincter2
4
+ # distincter2 runner. Just an entrypoint.
5
+ class Distincter2
6
+ # distincter2 starter.
7
+ # You need a project path to run validation.
8
+ def start(path)
9
+ checker = ::Distincter2::D2Checker.new
10
+ checker.check(path)
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: distincter2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Artem Fomchenkov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 5.18.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 5.18.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.22.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.22.0
69
+ description:
70
+ email: artem.fomchenkov@outlook.com
71
+ executables:
72
+ - distincter2
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - README.md
76
+ files:
77
+ - LICENSE
78
+ - README.md
79
+ - bin/distincter2
80
+ - lib/distincter2.rb
81
+ - lib/distincter2/checker.rb
82
+ homepage: http://github.com/fartem/distincter2
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.4.10
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A tool that can check lists in Markdown files and find duplicates
106
+ test_files: []