Skip to content
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

Clarification on insert_final_newline behavior for empty files #15

Closed
mcandre opened this issue Jan 13, 2020 · 3 comments · Fixed by #61
Closed

Clarification on insert_final_newline behavior for empty files #15

mcandre opened this issue Jan 13, 2020 · 3 comments · Fixed by #61

Comments

@mcandre
Copy link

mcandre commented Jan 13, 2020

POSIX requires non-empty files to feature a final end of line (e.g. \n line feed) terminator, and in general EditorConfig does a good job of helping users to enforce this.

For blank files, however, POSIX does allow for the omission of final end of line terminators. In the event that EditorConfig encounters a file with absolutely no content, it should not warn (and text editor plugins should not auto-insert) about end of line terminators.

In Atom for example, saving a blank file with EditorConfig and insert_final_newline rule enabled, does not present an extra end of line terminator. Neither does Vim. That is acceptable and storage-optimal behavior as far as POSIX is concerned. Not sure about how other EditorConfig toolsets behave.

If we ignore backwards compatibility, then EditorConfig should clarify final eol rule behavior. EditorConfig plugins and linters should go ahead and check for empty files before warning or auto-inserting final eol terminators. This could temporarily break some CI configurations, though the end result is that user data is more POSIX compliant.

However, if backwards compatibility is preeminent, then we may want to create a new option for this rule, something like blank_files_skip_eol, which takes values true, false, or none (not enforced). And encourage the community of EditorConfig tools to update and encourage good form.

@mcandre mcandre changed the title Clarification on final end of line behavior for empty files Clarification on insert_final_newline behavior for empty files Jan 13, 2020
@cxw42
Copy link
Member

cxw42 commented Jan 13, 2020

I think this is a duplicate of of editorconfig/editorconfig#416

@randstr
Copy link

randstr commented Jan 18, 2020

Empty files have zero lines, so there's nothing to terminate. Adding a newline in that case would inserting a new (empty) line, which is just wrong. Editors and linters that don't respect this behavior are buggy.

For the specification, yes, it can be clarified if necessary, to help implementers avoid mistakes. Is that necessary?

@cxw42
Copy link
Member

cxw42 commented Apr 17, 2020

Per @ppalaga at editorconfig/editorconfig#416 (comment) , I agree with clarifying the specification to state expressly that editors shall not insert newlines in empty files when saving those files with insert_final_newline = true.

cxw42 added a commit to cxw42/editorconfig-specification that referenced this issue Sep 23, 2024
cxw42 added a commit to cxw42/editorconfig-specification that referenced this issue Sep 23, 2024
@xuhdev xuhdev closed this as completed in bd9df36 Sep 24, 2024
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

Successfully merging a pull request may close this issue.

3 participants