2023-08-17 09:47:40 +00:00
|
|
|
'use strict'
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
class Warning {
|
|
|
|
constructor(text, opts = {}) {
|
|
|
|
this.type = 'warning'
|
|
|
|
this.text = text
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
if (opts.node && opts.node.source) {
|
2023-08-17 09:47:40 +00:00
|
|
|
let range = opts.node.rangeBy(opts)
|
|
|
|
this.line = range.start.line
|
|
|
|
this.column = range.start.column
|
|
|
|
this.endLine = range.end.line
|
|
|
|
this.endColumn = range.end.column
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
for (let opt in opts) this[opt] = opts[opt]
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
toString() {
|
2022-01-21 08:28:41 +00:00
|
|
|
if (this.node) {
|
|
|
|
return this.node.error(this.text, {
|
|
|
|
index: this.index,
|
2023-08-17 09:47:40 +00:00
|
|
|
plugin: this.plugin,
|
2022-01-21 08:28:41 +00:00
|
|
|
word: this.word
|
2023-08-17 09:47:40 +00:00
|
|
|
}).message
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.plugin) {
|
2023-08-17 09:47:40 +00:00
|
|
|
return this.plugin + ': ' + this.text
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
return this.text
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
2023-08-17 09:47:40 +00:00
|
|
|
}
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2023-08-17 09:47:40 +00:00
|
|
|
module.exports = Warning
|
|
|
|
Warning.default = Warning
|