Skip to content

Stripping of newlines in comments when preceded by carriage returns #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brettz9 opened this issue Feb 20, 2022 · 4 comments · Fixed by #146
Closed

Stripping of newlines in comments when preceded by carriage returns #145

brettz9 opened this issue Feb 20, 2022 · 4 comments · Fixed by #146
Labels

Comments

@brettz9
Copy link
Contributor

brettz9 commented Feb 20, 2022

Hi,

Our users for eslint-plugin-jsdoc have reported problems with Vue in passing on preserving newlines within the ESLint AST comments property when carriage returns are also present (preceding them).

I've confirmed that @babel/eslint-parser does not strip the newlines when interpreting the text within the user's <script> tag, but when supplying the text to vue-eslint-parser, though the carriage returns our preserved, the newlines are stripped, producing comment AST like the following, causing our plugin to report errors when there should be none:

[
  {
    type: 'Block',
    value: '*\r       * @description TESTSTETSTST\r       * @param {string} arg - lorem\r       * @return {string} - someDescription\r       ',
    // ...
  }
]

However, I see that in the likes of templateBody AST, at least, instead of newlines being missing, the newlines are present (and the carriage returns are not added), as perhaps is expected. But for comments, there is the above problem.

Code to reproduce (in a type: "module" package):

import {parseForESLint} from 'vue-eslint-parser';

const parsed = parseForESLint(`\r
  <template>\r
    <div>HELLO WORLD</div>\r
  </template>\r
\r
  <script>\r
  export default {\r
    computed: {\r
      /**\r
       * @description TESTSTETSTST\r
       * @param {string} arg - lorem\r
       * @return {string} - someDescription\r
       */\r
      isForTestingLint (arg) {\r
        return arg;\r
      },\r
    },\r
  };\r
  </script>\r
`, {
  parser: "@babel/eslint-parser"
})

console.log('parsed', parsed.ast.comments);
@ota-meshi
Copy link
Member

Thank you for this issue!

It looks like a bug to me. I think we need to replace those CRLF with LF.

@ota-meshi ota-meshi added the bug label Feb 21, 2022
@brettz9
Copy link
Contributor Author

brettz9 commented Feb 21, 2022

Thanks! If possible, though, I think it might be more ideal for us if you could preserve them so that when fixing comments for people, our parser remains aware of the original line endings.

@brettz9
Copy link
Contributor Author

brettz9 commented Feb 21, 2022

The comments are kind of an exception to the Abstract part of the AST acronym (Abstract Syntax Tree), so I think it makes sense there to retain the full exact formatting data.

@ota-meshi
Copy link
Member

Thank you for your opinion.
As you say, I think it makes sense to preserve the original line endings in the AST of the script comment in <script>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants