UNPKG

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