npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clang-format

v1.8.0

Published

node wrapper around clang-format

Downloads

448,379

Readme

Build Status

clang-format

node.js module which wraps the native clang-format executable.

From the command-line:

$ npm install -g clang-format
$ clang-format -help

If your platform isn't yet supported, you can create the native binary from the latest upstream clang sources, make sure it is stripped and optimized (should be about 1.4MB as of mid-2015) and send a pull request to add it.

Checking formatting

Ensuring that changes to your code are properly formatted is an important part of your development workflow. Note that the check-clang-format and git-clang-format commands require Python to be globally available.

We recommend using a git pre-commit hook. You can configure this as follows:

  1. add a precommit script to your package.json file:

    "scripts": {
        "precommit": "check-clang-format"
    }

    By default, the user gets an error instructing them to run ./node_modules/.bin/git-clang-format. You may find it more ergonomic to set up a package.json script, eg. "scripts": { "format": "git-clang-format" }

    In this case, add a second argument to the "precommit" script, giving the error you'd like to print for users, eg.

    "precommit": "check-clang-format \"yarn format\""

  2. Add a devDependency on the husky package, which will add a .git/hooks/pre-commit script, which in turn triggers the precommit package.json script to run whenever someone adds a commit in this repository:

    $ yarn add -D husky

    or

    npm install --save-dev husky

Why do this in a pre-commit hook? For one thing, it's faster to run clang-format only on the changed files, especially as the repository grows. Also, this lets you upgrade clang-format or change your settings without needing to re-format the entire repository, while still enforcing that later changes follow the new style.

Globbing files

$ clang-format --glob=folder/**/*.js

This will run clang-format once per file result, and show the total formatted files at the end. See node-glob for globbing semantics.

Compiling clang-format

For Linux, compile a statically linked MinSizeRel build:

git clone --depth=1 https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_BUILD_STATIC=true -DLLVM_ENABLE_PROJECTS=clang ../llvm
ninja clang-format
strip bin/clang-format

For Mac OS X, static linking is not required.

Windows

Windows snapshot builds to include in the release can be found at the LLVM website.

Configure with:

cmake -G "Visual Studio 12" -DCMAKE_BUILD_TYPE=MinSizeRel ..

In the generated Visual Studio project, search for the clang-format binary in the Solution Explorer window, right click and choose Build.