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

Add clang tidy/format docs #103

Merged
merged 2 commits into from
Jan 10, 2018
Merged

Add clang tidy/format docs #103

merged 2 commits into from
Jan 10, 2018

Conversation

GretaCB
Copy link
Contributor

@GretaCB GretaCB commented Jan 10, 2018

Per #70, add more info and context about how the skel uses clang-tidy and clang-format.

cc @mapbox/core-tech

@GretaCB GretaCB mentioned this pull request Jan 10, 2018
@@ -172,6 +173,40 @@ User of your module runs 'npm install'

This binary file `../lib/binding/module.node` is what `require()` points to within Node.js.

# Clang Tools

This skeleton uses two clang llvm tools for automated formatting and static fixes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally say clang/llvm to denote the projects are the same (just different parts: llvm is the term for the entire project and clang is the term for the "front-end" sub-projects).

This skeleton uses two clang llvm tools for automated formatting and static fixes.

Each of these tools run within their own [Travis jobs](https://github.com/mapbox/node-cpp-skel/blob/master/.travis.yml). You can disable these Travis jobs if you'd like, by commenting them out in `.travis.yml`. This may be necessary if you're porting this skel into an already-existing project that triggers tons of clang-tidy errors, and you'd like to work through them gradually while still actively iterating on other parts of your code.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍


### [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
Lint framework that can do very powerful checks, for example bugs that can be deduced via [static analysis](https://github.com/mapbox/cpp/blob/master/glossary.md#static-analysis), unneeded copies, inefficient for-loops, and improved readability. In many cases, it can fix and modernize your code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome description 👏

make tidy
```

- If clang-tidy outputs a failure, it will also output a specific code. Check llvm's clang docs for that exact code to learn more. For example, see ["performance-unnecessary-copy-initialization"](https://clang.llvm.org/extra/clang-tidy/checks/performance-unnecessary-copy-initialization.html).
Copy link
Contributor

Choose a reason for hiding this comment

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

If not heard them referred to as codes but rather checks. How about:

The clang-tidy tool has a large set of checks and when one fails the error message contains the shorthand for the check name. See llvm's docs for details about what failed check is referring to. For example, see ...

```

- If clang-tidy outputs a failure, it will also output a specific code. Check llvm's clang docs for that exact code to learn more. For example, see ["performance-unnecessary-copy-initialization"](https://clang.llvm.org/extra/clang-tidy/checks/performance-unnecessary-copy-initialization.html).
- Set tidy preferences in [`.clang-tidy`](https://github.com/mapbox/node-cpp-skel/blob/master/.clang-tidy). When you run clang-tidy, you'll see output of a number of specific checks that tidy runs. You can add/remove any of these checks via the `.clang-tidy` file, configure these checks, and specify the files you'd like to run these checks against. The skel runs clang-tidy against everything within the `/src` directory.
Copy link
Contributor

Choose a reason for hiding this comment

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

cant -> can't

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops, this was meant to refer to the line below that reads you either want to keep as-is or cant control

- Installed and run via [`/scripts/clang-tidy.sh`](https://github.com/mapbox/node-cpp-skel/blob/master/scripts/clang-tidy.sh)
- `NOLINT`: In the case that clang-tidy throws for code that you either want to keep as-is or cant control, you can [use `NOLINT`](https://github.com/mapbox/node-cpp-skel/blob/87c8d51f2d7d05ac44f3ea7a607f60e73a2af9c8/src/module.cpp#L43-L46) to silent clang-tidy.
- Since clang-tidy must compile the code to do its checks, skel [generates](https://github.com/mapbox/node-cpp-skel/blob/master/scripts/generate_compile_commands.py) a JSON file that tells clang-tidy which files to run against and what compile command to run. This file newly generated file, `/build/compile_command.json`, is created when running `make tidy`. See [clang's JSON compilation format docs](https://clang.llvm.org/docs/JSONCompilationDatabase.html) for more info.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! One chunk of text reads oddly however This file newly generated file. Should it read: This newly generated file?

Copy link
Contributor

@springmeyer springmeyer left a comment

Choose a reason for hiding this comment

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

Great PR. I made minor comments inline. I think this is ready to merge anytime you do @GretaCB.

@GretaCB GretaCB merged commit 4625055 into master Jan 10, 2018
@springmeyer springmeyer deleted the clang-docs branch January 11, 2018 18:38
@springmeyer
Copy link
Contributor

🙌

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.

2 participants