warning.d.ts 1.9 KB

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