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