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

Improve on missing newline in a file by adding line number #55

Closed
bwbroersma opened this issue Jul 17, 2023 · 1 comment
Closed

Improve on missing newline in a file by adding line number #55

bwbroersma opened this issue Jul 17, 2023 · 1 comment

Comments

@bwbroersma
Copy link
Contributor

Although #21 was fixed in #35 (by these 5 lines in 4dc8b2b), the current error does not list the line number, nor indicate that it's about the last line of the file:

[
  {
    'code': 'no_line_separators',
    'message': 'Every line must end with either a carriage return and line feed characters or just a line feed character',
    'line': None
  }
]

Either:

  1. the line number must be specified; and/or
  2. the text message should be made explicit it's about the last line.

So the problem in the code is here:

self._line_no = None
self.validate_contents()

It set's the _line_no to None, and then in validate_contents the check is done:

sectxt/sectxt/__init__.py

Lines 284 to 290 in 79bb386

if self.lines[-1]["type"] != "empty":
self._add_error(
"no_line_separators",
"Every line must end with either a carriage "
"return and line feed characters or just a line "
"feed character",
)

In the _add_error the _line_no is used:

sectxt/sectxt/__init__.py

Lines 95 to 101 in 79bb386

def _add_error(
self,
code: str,
message: str,
) -> None:
err_dict: ErrorDict = {"code": code, "message": message, "line": self._line_no}
self._errors.append(err_dict)

I would propose doing both:

  1. Add explicit_line_no=None to the _add_error definition, plus self._line_no if explicit_line_no = None else explicit_line_no and a self.lines[-1]._line_no to the _add_error call in the 'empty content after \r?\n' check in validate_contents.
  2. Change the text to 'Every line, including the last one, must end with either a carriage return and line feed characters or just a line feed character'
@DigitalTrustCenter
Copy link
Owner

With the new release the line is added with the missing newline error and the error message has been clarified.

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

No branches or pull requests

2 participants