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

vet: add check to ensure terminating newline #7645

Merged
merged 86 commits into from
Oct 7, 2024

Conversation

eshitachandwani
Copy link
Member

RELEASE NOTES: None

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.75%. Comparing base (859602c) to head (a1c7b90).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7645      +/-   ##
==========================================
- Coverage   81.85%   81.75%   -0.11%     
==========================================
  Files         361      361              
  Lines       27822    27822              
==========================================
- Hits        22773    22745      -28     
- Misses       3851     3872      +21     
- Partials     1198     1205       +7     

see 18 files with indirect coverage changes

scripts/vet.sh Outdated
@@ -70,6 +70,9 @@ not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" --
# - Ensure that no trailing spaces are found.
not git grep '[[:blank:]]$'

# - Ensure that all files have a terminating newline.
git grep -l '$' -- "*.txt" "*.md" | xargs -I {} sh -c '[ -n "$(tail -c 1 "{}")" ] && echo "{}: No terminating new line found"'
Copy link
Contributor

Choose a reason for hiding this comment

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

you have to negate the output. git grep returns exit status 1 when success so we have to negate to get 0. do not git grep....

Copy link
Member

Choose a reason for hiding this comment

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

We should apply this restriction to all files in our repo I think, not just txt/md files. (We don't check in any binary files, at least not currently, so no need to worry about that.) So the first part can be git ls-files instead of a grep.

Copy link
Member

Choose a reason for hiding this comment

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

Also to prevent your sh command from erroring, you can do && echo "{}: ..." || true (but maybe there's a better way?).

Copy link
Member Author

Choose a reason for hiding this comment

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

We should apply this restriction to all files in our repo I think, not just txt/md files. (We don't check in any binary files, at least not currently, so no need to worry about that.) So the first part can be git ls-files instead of a grep.

I noticed that the g3 presubmits only mandate terminating newline in text files, so I thought of following that, but I will change it to check in all the files

Copy link
Member Author

Choose a reason for hiding this comment

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

Also to prevent your sh command from erroring, you can do && echo "{}: ..." || true (but maybe there's a better way?).

Added specific checks forsh command errors by avoiding running on empty files and checking permissions and readability

@eshitachandwani
Copy link
Member Author

Adding newline to the following files :

  • Documentation/grpc-metadata.md
  • examples/data/rbac/policy.json
  • examples/features/name_resolving/README.md
  • reflection/test/grpc_testing_not_regenerate/dynamic.proto
  • scripts/vet.sh
  • testdata/x509/client_with_spiffe_openssl.cnf

scripts/vet.sh Outdated
@@ -70,6 +70,9 @@ not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" --
# - Ensure that no trailing spaces are found.
not git grep '[[:blank:]]$'

# - Ensure that all files have a terminating newline.
! git ls-files | xargs -r -I {} sh -c '[ -n "$(tail -c 1 "{}" 2>/dev/null)" ] && echo "{}: No terminating new line found"'
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since everywhere we are using not, let's continue to use that instead of !

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion for echo: missing a terminating newline

@easwars
Copy link
Contributor

easwars commented Oct 4, 2024

Please fix the merge conflict. Thanks.

@easwars easwars assigned eshitachandwani and unassigned dfawley Oct 4, 2024
scripts/vet.sh Outdated
@@ -70,6 +70,9 @@ not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" --
# - Ensure that no trailing spaces are found.
not git grep '[[:blank:]]$'

# - Ensure that all files have a terminating newline.
git ls-files | not xargs -r -I {} sh -c '[ -n "$(tail -c 1 "{}" 2>/dev/null)" ] && echo "{}: No terminating new line found"' | fail_on_output
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you want this -r since there should always be results from git ls-files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@easwars easwars merged commit e8a70c6 into grpc:master Oct 7, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants