Skip to content

Unexpected EOL of parsed comment blocks #160

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
gcunsolo opened this issue Jun 23, 2022 · 1 comment
Closed

Unexpected EOL of parsed comment blocks #160

gcunsolo opened this issue Jun 23, 2022 · 1 comment

Comments

@gcunsolo
Copy link

Hi!
First of all, thanks for your job :)

Following up #145 I may have spotted a similar EOL problem on comment blocks:

Premises

The following test succeed (note the CR as EOL):

it('parsed.ast.comments  // succeeding with CR', () => {
    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: '@typescript-eslint/parser',
    });

    expect(parsed.ast.comments[0].value).to.equal(
      '*\r\n'
      + '       * @description TESTSTETSTST\r\n'
      + '       * @param {string} arg - lorem\r\n'
      + '       * @return {string} - someDescription\r\n'
      + '       ',
    );
  });

The problem (?)

The following test fails (note the LF as EOL):

  it('parsed.ast.comments // failing with LF', () => {
    const parsed = parseForESLint(`\n
  <template>\n
    <div>HELLO WORLD</div>\n
  </template>\n
\n
  <script>\n
  export default {\n
    computed: {\n
      /**\n
       * @description TESTSTETSTST\n
       * @param {string} arg - lorem\n
       * @return {string} - someDescription\n
       */\n
      isForTestingLint (arg) {\n
        return arg;\n
      },\n
    },\n
  };\n
  </script>\n
`, {
      parser: '@typescript-eslint/parser',
    });

    expect(parsed.ast.comments[0].value).to.equal(
      '*\r\n'
      + '       * @description TESTSTETSTST\r\n'
      + '       * @param {string} arg - lorem\r\n'
      + '       * @return {string} - someDescription\r\n'
      + '       ',
    );
  });

I would expect the content of parsed.ast.comments[0].value to be

      '*\r\n'
      + '       * @description TESTSTETSTST\r\n'
      + '       * @param {string} arg - lorem\r\n'
      + '       * @return {string} - someDescription\r\n'
      + '       ',

Instead I'm having

      '*\n\n'
      + '       * @description TESTSTETSTST\n\n'
      + '       * @param {string} arg - lorem\n\n'
      + '       * @return {string} - someDescription\n\n'
      + '       ',

For your information, the same unexpected behavior is obtained when using CRLF as EOL
The following code:

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

would produce

      '*\r\n\n'
      + '       * @description TESTSTETSTST\r\n\n'
      + '       * @param {string} arg - lorem\r\n\n'
      + '       * @return {string} - someDescription\r\n\n'
      + '       ',

The question

From what I observe, the following rules are true:

CR turns into CRLF
LF turns into LF + LF
CRLF turns into CRLF + LF

Is this the expected behavior?

Thanks in advance for your time

@ota-meshi
Copy link
Member

If I understand what you say, I think the parser is working right. Check the result of actually running the template literal.

JSON.stringify(`\r\n
  <template>\r\n
    <div>HELLO WORLD</div>\r\n
  </template>\r\n
\r\n
  <script>\r\n
  export default {\r\n
    computed: {\r\n
      /**\r\n
       * @description TESTSTETSTST\r\n
       * @param {string} arg - lorem\r\n
       * @return {string} - someDescription\r\n
       */\r\n
      isForTestingLint (arg) {\r\n
        return arg;\r\n
      },\r\n
    },\r\n
  };\r\n
  </script>\r\n
`)

@ota-meshi ota-meshi closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants