Skip to content

Add option to configure non-standard trailing newlines#208

Merged
SaschaMann merged 2 commits into
mainfrom
trailing-whitespace-checks-really-bother-some-maintainers-aka-me-jk
May 4, 2022
Merged

Add option to configure non-standard trailing newlines#208
SaschaMann merged 2 commits into
mainfrom
trailing-whitespace-checks-really-bother-some-maintainers-aka-me-jk

Conversation

@SaschaMann

@SaschaMann SaschaMann commented May 3, 2022

Copy link
Copy Markdown
Contributor

@SaschaMann
SaschaMann requested a review from ErikSchierboom May 3, 2022 13:52
@SaschaMann
SaschaMann requested a review from a team as a code owner May 3, 2022 13:52
@SaschaMann
SaschaMann temporarily deployed to abort-timer May 3, 2022 13:55 Inactive
Comment thread scripts/apply-track-config.jl Outdated
# Add or remove trailing newlines depending on global config
# The default assumption is one trailing newline
newlines = haskey(global_cfg["files"], file) ? get(global_cfg["files"][file], "trailing_newlines", 1) : 1
write(io, "\n" ^ newlines)

@SaschaMann SaschaMann May 3, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ^ is a bit unusual for strings in most programming languages, here's an example:

julia> "x" ^ 5
"xxxxx"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@SaschaMann

Copy link
Copy Markdown
Contributor Author

This might cause unwanted changes if people added leading newlines to their CoC append, see exercism/julia#500 (fixed by exercism/julia@9d25dbd)

@ErikSchierboom ErikSchierboom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

# Add or remove trailing newlines depending on global config
# The default assumption is one trailing newline
newlines = haskey(global_cfg["files"], file) ? get(global_cfg["files"][file], "trailing_newlines", 1) : 1
write(io, "\n" ^ newlines)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment thread config.toml
# File-specific config
[files]
[files."CODE_OF_CONDUCT.md"]
trailing_newlines = 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was there just to prove it was working, right? https://github.com/exercism/julia/pull/500/files

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of. I think it's sensible that any append to that file is separated by two newlines as a new paragraph.

@ErikSchierboom ErikSchierboom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@ee7 Once this is merged, could you rebase your PR on main? That way we can do a test run with this functionality included in your PR

@ee7

ee7 commented May 4, 2022

Copy link
Copy Markdown
Member

could you rebase your PR on main?

Sure. So the idea is that we alter #205 to read from config.toml, and enforce the newline count for these special cases? Right now it requires every git-tracked, non-empty, non-binary file to end in exactly 1 newline.

@ErikSchierboom

Copy link
Copy Markdown
Member

Sure. So the idea is that we alter #205 to read from config.toml, and enforce the newline count for these special cases? Right now it requires every git-tracked, non-empty, non-binary file to end in exactly 1 newline.

No, it should work differently. Every file ends with exactly 1 newline within the repo, but when the org-wide-files syncing workflow runs, it'll ensure that the number of newlines specified in the config.toml is applied.

@ee7

ee7 commented May 4, 2022

Copy link
Copy Markdown
Member

Oh, I see. That sounds better.

@ee7 ee7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve, assuming that it works as Erik says it does :)

write(io, "\n" ^ newlines)

# Write append content
write(io, append_content)

@ee7 ee7 May 4, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the responsibility is still on the downstream repo to end their append file with exactly one newline, so that the combined file also ends with exactly 1 newline, right? That's fine by me.

We could choose to write the combined file with exactly 1 final newline, regardless of the number of newlines in the repo's append file. I don't think it's worth bothering (but feel free to do that if you like it).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the responsibility is still on the downstream repo to end their append file with exactly one newline, so that the combined file also ends with exactly 1 newline, right? That's fine by me.

Yes. If their append file does not end with exactly one newline, they either don't care or the append file itself would cause them issues already. I don't think we have to be concerned with those two cases.

@SaschaMann
SaschaMann merged commit f760ee1 into main May 4, 2022
@SaschaMann
SaschaMann deleted the trailing-whitespace-checks-really-bother-some-maintainers-aka-me-jk branch May 4, 2022 10:15
@ErikSchierboom

Copy link
Copy Markdown
Member

I've just done a test run and it looks like the newline appending works! https://github.com/exercism/csharp/pull/1921/files

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 this pull request may close these issues.

3 participants