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. * End position, exclusive, in CSS node string that caused the warning.
  7. */
  8. end?: RangePosition
  9. /**
  10. * End index, exclusive, in CSS node string that caused the warning.
  11. */
  12. endIndex?: number
  13. /**
  14. * Start index, inclusive, in CSS node string that caused the warning.
  15. */
  16. index?: number
  17. /**
  18. * CSS node that caused the warning.
  19. */
  20. node?: Node
  21. /**
  22. * Name of the plugin that created this warning. `Result#warn` fills
  23. * this property automatically.
  24. */
  25. plugin?: string
  26. /**
  27. * Start position, inclusive, in CSS node string that caused the warning.
  28. */
  29. start?: RangePosition
  30. /**
  31. * Word in CSS source that caused the warning.
  32. */
  33. word?: 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. * Column for inclusive start position in the input file with this warning’s source.
  50. *
  51. * ```js
  52. * warning.column //=> 6
  53. * ```
  54. */
  55. column: number
  56. /**
  57. * Column for exclusive end position in the input file with this warning’s source.
  58. *
  59. * ```js
  60. * warning.endColumn //=> 4
  61. * ```
  62. */
  63. endColumn?: number
  64. /**
  65. * Line for exclusive end position in the input file with this warning’s source.
  66. *
  67. * ```js
  68. * warning.endLine //=> 6
  69. * ```
  70. */
  71. endLine?: number
  72. /**
  73. * Line for inclusive start position in the input file with this warning’s source.
  74. *
  75. * ```js
  76. * warning.line //=> 5
  77. * ```
  78. */
  79. line: number
  80. /**
  81. * Contains the CSS node that caused the warning.
  82. *
  83. * ```js
  84. * warning.node.toString() //=> 'color: white !important'
  85. * ```
  86. */
  87. node: Node
  88. /**
  89. * The name of the plugin that created this warning.
  90. * When you call `Node#warn` it will fill this property automatically.
  91. *
  92. * ```js
  93. * warning.plugin //=> 'postcss-important'
  94. * ```
  95. */
  96. plugin: string
  97. /**
  98. * The warning message.
  99. *
  100. * ```js
  101. * warning.text //=> 'Try to avoid !important'
  102. * ```
  103. */
  104. text: string
  105. /**
  106. * Type to filter warnings from `Result#messages`.
  107. * Always equal to `"warning"`.
  108. */
  109. type: 'warning'
  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