aboutsummaryrefslogtreecommitdiffhomepage
path: root/CONTRIBUTING.md
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-04-01 20:48:11 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-04-04 21:00:43 -0700
commitfd1b7ba52901179c19f5997b650518993d919f52 (patch)
tree1600b09c7376ce259178a038587d5d1249dd1061 /CONTRIBUTING.md
parenta4642f141f7781792909cff385ff2316530416ee (diff)
support making fish code match the style guide
This changes implements two new make targets: `style` and `style-all`. These make it easy to ensure that a change conforms to the project style guides for C++ and fish code. Fixes #571
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r--CONTRIBUTING.md109
1 files changed, 46 insertions, 63 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6321cdc7..af2ad690 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,27 +1,31 @@
# Guidelines For Developers
+This document provides guidelines for making changes to the fish-shell project. This includes rules for how to format the code, naming conventions, etc. It also includes recommended best practices such as creating a Travis-CI account so you can verify your changes pass all the tests before making a pull-request.
+
+See the bottom of this document for help on installing the linting and style reformatting tools discussed in the following sections.
+
## Lint Free Code
-Automated analysis tools like cppcheck and oclint can help identify bugs. They also help ensure the code has a consistent style and avoids patterns that tend to confuse people.
+Automated analysis tools like cppcheck and oclint can point out potential bugs. They also help ensure the code has a consistent style and that it avoids patterns that tend to confuse people.
Ultimately we want lint free code. However, at the moment a lot of cleanup is required to reach that goal. For now simply try to avoid introducing new lint.
To make linting the code easy there are two make targets: `lint` and `lint-all`. The latter does just what the name implies. The former will lint any modified but not committed `*.cpp` files. If there is no uncommitted work it will lint the files in the most recent commit.
-To install the lint checkers on Mac OS X using HomeBrew:
+## Ensuring Your Changes Conform to the Style Guides
+
+The following sections discuss the specific rules for the style that should be used when writing fish code. To ensure your changes conform to the style rules you simply need to run
```
-brew tap oclint/formulae
-brew install oclint
-brew install cppcheck
+make style
```
-To install the lint checkers on Linux distros that use Apt:
+before commiting your change. If you've already committed your changes that's okay since it will then check the files in the most recent commit. This can be useful after you've merged someone elses change and want to check that it's style is acceptable.
+
+If you want to check the style of the entire code base run
```
-sudo apt-get install clang
-sudo apt-get install oclint
-sudo apt-get install cppcheck
+make style-all
```
## Fish Script Style Guide
@@ -34,75 +38,54 @@ The first word of global variable names should generally be `fish` for public va
## C++ Style Guide
-1. The `clang-format` command is authoritative with respect to indentation, whitespace around operators, etc. **Note**: this rule should be ignored at this time. A subsequent commit will add the necessary config file and make targets. After the happens the code will be cleaned up and this rule will become mandatory.
-
-1. All names in code should be `small_snake_case`. No Hungarian notation is used. Classes and structs names should be followed by `_t`.
-
-1. fish uses the Allman/BSD style of indentation.
-
-1. Indent with spaces, not tabs.
-
-1. Use 4 spaces per indent.
-
-1. Opening curly bracket is on the following line:
-
- // ✔:
- struct name
- {
- // code
- };
+1. The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) forms the basis of the fish C++ style guide. There are two major deviations for the fish project. First, a four, rather than two, space indent. Second, line lengths up to 100, rather than 80, characters.
- void func()
- {
- // code
- }
+1. The `clang-format` command is authoritative with respect to indentation, whitespace around operators, etc. **Note**: this rule should be ignored at this time. After the code is cleaned up this rule will become mandatory.
- if (...)
- {
- // code
- }
+1. All names in code should be `small_snake_case`. No Hungarian notation is used. Classes and structs names should be followed by `_t`.
- // ✗:
- void func() {
- // code
- }
+1. Always attach braces to the surrounding context.
-1. Put space after `if`, `while` and `for` before conditions.
+1. Indent with spaces, not tabs and use four spaces per indent.
- // ✔:
- if () {}
+## Installing the Required Tools
- // ✗:
- if() {}
+### Installing the Linting Tools
-1. Put spaces before and after operators excluding increment and decrement;
+To install the lint checkers on Mac OS X using HomeBrew:
- // ✔:
- int a = 1 + 2 * 3;
- a++;
+```
+brew tap oclint/formulae
+brew install oclint
+brew install cppcheck
+```
- // ✗:
- int a=1+2*3;
- a ++;
+To install the lint checkers on Linux distros that use Apt:
-1. Never put spaces between function name and parameters list.
+```
+sudo apt-get install clang
+sudo apt-get install oclint
+sudo apt-get install cppcheck
+```
- // ✔:
- func(args);
+### Installing the Reformatting Tools
- // ✗:
- func (args);
+To install the reformatting tool on Mac OS X using HomeBrew:
-1. Never put spaces after `(` and before `)`.
+```
+brew install clang-format
+```
-1. Always put space after comma and semicolon.
+To install the reformatting tool on Linux distros that use Apt:
- // ✔:
- func(arg1, arg2);
+```
+apt-cache search clang-format
+```
- for (int i = 0; i < LENGTH; i++) {}
+That will list the versions available. Pick the newest one available (3.6 for Ubuntu 14.04 as I write this) and install it:
- // ✗:
- func(arg1,arg2);
+```
+sudo apt-get install clang-format-3.6
+sudo ln -s /usr/bin/clang-format-3.6 /usr/bin/clang-format
- for (int i = 0;i<LENGTH;i++) {}
+```