File: Finding.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (110 lines) | stat: -rw-r--r-- 3,494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A problem with the style or syntax of the source code discovered during linting or formatting.
public struct Finding {
  /// The severity of a finding.
  public enum Severity {
    case warning
    case error
    case refactoring
    case convention
  }

  /// The file path and location in that file where a finding was encountered.
  public struct Location {
    /// The file path of the finding.
    public var file: String

    /// The 1-based line number of the finding.
    public var line: Int

    /// The 1-based column number of the finding.
    public var column: Int

    /// Creates a new finding with the given file path and 1-based line and column numbers.
    public init(file: String, line: Int, column: Int) {
      self.file = file
      self.line = line
      self.column = column
    }
  }

  /// A descriptive message about a finding.
  ///
  /// Finding messages are strongly typed so that they can act as an extensible namespace for
  /// messages defined by rules and other components of the formatter. To accomplish this, declare
  /// an `extension` of the `Finding.Message` type and add `static` properties or functions of type
  /// `Finding.Message`; these can be initialized using string literals or string interpolations.
  public struct Message:
    CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByStringInterpolation
  {
    /// The message text of the diagnostic.
    public var text: String

    public var description: String { text }

    public init(stringLiteral string: String) {
      self.text = string
    }

    public init(stringInterpolation: DefaultStringInterpolation) {
      self.text = String(describing: stringInterpolation)
    }
  }

  /// A note associating additional detail with a finding.
  public struct Note {
    /// The note's message.
    public var message: Message

    /// The optional location of the note, if different from the location of the finding.
    public var location: Location?

    /// Creates a new note with the given message and location.
    public init(message: Message, location: Location? = nil) {
      self.message = message
      self.location = location
    }
  }

  /// The category associated with the finding.
  public let category: FindingCategorizing

  /// The finding's message.
  public let message: Message

  /// The severity of the finding.
  public let severity: Severity

  /// The optional location of the finding.
  public let location: Location?

  /// Notes that provide additional detail about the finding.
  public let notes: [Note]

  /// Creates a new finding with the given category, message, severity, optional location, and
  /// notes.
  init(
    category: FindingCategorizing,
    message: Message,
    severity: Finding.Severity,
    location: Location? = nil,
    notes: [Note] = []
  ) {
    self.category = category
    self.message = message
    self.severity = severity
    self.location = location
    self.notes = notes
  }
}