distincter2 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b8d1d5aa62302ef718c566a9053311075f4999fc1e8509c1e2d93e788f85a87
4
- data.tar.gz: 66ebec72784df7a866f179c730f354120db1e227911655a8ee11ce509947adb5
3
+ metadata.gz: 0a6cd807f2f889320a66b76f7f787b1caac82139d48026c9840966e36a06a20a
4
+ data.tar.gz: 4240110004fb807cad542c872e03b952fbcbbc2c09b8d98295703e3074ff5148
5
5
  SHA512:
6
- metadata.gz: 81680f8b162f0851527be19be9a8018ebf34a9a613aab8f7451a9035ba3e8b1146303054810dff9724638ab3bd871965e27a2c030949c85804a2a477e0e6f4f4
7
- data.tar.gz: 9c5898feafe48a5111c47bdbe99907c2b36eba081ffcc2d89f9e70cdaa9cbc542828f76f10cf6f64ba7d7dc68acb6a44a9793f2f4b0e324b11277b7e4c25fa1d
6
+ metadata.gz: c0869afab0fbe87c5cb6daa71aa6dd6c8ca0b123e86623031acbe857ddebad38dfe8b143e08b406e88f4ae81e72963b34153be216f40121f2fc53af2fb92ad9f
7
+ data.tar.gz: 133222727ec67744206a168e09aa52cbbea1a25fd8dfc36f3ae502000c04145dec2545271d4f95b244045c4fccc908641b1f07afd95b3d0a6340b4ef808119bd
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Artem Fomchenkov
3
+ Copyright (c) 2023-2025 Artem Fomchenkov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -10,22 +10,20 @@ A tool that can check lists in Markdown files and find duplicates.
10
10
 
11
11
  ## How to use
12
12
 
13
- ### Global installation
13
+ You need to install `distincter2` from [RubyGems](https://rubygems.org/gems/distincter2) by next command:
14
14
 
15
15
  ```shell
16
16
  $ gem i distincter2
17
- $ distincter2 ./path_to_directory_with_markdown_files
18
17
  ```
19
-
20
- ### Local installation
18
+ After that, run `distincter2` from any place with a path to your markdown files as parameter:
21
19
 
22
20
  ```shell
23
- $ ./bin/local_distincter2 ./path_to_directory_with_markdown_files
21
+ $ distincter2 ./path_to_directory_with_markdown_files
24
22
  ```
25
23
 
26
24
  ### Config
27
25
 
28
- Add `distincter2_config.d2c` to root of your project and add excluded files line by line. Below you can find examples.
26
+ Add `.d2_config.d2c` to root of your project and add excluded files line by line. Below you can find examples.
29
27
 
30
28
  #### v1
31
29
 
@@ -47,6 +45,25 @@ BOOKS.md
47
45
  DONE.md
48
46
  ```
49
47
 
48
+ ## Documentation
49
+
50
+ You can generate documentation locally by next command from root of the project:
51
+
52
+ ```shell
53
+ $ rdoc
54
+ ```
55
+
56
+ ## How to contribute
57
+
58
+ Read [Commit Convention](./COMMIT_CONVENTION.md). Make sure your build is green before you contribute your pull request.
59
+ Then:
60
+
61
+ ```shell
62
+ $ bundle exec rake
63
+ ```
64
+
65
+ If you don't see any error messages, submit your pull request.
66
+
50
67
  ## Contributors
51
68
 
52
69
  * [@fartem](https://github.com/fartem) as Artem Fomchenkov
@@ -1,26 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Distincter2
4
- # distincter2 checker.
5
- # Handles a file and operate them.
4
+ # Class to check for duplicate lines in markdown files
6
5
  class D2Checker
7
- # @param {D2Config} config
8
- # @param {Boolean} mute
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
- # @param {String} path
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
- # @param {String} path
22
- # @return {String[]}
23
- # rubocop:disable Metrics/MethodLength
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
- # rubocop:enable Metrics/MethodLength
49
-
50
- # @param {String} entry
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
- # @param {String} path
58
- # @return {String[]}
59
- # rubocop:disable Metrics/MethodLength
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
@@ -3,51 +3,71 @@
3
3
  require 'set'
4
4
 
5
5
  module Distincter2
6
- # Distincter2 config.
6
+ # Class representing the configuration for Distincter2.
7
7
  class D2Config
8
- # @param {String[]} exclude_paths
9
- # @param {String} version
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
- attr_accessor :exclude_paths, :version
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
- # D2Config with empty arguments.
19
- class D2ConfigEmpty < ::Distincter2::D2Config
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
- # D2Config parser.
40
+ # Class representing a parser for Distincter2 configuration files.
27
41
  class D2ConfigParser
28
- # @param {String} config_path
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
- # @return {D2Config}
34
- # rubocop:disable Metrics/MethodLength
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
- next if l == 'v1'
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,43 @@ 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
- # You need a project path to run validation.
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)
12
- config_path = "#{path}/distincter2_config.d2c"
22
+ # Construct the path to the .d2_config.d2c file
23
+ new_config_path = "#{path}/.d2_config.d2c"
24
+ old_config_path =
25
+ if ::File.exist?(new_config_path)
26
+ nil
27
+ else
28
+ "#{path}/distincter2_config.d2c"
29
+ end
30
+
31
+ config_path = old_config_path.nil? ? new_config_path : old_config_path
32
+
33
+ # Create a new D2Checker instance with the appropriate configuration
13
34
  checker = ::Distincter2::D2Checker.new(
14
35
  if ::File.exist?(config_path)
36
+ # If the config file exists, parse it and use the parsed configuration
15
37
  ::Distincter2::D2ConfigParser.new(config_path).parse
16
38
  else
17
- ::Distincter2::D2ConfigEmpty.new
39
+ # If the config file does not exist, use an empty configuration
40
+ ::Distincter2::D2EmptyConfig.new
18
41
  end
19
42
  )
43
+
44
+ # Run the validation process using the checker
20
45
  checker.check(path)
21
46
  end
22
47
  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.1
4
+ version: 1.4.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-09-14 00:00:00.000000000 Z
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.4.10
117
+ rubygems_version: 3.5.23
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: A tool that can check lists in Markdown files and find duplicates