distincter2 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/bin/distincter2 +2 -0
- data/lib/distincter2/checker.rb +28 -7
- data/lib/distincter2/config.rb +53 -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: 4b8d1d5aa62302ef718c566a9053311075f4999fc1e8509c1e2d93e788f85a87
|
4
|
+
data.tar.gz: 66ebec72784df7a866f179c730f354120db1e227911655a8ee11ce509947adb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81680f8b162f0851527be19be9a8018ebf34a9a613aab8f7451a9035ba3e8b1146303054810dff9724638ab3bd871965e27a2c030949c85804a2a477e0e6f4f4
|
7
|
+
data.tar.gz: 9c5898feafe48a5111c47bdbe99907c2b36eba081ffcc2d89f9e70cdaa9cbc542828f76f10cf6f64ba7d7dc68acb6a44a9793f2f4b0e324b11277b7e4c25fa1d
|
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,30 @@ $ 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. Below you can find examples.
|
29
|
+
|
30
|
+
#### v1
|
31
|
+
|
32
|
+
Provides basic list for excluding files by names (without directories).
|
33
|
+
|
34
|
+
Add `v1`:
|
35
|
+
|
36
|
+
```text
|
37
|
+
v1
|
38
|
+
|
39
|
+
BOOKS.md
|
40
|
+
DONE.md
|
41
|
+
```
|
42
|
+
|
43
|
+
Or without `v1`:
|
44
|
+
|
45
|
+
```text
|
46
|
+
BOOKS.md
|
47
|
+
DONE.md
|
48
|
+
```
|
49
|
+
|
25
50
|
## Contributors
|
26
51
|
|
27
52
|
* [@fartem](https://github.com/fartem) as Artem Fomchenkov
|
data/bin/distincter2
CHANGED
data/lib/distincter2/checker.rb
CHANGED
@@ -1,42 +1,61 @@
|
|
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 unless can_analyze(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} entry
|
51
|
+
def can_analyze(entry)
|
52
|
+
return false unless @config.version == 'v1'
|
53
|
+
|
54
|
+
@config.exclude_paths.none?(entry)
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param {String} path
|
58
|
+
# @return {String[]}
|
40
59
|
# rubocop:disable Metrics/MethodLength
|
41
60
|
def analyze_file(path)
|
42
61
|
lines = []
|
@@ -45,6 +64,7 @@ module Distincter2
|
|
45
64
|
lines << line if !line.empty? && line.start_with?('-')
|
46
65
|
end
|
47
66
|
end
|
67
|
+
|
48
68
|
duplicates = lines.select { |line| lines.count(line) > 1 }
|
49
69
|
.uniq
|
50
70
|
unless @mute
|
@@ -52,6 +72,7 @@ module Distincter2
|
|
52
72
|
puts("#{path} : #{duplicate}")
|
53
73
|
end
|
54
74
|
end
|
75
|
+
|
55
76
|
duplicates
|
56
77
|
end
|
57
78
|
|
@@ -0,0 +1,53 @@
|
|
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
|
+
# @param {String} version
|
10
|
+
def initialize(exclude_paths, version = 'v1')
|
11
|
+
@exclude_paths = exclude_paths.to_set
|
12
|
+
@version = version
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :exclude_paths, :version
|
16
|
+
end
|
17
|
+
|
18
|
+
# D2Config with empty arguments.
|
19
|
+
class D2ConfigEmpty < ::Distincter2::D2Config
|
20
|
+
# Constructor without paths.
|
21
|
+
def initialize
|
22
|
+
super([])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# D2Config parser.
|
27
|
+
class D2ConfigParser
|
28
|
+
# @param {String} config_path
|
29
|
+
def initialize(config_path)
|
30
|
+
@config_path = config_path
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return {D2Config}
|
34
|
+
# rubocop:disable Metrics/MethodLength
|
35
|
+
def parse
|
36
|
+
exclude_paths = []
|
37
|
+
version = 'v1'
|
38
|
+
::File.open(@config_path, 'r') do |file|
|
39
|
+
file.readlines.each do |line|
|
40
|
+
l = line.strip
|
41
|
+
|
42
|
+
next if l == 'v1'
|
43
|
+
|
44
|
+
next if l.empty?
|
45
|
+
|
46
|
+
exclude_paths << l
|
47
|
+
end
|
48
|
+
end
|
49
|
+
::Distincter2::D2Config.new(exclude_paths, version)
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/MethodLength
|
52
|
+
end
|
53
|
+
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.1
|
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
|