You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
2.7 KiB

2 years ago
  1. import { RangePosition } from './css-syntax-error.js'
  2. import Node from './node.js'
  3. export interface WarningOptions {
  4. /**
  5. * CSS node that caused the warning.
  6. */
  7. node?: Node
  8. /**
  9. * Word in CSS source that caused the warning.
  10. */
  11. word?: string
  12. /**
  13. * Start index, inclusive, in CSS node string that caused the warning.
  14. */
  15. index?: number
  16. /**
  17. * End index, exclusive, in CSS node string that caused the warning.
  18. */
  19. endIndex?: number
  20. /**
  21. * Start position, inclusive, in CSS node string that caused the warning.
  22. */
  23. start?: RangePosition
  24. /**
  25. * End position, exclusive, in CSS node string that caused the warning.
  26. */
  27. end?: RangePosition
  28. /**
  29. * Name of the plugin that created this warning. `Result#warn` fills
  30. * this property automatically.
  31. */
  32. plugin?: string
  33. }
  34. /**
  35. * Represents a plugins warning. It can be created using `Node#warn`.
  36. *
  37. * ```js
  38. * if (decl.important) {
  39. * decl.warn(result, 'Avoid !important', { word: '!important' })
  40. * }
  41. * ```
  42. */
  43. export default class Warning {
  44. /**
  45. * Type to filter warnings from `Result#messages`.
  46. * Always equal to `"warning"`.
  47. */
  48. type: 'warning'
  49. /**
  50. * The warning message.
  51. *
  52. * ```js
  53. * warning.text //=> 'Try to avoid !important'
  54. * ```
  55. */
  56. text: string
  57. /**
  58. * The name of the plugin that created this warning.
  59. * When you call `Node#warn` it will fill this property automatically.
  60. *
  61. * ```js
  62. * warning.plugin //=> 'postcss-important'
  63. * ```
  64. */
  65. plugin: string
  66. /**
  67. * Contains the CSS node that caused the warning.
  68. *
  69. * ```js
  70. * warning.node.toString() //=> 'color: white !important'
  71. * ```
  72. */
  73. node: Node
  74. /**
  75. * Line for inclusive start position in the input file with this warnings source.
  76. *
  77. * ```js
  78. * warning.line //=> 5
  79. * ```
  80. */
  81. line: number
  82. /**
  83. * Column for inclusive start position in the input file with this warnings source.
  84. *
  85. * ```js
  86. * warning.column //=> 6
  87. * ```
  88. */
  89. column: number
  90. /**
  91. * Line for exclusive end position in the input file with this warnings source.
  92. *
  93. * ```js
  94. * warning.endLine //=> 6
  95. * ```
  96. */
  97. endLine?: number
  98. /**
  99. * Column for exclusive end position in the input file with this warnings source.
  100. *
  101. * ```js
  102. * warning.endColumn //=> 4
  103. * ```
  104. */
  105. endColumn?: number
  106. /**
  107. * @param text Warning message.
  108. * @param opts Warning options.
  109. */
  110. constructor(text: string, opts?: WarningOptions)
  111. /**
  112. * Returns a warning position and message.
  113. *
  114. * ```js
  115. * warning.toString() //=> 'postcss-lint:a.css:10:14: Avoid !important'
  116. * ```
  117. *
  118. * @return Warning position and message.
  119. */
  120. toString(): string
  121. }