You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
739 B

2 years ago
  1. 'use strict'
  2. class Warning {
  3. constructor(text, opts = {}) {
  4. this.type = 'warning'
  5. this.text = text
  6. if (opts.node && opts.node.source) {
  7. let range = opts.node.rangeBy(opts)
  8. this.line = range.start.line
  9. this.column = range.start.column
  10. this.endLine = range.end.line
  11. this.endColumn = range.end.column
  12. }
  13. for (let opt in opts) this[opt] = opts[opt]
  14. }
  15. toString() {
  16. if (this.node) {
  17. return this.node.error(this.text, {
  18. plugin: this.plugin,
  19. index: this.index,
  20. word: this.word
  21. }).message
  22. }
  23. if (this.plugin) {
  24. return this.plugin + ': ' + this.text
  25. }
  26. return this.text
  27. }
  28. }
  29. module.exports = Warning
  30. Warning.default = Warning