Skip to content

Unexpected EOL of parsed comment blocks #160

@gcunsolo

Description

@gcunsolo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions