Skip to content

Commit

Permalink
Add contributing guideline
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Aug 15, 2015
1 parent e454d3b commit e6d60e2
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 0 deletions.
142 changes: 142 additions & 0 deletions CONTRIBUTING.rst
@@ -0,0 +1,142 @@
HOW TO CONTRIBUTE
-----------------

Look at the project issues list for things to do.
If you are planning contributing code that does not fix issue, visit the project IRC channel first.

Include clear description in comment, what your commit does.
If it fixes issue, include issue code in the description.

Eventually some testing guidelines will be added, but for now there is none.

If you have questions or need help, visit the project IRC channel.

MAKING CHANGES
--------------

- Fork the repository.
- Create branch for your feature.
- Follow the code style guidelines below and make changes.
- Open PR against master.
- When your PR is approved, squash your commits into one if they aren't already.
- PR gets merged.

CODE STYLE
----------

Project uses the C99 standard, avoid GNU and other unportable extensions.
Use C99 standard types. (stdbool, stdint)

3 spaces indentation, no tabs. Unix newlines (LF), UTF8 files and no BOM.

Variable declarations should be done where the variables are first used.
Do not put variable declarations top of the function like in ANSI C, this is pointless.

Asserts are encouraged, use them whenever it makes sense.
When validating function arguments (user input), put the asserts at top of the function.
This helps others to immediately see what is not valid input for the function.

Avoid useless comments in code. Code should be clear enough to understand without comments.
If something is hard to explain with comment, or you are not sure of something, the code probably could be simplified.
Comments are there when something has good reason to be explained.

Do not use typedef without a good reason. See Linux kernel's `Chapter 5 Typedefs <https://kernel.org/doc/Documentation/CodingStyle>`_

Use const whenever variable should not change.

Use static always when symbol should not be exposed outside, do not use static inside functions unless really needed.

Use newline after type name in function declarations. For function prototypes, just keep them one line.

Single line conditionals are allowed, however if the conditional contains else, it should be bracketed.

Avoid unnecessary whitespace and newlines.

Put opening brace on same line for anything except function declarations and cases.

Do not put spaces around parenthesis, with exception of open parenthesis for keyword (if, while, for)

Put spaces around arithmetic operators. (1+2 -> 1 + 2)

Put spaces after colons. (a,b,c -> a, b, c)

Get familiar with the utility functions included in `chck <https://github.com/Cloudef/chck>`_, especially the chck_string and chck_pool.
Any useful generic utility function should be contributed there.

.. code:: c
#include <stdint.h>
#include <stdbool.h>
#if INDENT_CPP
# define EXPLAIN "Put # always leftmost and indent with spaces after it"
#endif
enum type {
WHITE,
GRAY,
BLACK,
};
struct foo {
bool bar;
enum type type;
};
bool prototype(int32_t foo);
/**
* Function comment block.
* Most editors do this formatting automatically.
*
* Always use static when the function is not supposed to be exposed outside.
*/
static bool
declaration(int32_t foo)
{
// User input assertation.
// In this case we document developer, foo must be between -32 and 32.
assert(foo > -32 && foo < 32);
bool bar = false;
// Single line ifs are allowed
if (foo == 1)
bar = true;
// However if you must use else, use braces
if ((foo + bar) * ~foo == 4) {
foo = 8;
} else {
bar = false;
}
if (foo == 8)
goto error;
// Pointer operators (star, reference) should be next to variable.
void *baf = NULL, *baz = NULL;
return bar;
// Labels are aligned to left
error:
return false;
}
UNCRUSTIFY
----------

The repository contains `Uncrustify <https://github.com/bengardner/uncrustify>`_ configuration
for automatic styling of source code. While it does good job overall, there are few pitfalls.

The most common one is that it thinks anything with operators after cast is arithmetic.

.. code:: c
// formats this
static int foo = (bar)~0;
// to this
static int foo = (bar) ~0;
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -174,6 +174,11 @@ PACKAGING

For now you can look at the `AUR recipe <https://aur.archlinux.org/packages/wlc-git/>`_ for a example.

CONTRIBUTING
------------

See the `CONTRIBUTING <CONTRIBUTING.rst>`_ for more information.

BINDINGS
--------

Expand Down
147 changes: 147 additions & 0 deletions uncrustify.conf
@@ -0,0 +1,147 @@
# Uncrustify 0.61
# Generated from wlc source
newlines = lf
tok_split_gte = false
utf8_bom = remove
utf8_force = true
indent_columns = 3
indent_with_tabs = 0
indent_braces = false
indent_braces_no_func = false
indent_braces_no_struct = false
indent_brace_parent = false
indent_else_if = false
indent_var_def_cont = false
indent_func_def_force_col1 = false
indent_func_call_param = false
indent_func_def_param = false
indent_func_proto_param = false
indent_func_param_double = false
indent_relative_single_line_comments = false
indent_switch_case = indent_columns
indent_col1_comment = true
indent_label = 1
indent_access_spec = 1
indent_access_spec_body = false
indent_paren_nl = false
indent_comma_paren = false
indent_bool_paren = false
indent_first_bool_expr = false
indent_square_nl = false
indent_preserve_sql = false
indent_align_assign = true
sp_arith = force
sp_assign = force
sp_assign_default = force
sp_before_assign = force
sp_after_assign = force
sp_enum_assign = force
sp_pp_concat = ignore
sp_bool = force
sp_compare = force
sp_inside_paren = remove
sp_paren_paren = remove
sp_paren_brace = remove
sp_before_ptr_star = force
sp_before_unnamed_ptr_star = remove
sp_between_ptr_star = remove
sp_after_ptr_star = remove
sp_after_ptr_star_func = force
sp_after_type = force
sp_before_sparen = force
sp_inside_sparen = remove
sp_after_sparen = force
sp_sparen_brace = force
sp_before_semi = remove
sp_before_semi_for = remove
sp_after_semi = add
sp_after_semi_for = force
sp_before_square = remove
sp_before_squares = remove
sp_inside_square = remove
sp_after_comma = force
sp_before_comma = remove
sp_paren_comma = force
sp_before_case_colon = remove
# buggy with (type){ ... }
# sp_after_cast = remove
sp_inside_paren_cast = remove
sp_sizeof_paren = remove
sp_inside_braces = ignore
sp_inside_braces_empty = remove
sp_type_func = force
sp_func_proto_paren = remove
sp_func_def_paren = remove
sp_inside_fparens = remove
sp_inside_fparen = remove
sp_func_call_paren = remove
sp_func_call_paren_empty = remove
sp_attribute_paren = remove
sp_defined_paren = remove
sp_else_brace = force
sp_brace_else = force
sp_word_brace = add
sp_word_brace_ns = add
sp_before_nl_cont = add
sp_cond_colon = force
sp_cond_question = force
sp_cond_ternary_short = remove
sp_cmt_cpp_start = add
align_keep_tabs = false
align_with_tabs = false
align_on_tabstop = false
align_number_left = false
align_keep_extra_space = false
align_func_params = false
align_same_func_call_params = false
nl_assign_leave_one_liners = true
nl_start_of_file = remove
nl_end_of_file = force
nl_end_of_file_min = 1
nl_fcall_brace = remove
nl_enum_brace = remove
nl_struct_brace = remove
nl_union_brace = remove
nl_if_brace = remove
nl_brace_else = remove
nl_elseif_brace = remove
nl_else_brace = remove
nl_else_if = remove
nl_for_brace = remove
nl_while_brace = remove
nl_do_brace = remove
nl_brace_while = remove
nl_switch_brace = remove
nl_multi_line_cond = false
nl_multi_line_define = false
nl_before_case = false
nl_after_case = false
nl_case_colon_brace = force
nl_func_type_name = force
nl_func_proto_type_name = remove
nl_func_paren = remove
nl_func_def_paren = remove
nl_func_decl_start = remove
nl_func_def_start = remove
nl_func_decl_args = remove
nl_func_def_args = remove
nl_func_decl_end = remove
nl_func_def_end = remove
nl_func_decl_empty = remove
nl_func_def_empty = remove
nl_fdef_brace = force
nl_return_expr = remove
nl_after_semicolon = remove
nl_max = 2
nl_before_block_comment = 1
nl_before_c_comment = 1
nl_before_cpp_comment = 1
nl_after_struct = 1
eat_blanks_after_open_brace = true
eat_blanks_before_close_brace = true
mod_full_brace_do = force
mod_remove_extra_semicolon = true
mod_case_brace = remove
mod_remove_empty_return = true
cmt_convert_tab_to_spaces = true
cmt_star_cont = true

0 comments on commit e6d60e2

Please sign in to comment.