Skip to content

Bug/Feature Request: Missing newline (lf) character at the end, if output target is file #124

Closed

Description

@stockbal

Hi,

If working with abapGit repositories, each ABAP file is always ended with a newline (lf) character. The abapGit report adds this newline behind the scene, as the web editors like GitHub are doing the same thing.

ABAP Cleaner currently does not do this, and so I would have always at least this one diff if I clean a whole lot of files.

The code adjustment would be very simple. I am not sure if an extra cli option is required for this, as a newline at the end of file will not hurt anyone - I think 😉.

Kind regards,
Ludwig

Activity

  1. jmgrassau commented on Sep 30, 2023

    @jmgrassau
    Member

    Hi Ludwig,

    just to be sure I understand this correctly: This is just meant for the case of command line usage, i.e. for FrmMain.writeCleanUpResult(), right? Because I think in other contexts (e.g. returning the cleanup result to the ADT editor), the final LF would not be helpful.

    And would "cr lf" (\r\n) be fine as well? Because this is always used between ABAP statements (ABAP.LINE_SEPARATOR).

    Kind regards,
    Jörg-Michael

  2. self-assigned this
    on Sep 30, 2023
  3. stockbal commented on Sep 30, 2023

    @stockbal
    ContributorAuthor

    Hi Jörg-Michael,

    correct. This is only for cli usage.
    Regarding crlf vs lf. I think it has to be lf. Then ABAP Cleaner would be conform with abapGit (cl_abap_char_utilities=>newline = lf).

    I will check if crlf will cause any problems or not.

    Kind regards,
    Ludwig

  4. jmgrassau commented on Sep 30, 2023

    @jmgrassau
    Member

    Hi Ludwig,

    okay, I enhanced this to persistency.writeAllTextToFile(targetPath, output + ABAP.LINE_SEPARATOR);

    Regarding crlf versus lf, I think I chose crlf because that is what ABAP cleaner gets from the ADT editor (if I remember correctly), at least on Windows.

    Kind regards,
    Jörg-Michael

  5. stockbal commented on Sep 30, 2023

    @stockbal
    ContributorAuthor

    Hi Jörg-Michael,

    I also checked if it would make a difference with crlf or not. I couldn't detect one. At least no visible diff from git. Could also be because of the git setting core.autocrlf = true. So I think it should be fine either way 🤞.

    Kind regards,
    Ludwig

  6. jmgrassau commented on Sep 30, 2023

    @jmgrassau
    Member

    Hi Ludwig,

    great, thanks for checking! Actually, I realized that the method must check whether a lf or crlf is missing at the end, and only then add it; otherwise, if the source file ends with 3 line feeds, you'd get 4 line feeds in the target file etc. (this is because the parser ignores a single line feed at the end, but not multiple line feeds).

    I also enhanced this method a bit to write the "sourceFolderFile" to the console if(!) --stats and/or --usedrules are requested. Otherwise you wouldn't know which file the respective information belongs to.

    Kind regards,
    Jörg-Michael

  7. jmgrassau commented on Oct 2, 2023

    @jmgrassau
    Member

    Hi Ludwig,

    this was now released with version 1.6.0, so files cleaned via command line will now always end with at least one crlf!

    Kind regards,
    Jörg-Michael

  8. ConjuringCoffee commented on Oct 2, 2023

    @ConjuringCoffee
    Contributor

    Jörg-Michael, you're really on a roll in the past few days! Thanks for the work you do 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions