yard-lint 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.coditsu/ci.yml +3 -0
  3. data/CHANGELOG.md +28 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +454 -0
  6. data/bin/console +11 -0
  7. data/bin/setup +8 -0
  8. data/bin/yard-lint +109 -0
  9. data/lib/yard/lint/command_cache.rb +77 -0
  10. data/lib/yard/lint/config.rb +255 -0
  11. data/lib/yard/lint/config_loader.rb +198 -0
  12. data/lib/yard/lint/errors.rb +17 -0
  13. data/lib/yard/lint/formatters/progress.rb +50 -0
  14. data/lib/yard/lint/parsers/base.rb +23 -0
  15. data/lib/yard/lint/parsers/one_line_base.rb +35 -0
  16. data/lib/yard/lint/parsers/two_line_base.rb +45 -0
  17. data/lib/yard/lint/result_builder.rb +130 -0
  18. data/lib/yard/lint/results/aggregate.rb +86 -0
  19. data/lib/yard/lint/results/base.rb +156 -0
  20. data/lib/yard/lint/runner.rb +125 -0
  21. data/lib/yard/lint/validators/base.rb +120 -0
  22. data/lib/yard/lint/validators/config.rb +30 -0
  23. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/config.rb +20 -0
  24. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/parser.rb +43 -0
  25. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/result.rb +26 -0
  26. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/validator.rb +48 -0
  27. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods.rb +13 -0
  28. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/config.rb +20 -0
  29. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/messages_builder.rb +24 -0
  30. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/parser.rb +45 -0
  31. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/result.rb +25 -0
  32. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/validator.rb +55 -0
  33. data/lib/yard/lint/validators/documentation/undocumented_method_arguments.rb +13 -0
  34. data/lib/yard/lint/validators/documentation/undocumented_objects/config.rb +21 -0
  35. data/lib/yard/lint/validators/documentation/undocumented_objects/messages_builder.rb +23 -0
  36. data/lib/yard/lint/validators/documentation/undocumented_objects/parser.rb +39 -0
  37. data/lib/yard/lint/validators/documentation/undocumented_objects/result.rb +25 -0
  38. data/lib/yard/lint/validators/documentation/undocumented_objects/validator.rb +39 -0
  39. data/lib/yard/lint/validators/documentation/undocumented_objects.rb +14 -0
  40. data/lib/yard/lint/validators/semantic/abstract_methods/config.rb +24 -0
  41. data/lib/yard/lint/validators/semantic/abstract_methods/messages_builder.rb +25 -0
  42. data/lib/yard/lint/validators/semantic/abstract_methods/parser.rb +45 -0
  43. data/lib/yard/lint/validators/semantic/abstract_methods/result.rb +42 -0
  44. data/lib/yard/lint/validators/semantic/abstract_methods/validator.rb +65 -0
  45. data/lib/yard/lint/validators/semantic/abstract_methods.rb +13 -0
  46. data/lib/yard/lint/validators/tags/api_tags/config.rb +21 -0
  47. data/lib/yard/lint/validators/tags/api_tags/messages_builder.rb +29 -0
  48. data/lib/yard/lint/validators/tags/api_tags/parser.rb +50 -0
  49. data/lib/yard/lint/validators/tags/api_tags/result.rb +42 -0
  50. data/lib/yard/lint/validators/tags/api_tags/validator.rb +69 -0
  51. data/lib/yard/lint/validators/tags/api_tags.rb +13 -0
  52. data/lib/yard/lint/validators/tags/invalid_types/config.rb +22 -0
  53. data/lib/yard/lint/validators/tags/invalid_types/messages_builder.rb +24 -0
  54. data/lib/yard/lint/validators/tags/invalid_types/parser.rb +16 -0
  55. data/lib/yard/lint/validators/tags/invalid_types/result.rb +25 -0
  56. data/lib/yard/lint/validators/tags/invalid_types/validator.rb +106 -0
  57. data/lib/yard/lint/validators/tags/invalid_types.rb +13 -0
  58. data/lib/yard/lint/validators/tags/option_tags/config.rb +21 -0
  59. data/lib/yard/lint/validators/tags/option_tags/messages_builder.rb +24 -0
  60. data/lib/yard/lint/validators/tags/option_tags/parser.rb +45 -0
  61. data/lib/yard/lint/validators/tags/option_tags/result.rb +42 -0
  62. data/lib/yard/lint/validators/tags/option_tags/validator.rb +61 -0
  63. data/lib/yard/lint/validators/tags/option_tags.rb +13 -0
  64. data/lib/yard/lint/validators/tags/order/config.rb +33 -0
  65. data/lib/yard/lint/validators/tags/order/messages_builder.rb +30 -0
  66. data/lib/yard/lint/validators/tags/order/parser.rb +66 -0
  67. data/lib/yard/lint/validators/tags/order/result.rb +26 -0
  68. data/lib/yard/lint/validators/tags/order/validator.rb +89 -0
  69. data/lib/yard/lint/validators/tags/order.rb +13 -0
  70. data/lib/yard/lint/validators/warnings/duplicated_parameter_name/config.rb +22 -0
  71. data/lib/yard/lint/validators/warnings/duplicated_parameter_name/parser.rb +22 -0
  72. data/lib/yard/lint/validators/warnings/duplicated_parameter_name/result.rb +25 -0
  73. data/lib/yard/lint/validators/warnings/duplicated_parameter_name/validator.rb +33 -0
  74. data/lib/yard/lint/validators/warnings/duplicated_parameter_name.rb +14 -0
  75. data/lib/yard/lint/validators/warnings/invalid_directive_format/config.rb +22 -0
  76. data/lib/yard/lint/validators/warnings/invalid_directive_format/parser.rb +22 -0
  77. data/lib/yard/lint/validators/warnings/invalid_directive_format/result.rb +25 -0
  78. data/lib/yard/lint/validators/warnings/invalid_directive_format/validator.rb +33 -0
  79. data/lib/yard/lint/validators/warnings/invalid_directive_format.rb +14 -0
  80. data/lib/yard/lint/validators/warnings/invalid_tag_format/config.rb +22 -0
  81. data/lib/yard/lint/validators/warnings/invalid_tag_format/parser.rb +22 -0
  82. data/lib/yard/lint/validators/warnings/invalid_tag_format/result.rb +25 -0
  83. data/lib/yard/lint/validators/warnings/invalid_tag_format/validator.rb +33 -0
  84. data/lib/yard/lint/validators/warnings/invalid_tag_format.rb +14 -0
  85. data/lib/yard/lint/validators/warnings/unknown_directive/config.rb +22 -0
  86. data/lib/yard/lint/validators/warnings/unknown_directive/parser.rb +22 -0
  87. data/lib/yard/lint/validators/warnings/unknown_directive/result.rb +25 -0
  88. data/lib/yard/lint/validators/warnings/unknown_directive/validator.rb +33 -0
  89. data/lib/yard/lint/validators/warnings/unknown_directive.rb +14 -0
  90. data/lib/yard/lint/validators/warnings/unknown_parameter_name/config.rb +22 -0
  91. data/lib/yard/lint/validators/warnings/unknown_parameter_name/parser.rb +22 -0
  92. data/lib/yard/lint/validators/warnings/unknown_parameter_name/result.rb +25 -0
  93. data/lib/yard/lint/validators/warnings/unknown_parameter_name/validator.rb +33 -0
  94. data/lib/yard/lint/validators/warnings/unknown_parameter_name.rb +14 -0
  95. data/lib/yard/lint/validators/warnings/unknown_tag/config.rb +22 -0
  96. data/lib/yard/lint/validators/warnings/unknown_tag/parser.rb +24 -0
  97. data/lib/yard/lint/validators/warnings/unknown_tag/result.rb +25 -0
  98. data/lib/yard/lint/validators/warnings/unknown_tag/validator.rb +33 -0
  99. data/lib/yard/lint/validators/warnings/unknown_tag.rb +14 -0
  100. data/lib/yard/lint/version.rb +8 -0
  101. data/lib/yard/lint.rb +76 -0
  102. data/lib/yard-lint.rb +11 -0
  103. data/renovate.json +22 -0
  104. metadata +178 -0
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ module OptionTags
8
+ # Validator to check methods with options hash have @option tags
9
+ class Validator < Base
10
+ private
11
+
12
+ # Runs yard list query to find methods with options parameter but missing @option tags
13
+ # @param dir [String] dir where the yard db is (or where it should be generated)
14
+ # @param escaped_file_names [String] files for which we want to get the stats
15
+ # @return [Hash] shell command execution hash results
16
+ def yard_cmd(dir, escaped_file_names)
17
+ cmd = <<~CMD
18
+ yard list \
19
+ --private \
20
+ --protected \
21
+ -b #{Shellwords.escape(dir)} \
22
+ #{escaped_file_names}
23
+ CMD
24
+ cmd = cmd.tr("\n", ' ')
25
+ cmd = cmd.gsub('yard list', "yard list --query #{query}")
26
+
27
+ shell(cmd)
28
+ end
29
+
30
+ # @return [String] yard query to find methods with options parameter
31
+ # but no @option tags
32
+ def query
33
+ <<~QUERY
34
+ '
35
+ if object.is_a?(YARD::CodeObjects::MethodObject)
36
+ # Check if method has a parameter named "options" or "opts"
37
+ has_options_param = object.parameters.any? do |param|
38
+ param_name = param[0].to_s.gsub(/[*:]/, '')
39
+ ['options', 'opts', 'kwargs'].include?(param_name)
40
+ end
41
+
42
+ if has_options_param
43
+ # Check if method has any @option tags
44
+ option_tags = object.tags(:option)
45
+
46
+ if option_tags.empty?
47
+ puts object.file + ':' + object.line.to_s + ': ' + object.title
48
+ puts 'missing_option_tags'
49
+ end
50
+ end
51
+ end
52
+ false
53
+ '
54
+ QUERY
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ # OptionTags validator module
8
+ module OptionTags
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ module Order
8
+ # Configuration for Order validator
9
+ class Config < ::Yard::Lint::Validators::Config
10
+ self.id = :order
11
+ self.defaults = {
12
+ 'Enabled' => true,
13
+ 'Severity' => 'convention',
14
+ 'EnforcedOrder' => %w[
15
+ param
16
+ option
17
+ yield
18
+ yieldparam
19
+ yieldreturn
20
+ return
21
+ raise
22
+ see
23
+ example
24
+ note
25
+ todo
26
+ ]
27
+ }.freeze
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ module Order
8
+ # Builds messages for invalid tag order offenses
9
+ class MessagesBuilder
10
+ class << self
11
+ # Build message for invalid tag order
12
+ # @param offense [Hash] offense data with :method_name and :order keys
13
+ # @return [String] formatted message
14
+ def call(offense)
15
+ expected_order = offense[:order]
16
+ .to_s
17
+ .split(',')
18
+ .map { |tag| "`#{tag}`" }
19
+ .join(', ')
20
+
21
+ "The `#{offense[:method_name]}` has yard tags in an invalid order. " \
22
+ "Following tags need to be in the presented order: #{expected_order}."
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ module Order
8
+ # Class used to extract warnings details that are related to yard invalid tags order
9
+ class Parser < Parsers::Base
10
+ # Regexp to extract only word and numeric parts of the location line
11
+ NORMALIZATION_REGEXP = /\w+/
12
+
13
+ private_constant :NORMALIZATION_REGEXP
14
+
15
+ # @param yard_list [Hash] hash with :result key containing raw yard list results string
16
+ # and :tags_order key with expected tags order
17
+ # @return [Array<Hash>] hashes with details about objects with docs with invalid tags
18
+ # order.
19
+ def call(yard_list)
20
+ # Return empty array if yard_list is nil or empty
21
+ return [] if yard_list.nil? || yard_list.empty?
22
+ return [] if yard_list[:result].nil? || yard_list[:result].empty?
23
+
24
+ # Each raw offense result is combined out of two lines:
25
+ # - first line contains the issue location
26
+ # - second the order in which the tags should be
27
+ # That's why we split it and then for building the locations hashes we can use the
28
+ # UndocumentedMethodArguments parser as the location format is the same for both
29
+ # raw inputs
30
+ base_hash = {}
31
+
32
+ yard_list[:result].split("\n").each_slice(2).each do |location, ordering|
33
+ key = normalize(location)
34
+
35
+ if ordering == 'valid'
36
+ base_hash[key] = 'valid'
37
+ else
38
+ base_hash[key] ||= [location, ordering]
39
+ end
40
+ end
41
+
42
+ base_hash.delete_if { |_key, value| value == 'valid' }
43
+ order = base_hash.values.map(&:last)
44
+
45
+ Validators::Documentation::UndocumentedMethodArguments::Parser
46
+ .new
47
+ .call(base_hash.values.map(&:first).join("\n"))
48
+ .each.with_index { |element, index| element[:order] = order[index] }
49
+ end
50
+
51
+ private
52
+
53
+ # @param location_line [String] full line with the location. It can be used, when we
54
+ # use module_function or other aliases that alter the yard tags order
55
+ # @return [String] line without special characters
56
+ def normalize(location_line)
57
+ location_line
58
+ .scan(NORMALIZATION_REGEXP)
59
+ .join
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ module Order
8
+ # Result object for tag order validation
9
+ # Transforms parsed tag order violations into offense objects
10
+ class Result < Results::Base
11
+ self.default_severity = 'convention'
12
+ self.offense_type = 'method'
13
+ self.offense_name = 'InvalidTagOrder'
14
+
15
+ # Build human-readable message for tag order offense
16
+ # @param offense [Hash] offense data with :method_name and :order keys
17
+ # @return [String] formatted message
18
+ def build_message(offense)
19
+ MessagesBuilder.call(offense)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ module Order
8
+ # Runs a query that will pick all the objects that have docs with tags in an invalid
9
+ # order. By invalid we mean, that they are not as defined in the settings.
10
+ class Validator < Base
11
+ private
12
+
13
+ # Runs yard list query with proper settings on a given dir and files
14
+ # @param dir [String] dir where the yard db is (or where it should be generated)
15
+ # @param escaped_file_names [String] files for which we want to get the stats
16
+ # @return [Hash] shell command execution hash results
17
+ def yard_cmd(dir, escaped_file_names)
18
+ cmd = <<~CMD
19
+ yard list \
20
+ --private \
21
+ --protected \
22
+ --query #{query} \
23
+ -b #{Shellwords.escape(dir)} \
24
+ #{escaped_file_names}
25
+ CMD
26
+
27
+ result = shell(cmd)
28
+ result[:stdout] = { result: result[:stdout], tags_order: tags_order }
29
+ result
30
+ end
31
+
32
+ # @return [String] multiline yard query that we use to find methods with
33
+ # tags that are not in the valid order
34
+ # @note We need to print things for all of the elements as some of them
35
+ # are listed in yard twice (for example module functions), and for the
36
+ # second time, yard injects things by itself making it impossible to
37
+ # figure out whether the order is ok or now. That's why we print all and those
38
+ # that are ok, we mark with 'valid' and if it is reported later as invalid again,
39
+ # we know, that it is valid
40
+ def query
41
+ <<-QUERY
42
+ '
43
+ tags_order = #{query_array(tags_order)}
44
+ accu = []
45
+ str = "@"
46
+ slash = 92.chr
47
+ regexp = "^"+str+"("+slash+"S+)"
48
+ doc_tags = object.docstring.all.scan(Regexp.new(regexp)).flatten
49
+
50
+ doc_tags.each do |param|
51
+ accu << param unless accu.last == param
52
+ end
53
+
54
+ tags_order.delete_if { |el| !accu.include?(el) }
55
+ accu.delete_if { |el| !tags_order.include?(el) }
56
+
57
+ tags_orders = tags_order.join.to_i(36)
58
+ accus = accu.join.to_i(36)
59
+
60
+ puts object.file + ":" + object.line.to_s + ": " + object.title
61
+
62
+ if accus != tags_orders && !is_alias?
63
+ puts tags_order.join(",")
64
+ else
65
+ puts "valid"
66
+ end
67
+
68
+ false
69
+ ' \\
70
+ QUERY
71
+ end
72
+
73
+ # @return [Array<String>] tags order
74
+ def tags_order
75
+ config.validator_config('Tags/Order', 'EnforcedOrder')
76
+ end
77
+
78
+ # @param elements [Array<String>] array of elements that we want to convert into
79
+ # a string ruby yard query array form
80
+ # @return [String] array of elements for yard query converted into a string
81
+ def query_array(elements)
82
+ "[#{elements.map { |type| "\"#{type}\"" }.join(',')}]"
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Tags
7
+ # Order validator module
8
+ module Order
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ # Validators for checking YARD warnings
7
+ module Warnings
8
+ # Validator for detecting duplicated parameter names in @param tags
9
+ module DuplicatedParameterName
10
+ # Configuration for DuplicatedParameterName validator
11
+ class Config < ::Yard::Lint::Validators::Config
12
+ self.id = :duplicated_parameter_name
13
+ self.defaults = {
14
+ 'Enabled' => true,
15
+ 'Severity' => 'error'
16
+ }.freeze
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module DuplicatedParameterName
8
+ # Parser for DuplicatedParameterName warnings
9
+ class Parser < ::Yard::Lint::Parsers::OneLineBase
10
+ # Set of regexps for detecting warnings reported by YARD stats
11
+ self.regexps = {
12
+ general: /^\[warn\]: @param tag has duplicate parameter name/,
13
+ message: /\[warn\]: (.*) in file/,
14
+ location: /in file `(.*)`/,
15
+ line: /line (\d*)/
16
+ }.freeze
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module DuplicatedParameterName
8
+ # Result object for DuplicatedParameterName validation
9
+ class Result < Results::Base
10
+ self.default_severity = 'error'
11
+ self.offense_type = 'line'
12
+ self.offense_name = 'DuplicatedParameterName'
13
+
14
+ # Build human-readable message for DuplicatedParameterName offense
15
+ # @param offense [Hash] offense data with :message key
16
+ # @return [String] formatted message
17
+ def build_message(offense)
18
+ offense[:message] || 'DuplicatedParameterName detected'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module DuplicatedParameterName
8
+ # Runs YARD stats command to check for duplicatedparametername
9
+ class Validator < Base
10
+ private
11
+
12
+ # Runs YARD stats command with proper settings on a given dir and files
13
+ # @param dir [String] dir where we should generate the temp docs
14
+ # @param escaped_file_names [String] files for which we want to run YARD stats
15
+ # @return [Hash] shell command execution hash results
16
+ def yard_cmd(dir, escaped_file_names)
17
+ cmd = <<~CMD
18
+ yard stats \
19
+ #{shell_arguments} \
20
+ --compact \
21
+ -b #{Shellwords.escape(dir)} \
22
+ #{escaped_file_names}
23
+ CMD
24
+ cmd = cmd.tr("\n", ' ')
25
+
26
+ shell(cmd)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ # Validators for checking YARD warnings
7
+ module Warnings
8
+ # DuplicatedParameterName validator module
9
+ module DuplicatedParameterName
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ # Validators for checking YARD warnings
7
+ module Warnings
8
+ # Validator for detecting invalid directive formats
9
+ module InvalidDirectiveFormat
10
+ # Configuration for InvalidDirectiveFormat validator
11
+ class Config < ::Yard::Lint::Validators::Config
12
+ self.id = :invalid_directive_format
13
+ self.defaults = {
14
+ 'Enabled' => true,
15
+ 'Severity' => 'error'
16
+ }.freeze
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module InvalidDirectiveFormat
8
+ # Parser for InvalidDirectiveFormat warnings
9
+ class Parser < ::Yard::Lint::Parsers::OneLineBase
10
+ # Set of regexps for detecting warnings reported by YARD stats
11
+ self.regexps = {
12
+ general: /^\[warn\]: Invalid directive format/,
13
+ message: /\[warn\]: (.*) in file/,
14
+ location: /in file `(.*)`/,
15
+ line: /line (\d*)/
16
+ }.freeze
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module InvalidDirectiveFormat
8
+ # Result object for InvalidDirectiveFormat validation
9
+ class Result < Results::Base
10
+ self.default_severity = 'error'
11
+ self.offense_type = 'line'
12
+ self.offense_name = 'InvalidDirectiveFormat'
13
+
14
+ # Build human-readable message for InvalidDirectiveFormat offense
15
+ # @param offense [Hash] offense data with :message key
16
+ # @return [String] formatted message
17
+ def build_message(offense)
18
+ offense[:message] || 'InvalidDirectiveFormat detected'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module InvalidDirectiveFormat
8
+ # Runs YARD stats command to check for invaliddirectiveformat
9
+ class Validator < Base
10
+ private
11
+
12
+ # Runs YARD stats command with proper settings on a given dir and files
13
+ # @param dir [String] dir where we should generate the temp docs
14
+ # @param escaped_file_names [String] files for which we want to run YARD stats
15
+ # @return [Hash] shell command execution hash results
16
+ def yard_cmd(dir, escaped_file_names)
17
+ cmd = <<~CMD
18
+ yard stats \
19
+ #{shell_arguments} \
20
+ --compact \
21
+ -b #{Shellwords.escape(dir)} \
22
+ #{escaped_file_names}
23
+ CMD
24
+ cmd = cmd.tr("\n", ' ')
25
+
26
+ shell(cmd)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ # Validators for checking YARD warnings
7
+ module Warnings
8
+ # InvalidDirectiveFormat validator module
9
+ module InvalidDirectiveFormat
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ # Validators for checking YARD warnings
7
+ module Warnings
8
+ # Validator for detecting invalid tag formats
9
+ module InvalidTagFormat
10
+ # Configuration for InvalidTagFormat validator
11
+ class Config < ::Yard::Lint::Validators::Config
12
+ self.id = :invalid_tag_format
13
+ self.defaults = {
14
+ 'Enabled' => true,
15
+ 'Severity' => 'error'
16
+ }.freeze
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module InvalidTagFormat
8
+ # Parser for InvalidTagFormat warnings
9
+ class Parser < ::Yard::Lint::Parsers::OneLineBase
10
+ # Set of regexps for detecting warnings reported by YARD stats
11
+ self.regexps = {
12
+ general: /^\[warn\]: Invalid tag format/,
13
+ message: /\[warn\]: (.*) in file/,
14
+ location: /in file `(.*)`/,
15
+ line: /line (\d*)/
16
+ }.freeze
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ module Validators
6
+ module Warnings
7
+ module InvalidTagFormat
8
+ # Result object for InvalidTagFormat validation
9
+ class Result < Results::Base
10
+ self.default_severity = 'error'
11
+ self.offense_type = 'line'
12
+ self.offense_name = 'InvalidTagFormat'
13
+
14
+ # Build human-readable message for InvalidTagFormat offense
15
+ # @param offense [Hash] offense data with :message key
16
+ # @return [String] formatted message
17
+ def build_message(offense)
18
+ offense[:message] || 'InvalidTagFormat detected'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end