distincter2 1.1.4 → 1.3.0
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/README.md +24 -0
- data/bin/distincter2 +15 -2
- data/lib/distincter2/checker.rb +21 -7
- data/lib/distincter2/config.rb +40 -0
- data/lib/distincter2.rb +12 -2
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ffd3065d97f5ea86eaa09c2a0a12f1d86bbce35409c8469ae4a3593284d831a
|
4
|
+
data.tar.gz: 40b4baf7cddb4ce8123442a7efb7b6e3c21a7a07236e0c3fe523877bc1c8901e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 238b6ca822da1fe8752e8dfbeea444cccf51ac237f9e044543ac92552d012bd4c330d4798bcd666e758b372bd5ad21c585abf8539f8ad41afe976780c79833bc
|
7
|
+
data.tar.gz: f526bdee7e4be1bebd6af837d223bef292c67c7b34d7a7078afa3d8def5722d11d1b88cc120e4b669c94927dbed3f324cf3d3f500b89f77a16406c9dd362e7e6
|
data/README.md
CHANGED
@@ -1,13 +1,37 @@
|
|
1
1
|
# distincter2
|
2
2
|
|
3
|
+
[](https://github.com/fartem/distincter2/actions?branch=master)
|
4
|
+
[](https://codebeat.co/projects/github-com-fartem-distincter2-master)
|
5
|
+
[](https://badge.fury.io/rb/distincter2)
|
6
|
+
|
7
|
+
## About
|
8
|
+
|
3
9
|
A tool that can check lists in Markdown files and find duplicates.
|
4
10
|
|
5
11
|
## How to use
|
6
12
|
|
13
|
+
### Global installation
|
14
|
+
|
15
|
+
```shell
|
16
|
+
$ gem i distincter2
|
17
|
+
$ distincter2 ./path_to_directory_with_markdown_files
|
18
|
+
```
|
19
|
+
|
20
|
+
### Local installation
|
21
|
+
|
7
22
|
```shell
|
8
23
|
$ ./bin/local_distincter2 ./path_to_directory_with_markdown_files
|
9
24
|
```
|
10
25
|
|
26
|
+
### Config
|
27
|
+
|
28
|
+
Add `distincter2_config.d2c` to root of your project and add excluded files line by line:
|
29
|
+
|
30
|
+
```text
|
31
|
+
BOOKS.md
|
32
|
+
DONE.md
|
33
|
+
```
|
34
|
+
|
11
35
|
## Contributors
|
12
36
|
|
13
37
|
* [@fartem](https://github.com/fartem) as Artem Fomchenkov
|
data/bin/distincter2
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
3
5
|
require 'distincter2'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
# @param text String
|
9
|
+
def red_colored_text(text)
|
10
|
+
text.colorize(:light_red)
|
11
|
+
end
|
4
12
|
|
5
|
-
|
6
|
-
|
13
|
+
if ::ARGV.empty?
|
14
|
+
puts red_colored_text('ERROR: You need to provide a path to directory with files.').to_s
|
15
|
+
exit(1)
|
16
|
+
else
|
17
|
+
distincter2 = ::Distincter2::Distincter2.new
|
18
|
+
distincter2.start(::ARGV[0])
|
19
|
+
end
|
data/lib/distincter2/checker.rb
CHANGED
@@ -1,42 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Distincter2
|
2
4
|
# distincter2 checker.
|
3
5
|
# Handles a file and operate them.
|
4
6
|
class D2Checker
|
5
|
-
#
|
6
|
-
|
7
|
+
# @param {D2Config} config
|
8
|
+
# @param {Boolean} mute
|
9
|
+
def initialize(config, mute: false)
|
10
|
+
@config = config
|
7
11
|
@mute = mute
|
8
12
|
end
|
9
13
|
|
10
|
-
#
|
14
|
+
# @param {String} path
|
11
15
|
def check(path)
|
12
16
|
duplicates = analyze_dir(path)
|
17
|
+
|
13
18
|
exit(duplicates.empty? ? 0 : 1)
|
14
19
|
end
|
15
20
|
|
16
|
-
#
|
21
|
+
# @param {String} path
|
22
|
+
# @return {String[]}
|
17
23
|
# rubocop:disable Metrics/MethodLength
|
18
24
|
def analyze_dir(path)
|
19
25
|
duplicates = []
|
20
26
|
::Dir.foreach(path).each do |entry|
|
21
27
|
next if entry.start_with?('.')
|
22
28
|
|
23
|
-
|
24
|
-
|
29
|
+
entry_name = ::File.basename(entry)
|
30
|
+
|
31
|
+
file = "#{::File.absolute_path(path)}/#{entry_name}"
|
25
32
|
if ::File.directory?(file)
|
26
33
|
analyze_result = analyze_dir(file)
|
27
34
|
else
|
28
35
|
next unless entry.end_with?('.md')
|
29
36
|
|
37
|
+
next if @config.exclude_paths.include?(entry_name)
|
38
|
+
|
30
39
|
analyze_result = analyze_file(file)
|
31
40
|
end
|
41
|
+
|
32
42
|
duplicates += analyze_result unless analyze_result.empty?
|
33
43
|
end
|
44
|
+
|
34
45
|
duplicates
|
35
46
|
end
|
36
47
|
|
37
48
|
# rubocop:enable Metrics/MethodLength
|
38
49
|
|
39
|
-
#
|
50
|
+
# @param {String} path
|
51
|
+
# @return {String[]}
|
40
52
|
# rubocop:disable Metrics/MethodLength
|
41
53
|
def analyze_file(path)
|
42
54
|
lines = []
|
@@ -45,6 +57,7 @@ module Distincter2
|
|
45
57
|
lines << line if !line.empty? && line.start_with?('-')
|
46
58
|
end
|
47
59
|
end
|
60
|
+
|
48
61
|
duplicates = lines.select { |line| lines.count(line) > 1 }
|
49
62
|
.uniq
|
50
63
|
unless @mute
|
@@ -52,6 +65,7 @@ module Distincter2
|
|
52
65
|
puts("#{path} : #{duplicate}")
|
53
66
|
end
|
54
67
|
end
|
68
|
+
|
55
69
|
duplicates
|
56
70
|
end
|
57
71
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module Distincter2
|
6
|
+
# Distincter2 config.
|
7
|
+
class D2Config
|
8
|
+
# @param {String[]} exclude_paths
|
9
|
+
def initialize(exclude_paths)
|
10
|
+
@exclude_paths = exclude_paths.to_set
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :exclude_paths
|
14
|
+
end
|
15
|
+
|
16
|
+
# D2Config with empty arguments.
|
17
|
+
class D2ConfigEmpty < ::Distincter2::D2Config
|
18
|
+
# Constructor without paths.
|
19
|
+
def initialize
|
20
|
+
super([])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# D2Config parser.
|
25
|
+
class D2ConfigParser
|
26
|
+
# @param {String} config_path
|
27
|
+
def initialize(config_path)
|
28
|
+
@config_path = config_path
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return {D2Config}
|
32
|
+
def parse
|
33
|
+
exclude_paths = []
|
34
|
+
::File.open(@config_path, 'r') do |file|
|
35
|
+
exclude_paths += file.readlines.map(&:strip)
|
36
|
+
end
|
37
|
+
::Distincter2::D2Config.new(exclude_paths)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/distincter2.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative './distincter2/checker'
|
4
|
+
require_relative './distincter2/config'
|
2
5
|
|
3
6
|
module Distincter2
|
4
7
|
# distincter2 runner. Just an entrypoint.
|
5
8
|
class Distincter2
|
6
|
-
#
|
9
|
+
#
|
7
10
|
# You need a project path to run validation.
|
8
11
|
def start(path)
|
9
|
-
|
12
|
+
config_path = "#{path}/distincter2_config.d2c"
|
13
|
+
checker = ::Distincter2::D2Checker.new(
|
14
|
+
if ::File.exist?(config_path)
|
15
|
+
::Distincter2::D2ConfigParser.new(config_path).parse
|
16
|
+
else
|
17
|
+
::Distincter2::D2ConfigEmpty.new
|
18
|
+
end
|
19
|
+
)
|
10
20
|
checker.check(path)
|
11
21
|
end
|
12
22
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distincter2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Fomchenkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,7 +93,8 @@ files:
|
|
79
93
|
- bin/distincter2
|
80
94
|
- lib/distincter2.rb
|
81
95
|
- lib/distincter2/checker.rb
|
82
|
-
|
96
|
+
- lib/distincter2/config.rb
|
97
|
+
homepage: https://github.com/fartem/distincter2
|
83
98
|
licenses:
|
84
99
|
- MIT
|
85
100
|
metadata: {}
|