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

tools: lint for inline headers #21521

Closed
wants to merge 4 commits into from

Conversation

Projects
None yet
6 participants
@ryzokuken
Copy link
Member

ryzokuken commented Jun 25, 2018

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

/cc @bnoordhuis

Had been reading the cpplint file today and hacked this up. LMK how this looks to you.

@ryzokuken ryzokuken requested a review from bnoordhuis Jun 25, 2018

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jun 25, 2018

Okay, wait, this doesn't even work. Let me push a few fixes.

@ryzokuken ryzokuken changed the title Lint for inline headers [WIP] Lint for inline headers Jun 25, 2018

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jun 25, 2018

@bnoordhuis this actually works now. I've added a temporary print statement just to demonstrate that, but it seems as if the error call isn't affecting the output?

@targos

This comment has been minimized.

Copy link
Member

targos commented Jun 25, 2018

if h[0] == name:
err = '%s includes both %s and %s' % (filename, header[0], h[0])
error(filename, h[1], 'build/include', 5, err)
print err

This comment has been minimized.

@bnoordhuis

bnoordhuis Jun 25, 2018

Member

More succinct of way of doing it:

all_headers = dict(item for sublist in include_state.include_list
                   for item in sublist)
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
                  if name.endswith('-inl.h'))
bad_headers &= set(all_headers.keys())  # compute intersection

for name in bad_headers:
  # lineno = all_headers[name]

It's also slightly more idiomatic vis-a-vis other include checks.

This comment has been minimized.

@ryzokuken

ryzokuken Jun 26, 2018

Author Member

@bnoordhuis okay, will try this. That said, I'm more interested at this point to find out what's wrong with my solution? It might not be idiomatic, but it should work. Why does error not work?

This comment has been minimized.

@bnoordhuis

bnoordhuis Jun 26, 2018

Member

Oh, is that your question? :-)

I assume you're testing it from the command line like this: python tools/cpplint.py src/*.cc?

Look for _DEFAULT_FILTERS: build/include is off by default. Pass --filter=build/include to test it, or --filter=+build/include to enable it in addition to the other rules.

This comment has been minimized.

@ryzokuken

ryzokuken Jun 26, 2018

Author Member

@bnoordhuis I was! That helped.

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jun 26, 2018

@bnoordhuis this works. Let me know if it looks okay and I'll squash the changes together.

@ryzokuken ryzokuken changed the title [WIP] Lint for inline headers tools: lint for inline headers Jun 27, 2018

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jun 27, 2018


for name in bad_headers:
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
error(filename, all_headers[name], 'build/include', 5, err)

This comment has been minimized.

@bnoordhuis

bnoordhuis Jun 27, 2018

Member

Maybe assign line = all_headers[name] for clarity.

This comment has been minimized.

@ryzokuken

ryzokuken Jun 27, 2018

Author Member

Sure. Will do.

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jul 8, 2018

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jul 29, 2018

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jul 29, 2018

CI passed, landing this.

@ryzokuken

This comment has been minimized.

Copy link
Member Author

ryzokuken commented Jul 29, 2018

Landed in fc81e80

@ryzokuken ryzokuken closed this Jul 29, 2018

ryzokuken added a commit that referenced this pull request Jul 29, 2018

tools: update cpplint to check for inline headers
Update cpplint.py to check for inline headers when the corresponding
header is already included.

PR-URL: #21521
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>

targos added a commit that referenced this pull request Jul 31, 2018

tools: update cpplint to check for inline headers
Update cpplint.py to check for inline headers when the corresponding
header is already included.

PR-URL: #21521
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>

@targos targos referenced this pull request Jul 31, 2018

Merged

v10.8.0 proposal #22040

refack added a commit to refack/node that referenced this pull request Apr 7, 2019

tools: refloat 4 Node.js patches to cpplint.py
* Add 3 Node.js checks
* Adjest cpplint.py header rules to Node.js convention

Cherry-pick 12c8b4d
Original commit message:
    This commit is a suggestion for adding a rule for NULL usages in the
    code base. This will currently report a number of errors which could be
    ignored using // NOLINT (readability/null_usage)

    PR-URL: nodejs#17373
    Reviewed-By: Jon Moss <me@jonathanmoss.me>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Timothy Gu <timothygu99@gmail.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
    Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
    Reviewed-By: Tobias Nießen <tniessen@tnie.de>

Refs: nodejs@12c8b4d

Cherry-pick fc81e80
Original commit message:

    Update cpplint.py to check for inline headers when the corresponding
    header is already included.

    PR-URL: nodejs#21521
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: James M Snell <jasnell@gmail.com>

Refs: nodejs@fc81e80

Cherry-pick cbc3dd9
Original commit message:

    src, tools: add check for left leaning pointers

    This commit adds a rule to cpplint to check that pointers in the code
    base lean to the left and not right, and also fixes the violations
    reported.

    PR-URL: nodejs#21010
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
    Reviewed-By: James M Snell <jasnell@gmail.com>

Refs: nodejs@cbc3dd9

Cherry-pick 9029981
Original commit message:

    tools: fix cpplint.py header rules

    THIS COMMIT SHOULD GO WITH THE NEXT. IT WILL FIND NEW LINT.

    PR-URL: nodejs#26306
    Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>

Refs: nodejs@9029981
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.