distincter2 1.3.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -1
- data/lib/distincter2/checker.rb +27 -15
- data/lib/distincter2/config.rb +43 -10
- data/lib/distincter2.rb +19 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7356757437f888b0a6ab4054086150075337e10a56bd32c970bd2bd1e6c5687
|
4
|
+
data.tar.gz: 385dddc273aab58dad6002c533feeb72002f886fdb82ef45ce35f12a8d7179f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20c5b2ea990ec92ead8e5b0808ab0ce1cb75f2dc3bc0075c3945e1f40e5cfb5cc5fc17cfbe13368d34817841455d81c799103a615746665a0fa472c3759fa867
|
7
|
+
data.tar.gz: a8d452f076387b8087486e251adfdf9d43033213da477f8ff3ddacfceee6c212d70f3717ecb40369a9a5e0d3e25eeee62738788c6be162a00473b2c80a4f1e5e
|
data/README.md
CHANGED
@@ -25,13 +25,49 @@ $ ./bin/local_distincter2 ./path_to_directory_with_markdown_files
|
|
25
25
|
|
26
26
|
### Config
|
27
27
|
|
28
|
-
Add `distincter2_config.d2c` to root of your project and add excluded files line by line
|
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`:
|
29
35
|
|
30
36
|
```text
|
37
|
+
v1
|
38
|
+
|
31
39
|
BOOKS.md
|
32
40
|
DONE.md
|
33
41
|
```
|
34
42
|
|
43
|
+
Or without `v1`:
|
44
|
+
|
45
|
+
```text
|
46
|
+
BOOKS.md
|
47
|
+
DONE.md
|
48
|
+
```
|
49
|
+
|
50
|
+
## How to contribute
|
51
|
+
|
52
|
+
### Documentation
|
53
|
+
|
54
|
+
Just run:
|
55
|
+
|
56
|
+
```shell
|
57
|
+
$ rdoc
|
58
|
+
```
|
59
|
+
|
60
|
+
### Contribution
|
61
|
+
|
62
|
+
Read [Commit Convention](./COMMIT_CONVENTION.md). Make sure your build is green before you contribute your pull request.
|
63
|
+
Then:
|
64
|
+
|
65
|
+
```shell
|
66
|
+
$ bundle exec rake
|
67
|
+
```
|
68
|
+
|
69
|
+
If you don't see any error messages, submit your pull request.
|
70
|
+
|
35
71
|
## Contributors
|
36
72
|
|
37
73
|
* [@fartem](https://github.com/fartem) as Artem Fomchenkov
|
data/lib/distincter2/checker.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Distincter2
|
4
|
-
#
|
5
|
-
# Handles a file and operate them.
|
4
|
+
# Class to check for duplicate lines in markdown files
|
6
5
|
class D2Checker
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# Initialize the D2Checker with a configuration object and an optional mute flag
|
7
|
+
#
|
8
|
+
# @param config [Object] The configuration object containing settings for the checker
|
9
|
+
# @param mute [Boolean] A flag indicating whether to mute the output of duplicate lines (default: false)
|
9
10
|
def initialize(config, mute: false)
|
10
11
|
@config = config
|
11
12
|
@mute = mute
|
12
13
|
end
|
13
14
|
|
14
|
-
#
|
15
|
+
# Check for duplicate lines in markdown files within a given directory
|
16
|
+
#
|
17
|
+
# @param path [String] The path to the directory to check
|
18
|
+
# @return [Array] An array of duplicate lines found in the markdown files
|
15
19
|
def check(path)
|
16
20
|
duplicates = analyze_dir(path)
|
17
21
|
|
18
22
|
exit(duplicates.empty? ? 0 : 1)
|
19
23
|
end
|
20
24
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
25
|
+
# Recursively analyze a directory for duplicate lines in markdown files
|
26
|
+
#
|
27
|
+
# @param path [String] The path to the directory to analyze
|
28
|
+
# @return [Array] An array of duplicate lines found in the markdown files
|
24
29
|
def analyze_dir(path)
|
25
30
|
duplicates = []
|
26
31
|
::Dir.foreach(path).each do |entry|
|
@@ -34,7 +39,7 @@ module Distincter2
|
|
34
39
|
else
|
35
40
|
next unless entry.end_with?('.md')
|
36
41
|
|
37
|
-
next
|
42
|
+
next unless can_analyze(entry_name)
|
38
43
|
|
39
44
|
analyze_result = analyze_file(file)
|
40
45
|
end
|
@@ -45,11 +50,20 @@ module Distincter2
|
|
45
50
|
duplicates
|
46
51
|
end
|
47
52
|
|
48
|
-
#
|
53
|
+
# Check if a file can be analyzed based on the configuration settings
|
54
|
+
#
|
55
|
+
# @param entry [String] The name of the file to check
|
56
|
+
# @return [Boolean] True if the file can be analyzed, false otherwise
|
57
|
+
def can_analyze(entry)
|
58
|
+
return false unless @config.version == 'v1'
|
49
59
|
|
50
|
-
|
51
|
-
|
52
|
-
|
60
|
+
@config.exclude_paths.none?(entry)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Analyze a markdown file for duplicate lines
|
64
|
+
#
|
65
|
+
# @param path [String] The path to the markdown file to analyze
|
66
|
+
# @return [Array] An array of duplicate lines found in the markdown file
|
53
67
|
def analyze_file(path)
|
54
68
|
lines = []
|
55
69
|
::File.open(path, 'r') do |file|
|
@@ -68,7 +82,5 @@ module Distincter2
|
|
68
82
|
|
69
83
|
duplicates
|
70
84
|
end
|
71
|
-
|
72
|
-
# rubocop:enable Metrics/MethodLength
|
73
85
|
end
|
74
86
|
end
|
data/lib/distincter2/config.rb
CHANGED
@@ -3,38 +3,71 @@
|
|
3
3
|
require 'set'
|
4
4
|
|
5
5
|
module Distincter2
|
6
|
-
# Distincter2
|
6
|
+
# Class representing the configuration for Distincter2.
|
7
7
|
class D2Config
|
8
|
-
#
|
9
|
-
|
8
|
+
# Initializes a new instance of D2Config.
|
9
|
+
#
|
10
|
+
# @param exclude_paths [Array<String>] An array of paths to be excluded.
|
11
|
+
# @param version [String] The version of the configuration. Default is 'v1'.
|
12
|
+
def initialize(exclude_paths, version = 'v1')
|
10
13
|
@exclude_paths = exclude_paths.to_set
|
14
|
+
@version = version
|
11
15
|
end
|
12
16
|
|
17
|
+
# Accessor for the exclude_paths attribute.
|
18
|
+
#
|
19
|
+
# @return [Set<String>] The set of paths to be excluded.
|
13
20
|
attr_accessor :exclude_paths
|
21
|
+
|
22
|
+
# Accessor for the version attribute.
|
23
|
+
#
|
24
|
+
# @return [String] The version of the configuration.
|
25
|
+
attr_accessor :version
|
14
26
|
end
|
15
27
|
|
16
|
-
#
|
17
|
-
class
|
28
|
+
# Class representing an empty configuration for Distincter2.
|
29
|
+
# This class inherits from D2Config and initializes with an empty array of exclude_paths.
|
30
|
+
class D2EmptyConfig < ::Distincter2::D2Config
|
18
31
|
# Constructor without paths.
|
32
|
+
#
|
33
|
+
# @return [void]
|
19
34
|
def initialize
|
35
|
+
# Calls the parent class's initialize method with an empty array of exclude_paths.
|
20
36
|
super([])
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
24
|
-
#
|
40
|
+
# Class representing a parser for Distincter2 configuration files.
|
25
41
|
class D2ConfigParser
|
26
|
-
#
|
42
|
+
# Initializes a new instance of D2ConfigParser.
|
43
|
+
#
|
44
|
+
# @param config_path [String] The path to the configuration file.
|
27
45
|
def initialize(config_path)
|
28
46
|
@config_path = config_path
|
29
47
|
end
|
30
48
|
|
31
|
-
#
|
49
|
+
# Parses the configuration file and returns a D2Config object.
|
50
|
+
#
|
51
|
+
# @return [Distincter2::D2Config] A D2Config object representing the parsed configuration.
|
32
52
|
def parse
|
33
53
|
exclude_paths = []
|
54
|
+
version = 'v1'
|
55
|
+
|
56
|
+
# Open the configuration file and read its lines.
|
34
57
|
::File.open(@config_path, 'r') do |file|
|
35
|
-
|
58
|
+
file.readlines.each do |line|
|
59
|
+
l = line.strip
|
60
|
+
|
61
|
+
# Skip lines that contain the version number or are empty.
|
62
|
+
next if l == 'v1' || l.empty?
|
63
|
+
|
64
|
+
# Add the non-empty, non-version lines to the exclude_paths array.
|
65
|
+
exclude_paths << l
|
66
|
+
end
|
36
67
|
end
|
37
|
-
|
68
|
+
|
69
|
+
# Create a new D2Config object with the parsed exclude_paths and version.
|
70
|
+
::Distincter2::D2Config.new(exclude_paths, version)
|
38
71
|
end
|
39
72
|
end
|
40
73
|
end
|
data/lib/distincter2.rb
CHANGED
@@ -5,18 +5,35 @@ require_relative './distincter2/config'
|
|
5
5
|
|
6
6
|
module Distincter2
|
7
7
|
# distincter2 runner. Just an entrypoint.
|
8
|
+
# This class represents the main entry point for the Distincter2 runner.
|
8
9
|
class Distincter2
|
10
|
+
# This method starts the validation process for a given project path.
|
9
11
|
#
|
10
|
-
#
|
12
|
+
# @param path [String] The path to the project directory.
|
13
|
+
# @return [void]
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# # Create an instance of Distincter2
|
17
|
+
# distincter = Distincter2.new
|
18
|
+
#
|
19
|
+
# # Start the validation process for a project located at '/path/to/project'
|
20
|
+
# distincter.start('/path/to/project')
|
11
21
|
def start(path)
|
22
|
+
# Construct the path to the distincter2_config.d2c file
|
12
23
|
config_path = "#{path}/distincter2_config.d2c"
|
24
|
+
|
25
|
+
# Create a new D2Checker instance with the appropriate configuration
|
13
26
|
checker = ::Distincter2::D2Checker.new(
|
14
27
|
if ::File.exist?(config_path)
|
28
|
+
# If the config file exists, parse it and use the parsed configuration
|
15
29
|
::Distincter2::D2ConfigParser.new(config_path).parse
|
16
30
|
else
|
17
|
-
|
31
|
+
# If the config file does not exist, use an empty configuration
|
32
|
+
::Distincter2::D2EmptyConfig.new
|
18
33
|
end
|
19
34
|
)
|
35
|
+
|
36
|
+
# Run the validation process using the checker
|
20
37
|
checker.check(path)
|
21
38
|
end
|
22
39
|
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.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Fomchenkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|