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. export { Warning_ as default }
  36. }
  37. /**
  38. * Represents a plugin’s warning. It can be created using `Node#warn`.
  39. *
  40. * ```js
  41. * if (decl.important) {
  42. * decl.warn(result, 'Avoid !important', { word: '!important' })
  43. * }
  44. * ```
  45. */
  46. declare class Warning_ {
  47. /**
  48. * Column for inclusive start position in the input file with this warning’s source.
  49. *
  50. * ```js
  51. * warning.column //=> 6
  52. * ```
  53. */
  54. column: number
  55. /**
  56. * Column for exclusive end position in the input file with this warning’s source.
  57. *
  58. * ```js
  59. * warning.endColumn //=> 4
  60. * ```
  61. */
  62. endColumn?: number
  63. /**
  64. * Line for exclusive end position in the input file with this warning’s source.
  65. *
  66. * ```js
  67. * warning.endLine //=> 6
  68. * ```
  69. */
  70. endLine?: number
  71. /**
  72. * Line for inclusive start position in the input file with this warning’s source.
  73. *
  74. * ```js
  75. * warning.line //=> 5
  76. * ```
  77. */
  78. line: number
  79. /**
  80. * Contains the CSS node that caused the warning.
  81. *
  82. * ```js
  83. * warning.node.toString() //=> 'color: white !important'
  84. * ```
  85. */
  86. node: Node
  87. /**
  88. * The name of the plugin that created this warning.
  89. * When you call `Node#warn` it will fill this property automatically.
  90. *
  91. * ```js
  92. * warning.plugin //=> 'postcss-important'
  93. * ```
  94. */
  95. plugin: string
  96. /**
  97. * The warning message.
  98. *
  99. * ```js
  100. * warning.text //=> 'Try to avoid !important'
  101. * ```
  102. */
  103. text: string
  104. /**
  105. * Type to filter warnings from `Result#messages`.
  106. * Always equal to `"warning"`.
  107. */
  108. type: 'warning'
  109. /**
  110. * @param text Warning message.
  111. * @param opts Warning options.
  112. */
  113. constructor(text: string, opts?: Warning.WarningOptions)
  114. /**
  115. * Returns a warning position and message.
  116. *
  117. * ```js
  118. * warning.toString() //=> 'postcss-lint:a.css:10:14: Avoid !important'
  119. * ```
  120. *
  121. * @return Warning position and message.
  122. */
  123. toString(): string
  124. }
  125. declare class Warning extends Warning_ {}
  126. export = Warning