Module: GraphQL::Doctor::Suppression
- Defined in:
- lib/graphql/doctor/suppression.rb
Constant Summary collapse
- PATTERN =
Regexp.new( "\\A#\\s*graphql-doctor:disable(?<file>-file)?\\s+(?<codes>GQLD\\d+(?:[\\s,]+GQLD\\d+)*)" \ "(?:\\s*(?:--|:)\\s*(?<reason>\\S.*))?\\s*\\z" )
Class Method Summary collapse
- .filter(diagnostics, comments, require_reason: false) ⇒ Object
- .rule(comment, require_reason) ⇒ Object
Class Method Details
.filter(diagnostics, comments, require_reason: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphql/doctor/suppression.rb', line 13 def filter(diagnostics, comments, require_reason: false) rules = comments.filter_map { |comment| rule(comment, require_reason) } diagnostics.reject do |diagnostic| rules.any? do |candidate| candidate[:path] == diagnostic.location.path && candidate[:codes].include?(diagnostic.code) && (candidate[:file] || candidate[:line] == diagnostic.location.start_line) end end end |
.rule(comment, require_reason) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/graphql/doctor/suppression.rb', line 24 def rule(comment, require_reason) match = PATTERN.match(comment.text) return unless match return if match[:file] && comment.location.start_line != 1 return if require_reason && match[:reason].to_s.empty? { file: !match[:file].nil?, codes: match[:codes].scan(/GQLD\d+/), path: comment.location.path, line: comment.location.start_line } end |