Module: TypeSpecFromSerializers::Linting
Overview
Internal: Linting methods for TypeSpec generation
Instance Method Summary collapse
-
#ambiguous_operations(name_counts, operations, config) ⇒ Object
Internal: Lints for duplicate action names.
-
#missing_documentation(controller, route, doc, config) ⇒ Object
Internal: Lints for missing documentation.
-
#missing_param_types(controller, route, path_param_names, param_types, config) ⇒ Object
Internal: Lints for missing parameter types.
- #print_summary ⇒ Object
- #reset_count ⇒ Object
-
#type_inference_failure(property, explicit_type, serializer_name, config) ⇒ Object
Internal: Lints for type inference failures.
-
#unknown_response_type(controller, route, response_type, config) ⇒ Object
Internal: Lints for unknown response types.
- #warning_count ⇒ Object
Instance Method Details
#ambiguous_operations(name_counts, operations, config) ⇒ Object
Internal: Lints for duplicate action names
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/typespec_from_serializers/generator.rb', line 84 def ambiguous_operations(name_counts, operations, config) return unless enabled?(config.linting, :ambiguous_operations) duplicates = name_counts.select { |_, count| count > 1 } duplicates.each do |action, count| @warning_count += 1 ops = operations.select { |op| op.action == action } methods = ops.map { |op| op.method }.join(', ') warn "TypeSpec Lint: Action '#{action}' used for multiple routes (#{methods}). Using method suffix to differentiate." end end |
#missing_documentation(controller, route, doc, config) ⇒ Object
Internal: Lints for missing documentation
73 74 75 76 77 78 79 80 81 |
# File 'lib/typespec_from_serializers/generator.rb', line 73 def missing_documentation(controller, route, doc, config) return unless enabled?(config.linting, :missing_documentation) && config.extract_docs if doc.nil? @warning_count += 1 location = "#{controller.camelize}#{config.controller_suffix}##{route[:action]}" warn "TypeSpec Lint: Missing documentation for #{location} (#{route[:method]} #{route[:path]}). Consider adding an RDoc comment." end end |
#missing_param_types(controller, route, path_param_names, param_types, config) ⇒ Object
Internal: Lints for missing parameter types
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/typespec_from_serializers/generator.rb', line 49 def missing_param_types(controller, route, path_param_names, param_types, config) return unless enabled?(config.linting, :missing_param_types) missing_path_params = path_param_names.select { |name| !param_types.key?(name) } unless missing_path_params.empty? @warning_count += 1 location = "#{controller.camelize}#{config.controller_suffix}##{route[:action]}" warn "TypeSpec Lint: Missing type for path parameter(s) #{missing_path_params.join(', ')} in #{location} (#{route[:method]} #{route[:path]}). Defaulting to 'string'." end end |
#print_summary ⇒ Object
43 44 45 46 |
# File 'lib/typespec_from_serializers/generator.rb', line 43 def print_summary return if @warning_count == 0 puts "\nTypeSpec generation completed with #{@warning_count} lint warning#{'s' unless @warning_count == 1}" end |
#reset_count ⇒ Object
35 36 37 |
# File 'lib/typespec_from_serializers/generator.rb', line 35 def reset_count @warning_count = 0 end |
#type_inference_failure(property, explicit_type, serializer_name, config) ⇒ Object
Internal: Lints for type inference failures
97 98 99 100 101 102 103 104 |
# File 'lib/typespec_from_serializers/generator.rb', line 97 def type_inference_failure(property, explicit_type, serializer_name, config) return unless enabled?(config.linting, :type_inference_failures) if property.type.nil? && explicit_type.nil? @warning_count += 1 warn "TypeSpec Lint: Could not infer type for '#{property.name}' in #{serializer_name}. Consider adding explicit type annotation." end end |
#unknown_response_type(controller, route, response_type, config) ⇒ Object
Internal: Lints for unknown response types
62 63 64 65 66 67 68 69 70 |
# File 'lib/typespec_from_serializers/generator.rb', line 62 def unknown_response_type(controller, route, response_type, config) return unless enabled?(config.linting, :unknown_response_types) if response_type == "unknown" @warning_count += 1 location = "#{controller.camelize}#{config.controller_suffix}##{route[:action]}" warn "TypeSpec Lint: Unknown response type for #{location} (#{route[:method]} #{route[:path]}). Consider adding a serializer or explicit type annotation." end end |
#warning_count ⇒ Object
39 40 41 |
# File 'lib/typespec_from_serializers/generator.rb', line 39 def warning_count @warning_count end |