Skip to content

Conversation

DanielNoord
Copy link
Owner

Closes #4.

Also moved some stuff around and updated the output a little.

I kept the proposed exit codes as it just makes everything future proof.

For future reference:
0 - Nothing happened, all files are fine.
1 - Internal error
2 - Config parsing error
4, 8, 16 - Empty for future use
32 - A file was changed or could be changed
64, 128, 256 - Empty for future use

@DanielNoord DanielNoord added the enhancement New feature or request label Mar 17, 2022
@DanielNoord DanielNoord added this to the 0.6.0 milestone Mar 17, 2022
@coveralls
Copy link

coveralls commented Mar 17, 2022

Pull Request Test Coverage Report for Build 2027370813

  • 22 of 22 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1998301260: 0.0%
Covered Lines: 427
Relevant Lines: 427

💛 - Coveralls

Copy link
Collaborator

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Looks great ! I have two small suggestions but feel free to disregard.

Comment on lines 42 to 54
if not is_changed: # pylint: disable=consider-using-assignment-expr
if len(filepaths) > 1:
files_string = f"{len(filepaths)} files"
else:
files_string = "1 file"

utils._print_to_console(
f"Nothing to do! All docstrings in {files_string} are correct 🎉\n",
self.config.quiet,
)
utils._sys_exit(0, self.config.exit_code)
else:
utils._sys_exit(32, self.config.exit_code)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if not is_changed: # pylint: disable=consider-using-assignment-expr
if len(filepaths) > 1:
files_string = f"{len(filepaths)} files"
else:
files_string = "1 file"
utils._print_to_console(
f"Nothing to do! All docstrings in {files_string} are correct 🎉\n",
self.config.quiet,
)
utils._sys_exit(0, self.config.exit_code)
else:
utils._sys_exit(32, self.config.exit_code)
if is_changed: # pylint: disable=consider-using-assignment-expr
utils._sys_exit(32, self.config.exit_code)
return # We may not sys exit depending on options
files_string = f"{len(filepaths)}"
files_string += "files" if len(filepaths) > 1 else "file"
utils._print_to_console(
f"Nothing to do! All docstrings in {files_string} are correct 🎉\n",
self.config.quiet,
)
utils._sys_exit(0, self.config.exit_code)

You know my favorite thing in the world is premature return I just had to say it 😄 Depending on what you think of displaying the name of a file if it's unique there the suggestion might need some tweaking.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I changed it around a little bit. You actually found a small bug: for 0 files checked due to exclude patterns we still said that 1 file was correct.

I changed it (and fixed the tests).

if len(filepaths) > 1:
files_string = f"{len(filepaths)} files"
else:
files_string = "1 file"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
files_string = "1 file"
files_string = f"'{filepaths[0].name}'"

Maybe a nice little bonus ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fails with IndexError in some test cases. I'll keep it in mind for a future enhancement.

Copy link
Collaborator

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

👍

@DanielNoord DanielNoord merged commit d99ef29 into main Mar 23, 2022
@DanielNoord DanielNoord deleted the exit-codes branch March 23, 2022 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exit with correct exit codes
3 participants