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

#177: Forbid to use CRLF end-of-line #708

Merged

Conversation

nifadyev
Copy link
Contributor

@nifadyev nifadyev commented Sep 30, 2024

I have made things!

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

Related issues

@nifadyev
Copy link
Contributor Author

Hey @sobolevn . Should file .env.eol be committed with \r\n line endings? Also, I don't know how to properly write the reasoning for this violation rule

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks!

Restricts to use `/r/n` (CRLF) end-of-line.

Reasoning:
???
Copy link
Member

Choose a reason for hiding this comment

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

Mixing different end-of-line chars can lead to different hard-to-debug problems.

???

Solution:
Use `/n` (LF) end-of-line.
Copy link
Member

Choose a reason for hiding this comment

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

Please, mention .gitattributes file here.

Solution:
Use `/n` (LF) end-of-line.

Example::
Copy link
Member

Choose a reason for hiding this comment

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

Please, remove this section.

@@ -35,3 +39,9 @@ def _check_value_quotes(self, node: Value) -> None:
self._add_violation(QuotedValueViolation(node, text=node.raw_text))
elif text.startswith("'") and text.endswith("'"):
self._add_violation(QuotedValueViolation(node, text=node.raw_text))

def _is_crlf_eol_used(self, node: Value) -> None:
crlf_eol = '\r'
Copy link
Member

Choose a reason for hiding this comment

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

Please, make this a module-level final constant.

setup.cfg Outdated
@@ -65,7 +65,8 @@ addopts =
--strict-markers
--strict-config
--doctest-modules
--cov=dotenv_linter
# Disable with option to allow debugging
; --cov=dotenv_linter
Copy link
Member

Choose a reason for hiding this comment

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

Please, re-enable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. Should it be mentioned somewhere? For example, in Development README section?

@@ -4,3 +4,4 @@
# See: https://github.com/wemake-services/dotenv-linter/issues/20
TEST=1
EMPTY=
VARIABLE_WITH_TRAILING_SLASH_R=value/r
Copy link
Member

Choose a reason for hiding this comment

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

/r and \r are clearly not the same

@@ -0,0 +1 @@
VARIABLE_WITH_CRLF_EOL=123
Copy link
Member

Choose a reason for hiding this comment

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

Please, make this test a code-only, no fixtures should be used. Since there are lots of editors / tools / etc that fix eofs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to make it clear - Are you suggest creating temp file inside test?

Copy link
Member

Choose a reason for hiding this comment

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

yes

assert str(violation_class.code) in stderr


def test_lint_wrong_eol(fixture_path: Callable) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_lint_wrong_eol(fixture_path: Callable) -> None:
def test_lint_wrong_eol(fixture_path: Callable[[str], str]) -> None:

@nifadyev
Copy link
Contributor Author

Is violation name suitable? InvalidEOLViolation is the first thing that came up into my mind

@@ -8,6 +8,8 @@
)
from dotenv_linter.visitors.base import BaseFSTVisitor

CRLF_EOL: Final[str] = '\r'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CRLF_EOL: Final[str] = '\r'
CRLF_EOL: Final = '\r'

"""Checks that `lint` command works for with with CRLF end-of-line."""
temp_file_path = fixture_path('.env.temp')
with open(temp_file_path, mode='w') as temp_file:
Copy link
Member

Choose a reason for hiding this comment

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

Please, use tempfile module instead here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've used tmp_path pytest fixture instead, tempfile.NamedTemporaryFile didn't work out

"""Checks that `lint` command works for with with CRLF end-of-line."""
temp_file_path = fixture_path('.env.temp')
with open(temp_file_path, mode='w') as temp_file:
_ = temp_file.write("VARIABLE_WITH_CRLF_EOL=123\r\n")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_ = temp_file.write("VARIABLE_WITH_CRLF_EOL=123\r\n")
temp_file.write("VARIABLE_WITH_CRLF_EOL=123\r\n")

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks! Great work!

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.28%. Comparing base (460b6fe) to head (a81dfda).
Report is 76 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #708      +/-   ##
==========================================
- Coverage   97.62%   97.28%   -0.35%     
==========================================
  Files          22       22              
  Lines         463      478      +15     
  Branches       74       95      +21     
==========================================
+ Hits          452      465      +13     
- Misses          8       10       +2     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sobolevn sobolevn merged commit 0fee69a into wemake-services:master Oct 4, 2024
7 of 8 checks passed
@nifadyev nifadyev deleted the feature/#177/forbid-to-use-crlf-eol branch October 4, 2024 11:05
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.

Forbid to use \r\n for line breaks
2 participants