Skip to content

build: 'check_format.py check' reports line number#2390

Merged
mattklein123 merged 6 commits intoenvoyproxy:masterfrom
taiki45:print-line-number
Jan 18, 2018
Merged

build: 'check_format.py check' reports line number#2390
mattklein123 merged 6 commits intoenvoyproxy:masterfrom
taiki45:print-line-number

Conversation

@taiki45
Copy link
Copy Markdown
Member

@taiki45 taiki45 commented Jan 17, 2018

Description:
Fixes #2298.

Example outputs:

$ ./tools/check_format.py check source/common/stats/statsd.cc
ERROR: header_order.py check failed for file: ./source/common/stats/statsd.cc
ERROR:   ./source/common/stats/statsd.cc:3
ERROR:   ./source/common/stats/statsd.cc:9
ERROR:   ./source/common/stats/statsd.cc:12
ERROR: clang-format check failed for file: ./source/common/stats/statsd.cc
ERROR:   ./source/common/stats/statsd.cc:26
ERROR:   ./source/common/stats/statsd.cc:38
ERROR:   ./source/common/stats/statsd.cc:46
ERROR: check format failed. run 'tools/check_format.py fix'
$ ./tools/check_format.py check source/common/stats/statsd.h
ERROR: ./source/common/stats/statsd.h has over-enthusiastic spaces:
ERROR:   ./source/common/stats/statsd.h:128
ERROR: header_order.py check failed for file: ./source/common/stats/statsd.h
ERROR:   ./source/common/stats/statsd.h:7
ERROR:   ./source/common/stats/statsd.h:12
ERROR: clang-format check failed for file: ./source/common/stats/statsd.h
ERROR:   ./source/common/stats/statsd.h:29
ERROR:   ./source/common/stats/statsd.h:128
ERROR:   ./source/common/stats/statsd.h:146
ERROR: check format failed. run 'tools/check_format.py fix'
$ ./tools/check_format.py check source/common/stats/BUILD
ERROR: buildifier check failed for file: ./source/common/stats/BUILD
ERROR:   ./source/common/stats/BUILD:16
ERROR:   ./source/common/stats/BUILD:24
ERROR: ./source/common/stats/BUILD has unexpected direct external dependency on protobuf, use //source/common/protobuf instead.
ERROR:   ./source/common/stats/BUILD:24
ERROR: check format failed. run 'tools/check_format.py fix'

Risk Level:
Low: Small bug fix or small optional feature.

Testing:
Manual testing in both macOS and Linux (Ubuntu 16.04.3 LTS).

Docs Changes:
N/A

Release Notes:
N/A

Fixes #2298.

To quickly find issues.

Example outputs:

  $ ./tools/check_format.py check source/common/stats/statsd.cc
  ERROR: header_order.py check failed for file: ./source/common/stats/statsd.cc
  ERROR:   ./source/common/stats/statsd.cc:3
  ERROR:   ./source/common/stats/statsd.cc:9
  ERROR:   ./source/common/stats/statsd.cc:12
  ERROR: clang-format check failed for file: ./source/common/stats/statsd.cc
  ERROR:   ./source/common/stats/statsd.cc:26
  ERROR:   ./source/common/stats/statsd.cc:38
  ERROR:   ./source/common/stats/statsd.cc:46
  ERROR: check format failed. run 'tools/check_format.py fix'

  $ ./tools/check_format.py check source/common/stats/statsd.h
  ERROR: ./source/common/stats/statsd.h has over-enthusiastic spaces:
  ERROR:   ./source/common/stats/statsd.h:128
  ERROR: header_order.py check failed for file: ./source/common/stats/statsd.h
  ERROR:   ./source/common/stats/statsd.h:7
  ERROR:   ./source/common/stats/statsd.h:12
  ERROR: clang-format check failed for file: ./source/common/stats/statsd.h
  ERROR:   ./source/common/stats/statsd.h:29
  ERROR:   ./source/common/stats/statsd.h:128
  ERROR:   ./source/common/stats/statsd.h:146
  ERROR: check format failed. run 'tools/check_format.py fix'

  $ ./tools/check_format.py check source/common/stats/BUILD
  ERROR: buildifier check failed for file: ./source/common/stats/BUILD
  ERROR:   ./source/common/stats/BUILD:16
  ERROR:   ./source/common/stats/BUILD:24
  ERROR: ./source/common/stats/BUILD has unexpected direct external dependency on protobuf, use //source/common/protobuf instead.
  ERROR:   ./source/common/stats/BUILD:24
  ERROR: check format failed. run 'tools/check_format.py fix'

Signed-off-by: Taiki Ono <taiks.4559@gmail.com>
@mattklein123
Copy link
Copy Markdown
Member

Thank you @taiki45! @danielhochman please review.

Signed-off-by: Taiki Ono <taiks.4559@gmail.com>
with open(file_path) as f:
if re.search('"protobuf"', f.read(), re.MULTILINE):
text = f.read()
if re.search(pattern, text, re.MULTILINE):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why use re? why not use in?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah i see why, see other comment

if re.search(pattern, text, re.MULTILINE):
printError("%s has over-enthusiastic spaces:" % file_path)
regex = re.compile(pattern)
for i, line in enumerate(text.splitlines()):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i see why re is useful here. can we abstract the find and output line number logic into a function to use it in both places?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry for the confusion but I also think we can use in instead of re.search. Is re.search still useful here?

Don't use costly regex search.

Signed-off-by: Taiki Ono <taiks.4559@gmail.com>
Signed-off-by: Taiki Ono <taiks.4559@gmail.com>
print "ERROR: something went wrong while executing: %s" % e.cmd
sys.exit(1)
# In case we can't find any line numbers, call printError at first.
printError(error_message + " for file: %s" % (file_path))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consistent string formatting please
i.e. "%s for file: %s" % (error_message, file_path)

def checkProtobufExternalDepsBuild(file_path):
if whitelistedForProtobufDeps(file_path):
return True
def findPatternAndPrintError(pattern, file_path, error_message):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i would rename from pattern (since it's no longer re-based) to substring

@danielhochman
Copy link
Copy Markdown
Contributor

+1 pending minor nits. thanks!

Signed-off-by: Taiki Ono <taiks.4559@gmail.com>
Signed-off-by: Taiki Ono <taiks.4559@gmail.com>
text = f.read()
if re.search('"google/protobuf', text, re.MULTILINE) or re.search(
"google::protobuf", text, re.MULTILINE):
if '"google/protobuf' in text or "google::protobuf" in text:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the leading quote intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is intentional to detect "include" statements like https://github.com/envoyproxy/envoy/pull/1236/files#diff-c0a36114a7b25e540b0cef252d0993e3L10, since this pattern is introduced with #1236.

@mattklein123 mattklein123 merged commit a2487b8 into envoyproxy:master Jan 18, 2018
@taiki45 taiki45 deleted the print-line-number branch January 18, 2018 23:45
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: Make the lookup of headers in HeadersBuilder and Headers case-insensitive and preserve the original casing of headers. Implemented on iOS only. Android side-changes are going to be implemented in a follow up PR. GH issue: #2390.
Risk Level: Low
Testing: Unit Tests
Docs Changes: Updated
Release Notes: Updated

Signed-off-by: Rafal Augustyniak <raugustyniak@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: Make the lookup of headers in HeadersBuilder and Headers case-insensitive and preserve the original casing of headers. Implemented on iOS only. Android side-changes are going to be implemented in a follow up PR. GH issue: #2390.
Risk Level: Low
Testing: Unit Tests
Docs Changes: Updated
Release Notes: Updated

Signed-off-by: Rafal Augustyniak <raugustyniak@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
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.

'./tools/check_format.py check' should print file & line-number of violations

3 participants