clang-format
node wrapper around clang-format
Last updated 9 months ago by mprobst .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install clang-format 
SYNC missed versions from official npm registry.

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:

cmake -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_BUILD_STATIC=true ..
ninja 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.

Current Tags

  • 1.4.0                                ...           latest (9 months ago)

65 Versions

  • 1.4.0                                ...           9 months ago
  • 1.3.0                                ...           a year ago
  • 1.2.4                                ...           2 years ago
  • 1.0.41-c                                ...           3 years ago
  • 1.2.3                                ...           3 years ago
  • 1.2.2                                ...           3 years ago
  • 1.0.41-b                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.55                                ...           3 years ago
  • 1.0.54                                ...           3 years ago
  • 1.0.53                                ...           3 years ago
  • 1.0.52                                ...           3 years ago
  • 1.0.51                                ...           3 years ago
  • 1.0.50                                ...           3 years ago
  • 1.0.49                                ...           4 years ago
  • 1.0.48                                ...           4 years ago
  • 1.0.46                                ...           4 years ago
  • 1.0.45                                ...           4 years ago
  • 1.0.44                                ...           4 years ago
  • 1.0.43                                ...           4 years ago
  • 1.0.42                                ...           4 years ago
  • 1.0.41                                ...           4 years ago
  • 1.0.40                                ...           4 years ago
  • 1.0.39                                ...           4 years ago
  • 1.0.38                                ...           5 years ago
  • 1.0.37                                ...           5 years ago
  • 1.0.36                                ...           5 years ago
  • 1.0.35                                ...           5 years ago
  • 1.0.34                                ...           5 years ago
  • 1.0.33                                ...           5 years ago
  • 1.0.32                                ...           5 years ago
  • 1.0.31                                ...           5 years ago
  • 1.0.30                                ...           5 years ago
  • 1.0.29                                ...           5 years ago
  • 1.0.28                                ...           5 years ago
  • 1.0.27                                ...           5 years ago
  • 1.0.26                                ...           5 years ago
  • 1.0.25                                ...           5 years ago
  • 1.0.24                                ...           5 years ago
  • 1.0.23                                ...           5 years ago
  • 1.0.22                                ...           5 years ago
  • 1.0.21                                ...           5 years ago
  • 1.0.20                                ...           5 years ago
  • 1.0.19                                ...           5 years ago
  • 1.0.18                                ...           5 years ago
  • 1.0.17                                ...           5 years ago
  • 1.0.16                                ...           5 years ago
  • 1.0.15                                ...           5 years ago
  • 1.0.14                                ...           5 years ago
  • 1.0.13                                ...           5 years ago
  • 1.0.12                                ...           5 years ago
  • 1.0.11                                ...           5 years ago
  • 1.0.10                                ...           6 years ago
  • 1.0.9                                ...           6 years ago
  • 1.0.8                                ...           6 years ago
  • 1.0.7                                ...           6 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago

Copyright 2014 - 2016 © taobao.org |