warning.d.ts 2.9 KB

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