vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.45k stars 667 forks source link

vue/multiline-html-element-content-newline message #742

Closed daluvi closed 5 years ago

daluvi commented 5 years ago

description

in this rule happen that the message was passed by an object to context.report. but the message not defined because the index of the object isn't 'message', is 'messageId', and the {workspace}/node_modules/eslint/lib/eslint.js, was expected a message type string and not object

Here happen two thing;
  1. in {workspace}/node_modules/eslint/lib/eslint.js was been expect a literal message
  2. this rule expect that message must be resolved by eslint.js

My packages are this:

My solution is:

if (beforeLineBreaks !== 1) {
  context.report({
    node: template.getLastToken(node.startTag),
    loc: {
      start: node.startTag.loc.end,
      end: contentFirst.loc.start
    },
    // messageId: 'unexpectedAfterClosingBracket'
    message: 'Expected 1 line break after opening tag (`<{{name}}>`), but {{actual}} line breaks found.',
    data: {
      name: node.rawName,
      actual: getPhrase(beforeLineBreaks)
    },
    fix (fixer) {
      const range = [node.startTag.range[1], contentFirst.range[0]]
      return fixer.replaceTextRange(range, '\n')
    }
  })
}

if (afterLineBreaks !== 1) {
  context.report({
    node: template.getFirstToken(node.endTag),
    loc: {
      start: contentLast.loc.end,
      end: node.endTag.loc.start
    },
    // messageId: 'unexpectedBeforeOpeningBracket'
    message: 'Expected 1 line break before closing tag (`</{{name}}>`), but {{actual}} line breaks found.',
    data: {
      name: node.name,
      actual: getPhrase(afterLineBreaks)
    },
    fix (fixer) {
      const range = [contentLast.range[1], node.endTag.range[0]]
      return fixer.replaceTextRange(range, '\n')
    }
  })
}

if this wasn't a solution, tell me why

armano2 commented 5 years ago

@daluvi we are not supporting eslint@3, messageId field was added in https://github.com/eslint/eslint/pull/9165 eslint@4.15,

lowest supported version of eslint is 5.0.0

armano2 commented 5 years ago

babel-eslint requires: eslint 4.19

you should consider updating it

mysticatea commented 5 years ago

Yeah, please use a newer ESLint.

daluvi commented 5 years ago

Thanks for the info. I'm sorry for this open topic. you helped me with your information for the next one. I promise to review the package.json of your package and I regret the late response