distincter2 1.3.1 → 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 +21 -0
- data/lib/distincter2/checker.rb +21 -16
- data/lib/distincter2/config.rb +34 -14
- 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
@@ -47,6 +47,27 @@ BOOKS.md
|
|
47
47
|
DONE.md
|
48
48
|
```
|
49
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
|
+
|
50
71
|
## Contributors
|
51
72
|
|
52
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|
|
@@ -45,18 +50,20 @@ module Distincter2
|
|
45
50
|
duplicates
|
46
51
|
end
|
47
52
|
|
48
|
-
#
|
49
|
-
|
50
|
-
# @param
|
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
|
51
57
|
def can_analyze(entry)
|
52
58
|
return false unless @config.version == 'v1'
|
53
59
|
|
54
60
|
@config.exclude_paths.none?(entry)
|
55
61
|
end
|
56
62
|
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
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
|
60
67
|
def analyze_file(path)
|
61
68
|
lines = []
|
62
69
|
::File.open(path, 'r') do |file|
|
@@ -75,7 +82,5 @@ module Distincter2
|
|
75
82
|
|
76
83
|
duplicates
|
77
84
|
end
|
78
|
-
|
79
|
-
# rubocop:enable Metrics/MethodLength
|
80
85
|
end
|
81
86
|
end
|
data/lib/distincter2/config.rb
CHANGED
@@ -3,51 +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'.
|
10
12
|
def initialize(exclude_paths, version = 'v1')
|
11
13
|
@exclude_paths = exclude_paths.to_set
|
12
14
|
@version = version
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
# Accessor for the exclude_paths attribute.
|
18
|
+
#
|
19
|
+
# @return [Set<String>] The set of paths to be excluded.
|
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
|
16
26
|
end
|
17
27
|
|
18
|
-
#
|
19
|
-
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
|
20
31
|
# Constructor without paths.
|
32
|
+
#
|
33
|
+
# @return [void]
|
21
34
|
def initialize
|
35
|
+
# Calls the parent class's initialize method with an empty array of exclude_paths.
|
22
36
|
super([])
|
23
37
|
end
|
24
38
|
end
|
25
39
|
|
26
|
-
#
|
40
|
+
# Class representing a parser for Distincter2 configuration files.
|
27
41
|
class D2ConfigParser
|
28
|
-
#
|
42
|
+
# Initializes a new instance of D2ConfigParser.
|
43
|
+
#
|
44
|
+
# @param config_path [String] The path to the configuration file.
|
29
45
|
def initialize(config_path)
|
30
46
|
@config_path = config_path
|
31
47
|
end
|
32
48
|
|
33
|
-
#
|
34
|
-
#
|
49
|
+
# Parses the configuration file and returns a D2Config object.
|
50
|
+
#
|
51
|
+
# @return [Distincter2::D2Config] A D2Config object representing the parsed configuration.
|
35
52
|
def parse
|
36
53
|
exclude_paths = []
|
37
54
|
version = 'v1'
|
55
|
+
|
56
|
+
# Open the configuration file and read its lines.
|
38
57
|
::File.open(@config_path, 'r') do |file|
|
39
58
|
file.readlines.each do |line|
|
40
59
|
l = line.strip
|
41
60
|
|
42
|
-
|
43
|
-
|
44
|
-
next if l.empty?
|
61
|
+
# Skip lines that contain the version number or are empty.
|
62
|
+
next if l == 'v1' || l.empty?
|
45
63
|
|
64
|
+
# Add the non-empty, non-version lines to the exclude_paths array.
|
46
65
|
exclude_paths << l
|
47
66
|
end
|
48
67
|
end
|
68
|
+
|
69
|
+
# Create a new D2Config object with the parsed exclude_paths and version.
|
49
70
|
::Distincter2::D2Config.new(exclude_paths, version)
|
50
71
|
end
|
51
|
-
# rubocop:enable Metrics/MethodLength
|
52
72
|
end
|
53
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
|