distincter2 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/bin/distincter2 +2 -0
- data/lib/distincter2/checker.rb +21 -7
- data/lib/distincter2/config.rb +40 -0
- data/lib/distincter2.rb +12 -2
- metadata +3 -2
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,6 +1,7 @@
|
|
1
1
|
# distincter2
|
2
2
|
|
3
3
|
[![GitHubActions](https://github.com/fartem/distincter2/workflows/Build/badge.svg)](https://github.com/fartem/distincter2/actions?branch=master)
|
4
|
+
[![codebeat badge](https://codebeat.co/badges/69d6a564-ddda-495b-9e10-107bf7691fb0)](https://codebeat.co/projects/github-com-fartem-distincter2-master)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/distincter2.svg)](https://badge.fury.io/rb/distincter2)
|
5
6
|
|
6
7
|
## About
|
@@ -22,6 +23,15 @@ $ distincter2 ./path_to_directory_with_markdown_files
|
|
22
23
|
$ ./bin/local_distincter2 ./path_to_directory_with_markdown_files
|
23
24
|
```
|
24
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
|
+
|
25
35
|
## Contributors
|
26
36
|
|
27
37
|
* [@fartem](https://github.com/fartem) as Artem Fomchenkov
|
data/bin/distincter2
CHANGED
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,14 +1,14 @@
|
|
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
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- bin/distincter2
|
94
94
|
- lib/distincter2.rb
|
95
95
|
- lib/distincter2/checker.rb
|
96
|
+
- lib/distincter2/config.rb
|
96
97
|
homepage: https://github.com/fartem/distincter2
|
97
98
|
licenses:
|
98
99
|
- MIT
|