| 1 |
Contribution Guidelines |
| 2 |
======================= |
| 3 |
|
| 4 |
Filing an Issue |
| 5 |
--------------- |
| 6 |
|
| 7 |
* Ensure the bug was not already reported by searching GitHub Issues. |
| 8 |
* If you're unable to find an open issue addressing the problem, |
| 9 |
open a new one. Be sure to include a title and clear description, |
| 10 |
as much relevant information as possible, such as Awesome errors, |
| 11 |
and a config sample or an executable test case |
| 12 |
(using Vicious as a stand-alone library) |
| 13 |
demonstrating the expected behavior that is not occurring. |
| 14 |
|
| 15 |
Please re-read your issue once again to avoid a couple of common mistakes |
| 16 |
(you can and should use this as a checklist): |
| 17 |
|
| 18 |
* Is the description of the issue itself sufficient? |
| 19 |
Make sure that it's obvious |
| 20 |
|
| 21 |
* What the problem is |
| 22 |
* How it could be fixed |
| 23 |
* How your proposed solution would look like |
| 24 |
|
| 25 |
* Have you provide the versions of Vicious and related software? |
| 26 |
We would like to how you installed Vicious, which OS you're using, |
| 27 |
the version of the software or what kind of hardware you are trying |
| 28 |
to get information from. |
| 29 |
* Is the issue already documented? |
| 30 |
* Does the issue involve one problem, and one problem only? |
| 31 |
Some people seem to think there is a limit of issues they can or should open. |
| 32 |
There is no limit of issues they can or should open. |
| 33 |
While it may seem appealing to be able to dump all your issues |
| 34 |
into one ticket, that means that someone who solves one of your issues |
| 35 |
cannot mark the issue as closed. |
| 36 |
* Is anyone going to need the feature? Only post features that you |
| 37 |
(or an incapacitated friend you can personally talk to) require. |
| 38 |
Do not post features because they seem like a good idea. |
| 39 |
If they're really useful, they'll be requested by someone who requires them. |
| 40 |
|
| 41 |
Requesting for Merging a Patch |
| 42 |
------------------------------ |
| 43 |
|
| 44 |
#. `Fork this repository`_ |
| 45 |
#. Check out the source code with:: |
| 46 |
|
| 47 |
git clone [email protected]:YOUR_GITHUB_USERNAME/vicious |
| 48 |
cd vicious |
| 49 |
|
| 50 |
#. Start working on your patch. If you want to add a new widget type, |
| 51 |
see the ``templates`` directory for a more detailed guide. |
| 52 |
#. Have a look at ``helpers.lua`` and ``spawn.lua`` |
| 53 |
for possible helper functions. |
| 54 |
#. Make sure your code follows the coding conventions below and check the code |
| 55 |
with ``luacheck``. This *should fail* at first, but you can continually |
| 56 |
re-run it until you're done:: |
| 57 |
|
| 58 |
luacheck --config tools/luacheckrc . |
| 59 |
|
| 60 |
#. Make sure your code works under all Lua versions claimed supported |
| 61 |
by Vicious, namely 5.1, 5.2 and 5.3. |
| 62 |
#. Update the copyright notices of the files you modified. Vicious is |
| 63 |
collectively licensed under GPLv2+, and to protect the freedom of the users, |
| 64 |
copyright holders need to be properly documented. |
| 65 |
#. Try to note your changes under ``CHANGELOG.rst``. If you find it is |
| 66 |
difficult to phrase the changes, you can leave it for us. |
| 67 |
#. Add_ the changes, commit_ them and push_ the result, like this:: |
| 68 |
|
| 69 |
git add widgets/bar_baz.lua README.md |
| 70 |
git commit -m '[bar_baz] Add widget type' |
| 71 |
git add helpers.lua CHANGELOG.rst |
| 72 |
git commit -m '[helpers] Fix foo' |
| 73 |
git push |
| 74 |
|
| 75 |
#. Finally, `create a pull request`_. We'll then review and merge it. |
| 76 |
|
| 77 |
In any case, thank you very much for your contributions! |
| 78 |
|
| 79 |
Coding Conventions |
| 80 |
------------------ |
| 81 |
|
| 82 |
This section introduces a guideline for writing idiomatic, robust |
| 83 |
and future-proof widget type code. |
| 84 |
|
| 85 |
Whitespace in Expressions and Statements |
| 86 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 87 |
|
| 88 |
Avoid extraneous whitespace in the following situations: |
| 89 |
|
| 90 |
* Immediately inside parentheses or brackets. Braces, however, are exceptions |
| 91 |
to this rule: |
| 92 |
|
| 93 |
.. code-block:: lua |
| 94 |
|
| 95 |
foo(bar[1], { baz = 2 }) -- yes |
| 96 |
foo( bar[ 1 ], {baz = 2} ) -- no |
| 97 |
|
| 98 |
* Immediately before a comma, semicolon, or colon. |
| 99 |
* Immediately before the open parenthesis, braces, quote, etc. |
| 100 |
that starts the argument list of a function call; or the open bracket |
| 101 |
that starts an indexing. In other words, prefer these: |
| 102 |
|
| 103 |
.. code-block:: lua |
| 104 |
|
| 105 |
foo(bar, baz) |
| 106 |
foo{ bar, baz } |
| 107 |
foo"bar" |
| 108 |
foo[[bar]] |
| 109 |
foo[bar] |
| 110 |
|
| 111 |
* Trailing at the end of line or (newline) at the end of file. |
| 112 |
|
| 113 |
Always surround these binary operators with a single space on either side: |
| 114 |
assignment (``=``), comparisons, Booleans (``and``, ``or``, ``not``). |
| 115 |
If operators with different priorities are used, consider adding whitespace |
| 116 |
around the operators with the lowest priorities. Use your own judgment; |
| 117 |
however, never use more than one space, and always have |
| 118 |
the same amount of whitespace on both sides of a binary operator. |
| 119 |
|
| 120 |
Indentation |
| 121 |
^^^^^^^^^^^ |
| 122 |
|
| 123 |
Use 4 *spaces* per indentation level. |
| 124 |
|
| 125 |
Continuation lines should align wrapped elements either vertically |
| 126 |
inside parentheses, brackets and braces, or using a hanging indent |
| 127 |
(the opening parenthesis of a parenthesized statement is the last |
| 128 |
non-whitespace character of the line, with subsequent lines being indented |
| 129 |
until the closing parenthesis), e.g. |
| 130 |
|
| 131 |
.. code-block:: lua |
| 132 |
|
| 133 |
-- Vertically aligned |
| 134 |
long_function_call{ foo, bar, |
| 135 |
baz } |
| 136 |
|
| 137 |
-- Hanging indentation |
| 138 |
long_function_call( |
| 139 |
foo, bar |
| 140 |
baz) |
| 141 |
|
| 142 |
The closing brace or bracket on multi-line constructs may either line up under |
| 143 |
the first character of the line that starts the construct, as in: |
| 144 |
|
| 145 |
.. code-block:: lua |
| 146 |
|
| 147 |
long_function_call{ |
| 148 |
foo = 1, bar = 2, |
| 149 |
baz = 3, |
| 150 |
} |
| 151 |
|
| 152 |
In this case, and this case only, the trailing comma is acceptable |
| 153 |
to avoid diff noises when more values are added, |
| 154 |
but since Vicious often deal with system APIs which rarely ever change, |
| 155 |
it's occasionally helpful to do so. |
| 156 |
|
| 157 |
Trailing right parentheses, however, are not allowed. |
| 158 |
|
| 159 |
Maximum Line Length |
| 160 |
^^^^^^^^^^^^^^^^^^^ |
| 161 |
|
| 162 |
If possible, try to limit all *code* lines to a maximum |
| 163 |
of 80 characters. In case you find some lines in your patch would be |
| 164 |
more readable exceeding this limit, feel free to discuss with us. |
| 165 |
Comments and long strings need not to follow this restriction however. |
| 166 |
|
| 167 |
As one might have noticed, the syntactic sugars ``f{<fields>}`` |
| 168 |
(for ``f({<fields>})``) and ``f'<string>'`` |
| 169 |
(or ``f"<string>"``/``f[[<string>]]``, for ``f('<string>')``) |
| 170 |
are especially preferred to squeeze the line length to this limit. |
| 171 |
|
| 172 |
Blank Lines |
| 173 |
^^^^^^^^^^^ |
| 174 |
|
| 175 |
Surround function definitions with a single blank line. Extra blank lines |
| 176 |
may be used (sparingly) to separate groups of related functions. |
| 177 |
Blank lines may be omitted between a bunch of related one-liners |
| 178 |
(e.g. a set of dummy implementations). |
| 179 |
Use blank lines in functions, sparingly, to indicate logical sections. |
| 180 |
|
| 181 |
Requiring Libraries |
| 182 |
^^^^^^^^^^^^^^^^^^^ |
| 183 |
|
| 184 |
All standard libraries should be localized before used |
| 185 |
for the matter of performance. |
| 186 |
|
| 187 |
``require``'s should always be put at the top of the source file, |
| 188 |
just after the copyright header, and before module globals and constants, |
| 189 |
and grouped in the following order: |
| 190 |
|
| 191 |
1. Standard libraries |
| 192 |
2. Related third-party libraries |
| 193 |
3. Local libraries |
| 194 |
|
| 195 |
For example, |
| 196 |
|
| 197 |
.. code-block:: lua |
| 198 |
|
| 199 |
local type = type |
| 200 |
local table = { concat = table.concat, insert = table.insert } |
| 201 |
|
| 202 |
local awful = require("awful") |
| 203 |
|
| 204 |
local helpers = require("vicious.helpers") |
| 205 |
|
| 206 |
String Quotes |
| 207 |
^^^^^^^^^^^^^ |
| 208 |
|
| 209 |
In Lua, single-quoted strings and double-quoted strings are the same, |
| 210 |
so the choice is totally up to you, but please be consistent within a module. |
| 211 |
When a string contains single or double quote characters, however, |
| 212 |
use the other one to avoid backslashes in the string. It improves readability: |
| 213 |
|
| 214 |
.. code-block:: lua |
| 215 |
|
| 216 |
'"key": "value"' -- good |
| 217 |
"\"key\": \"value\"" -- no good |
| 218 |
|
| 219 |
It is preferable to add a newline immediately after the opening long bracket: |
| 220 |
|
| 221 |
.. code-block:: lua |
| 222 |
|
| 223 |
foo = [[ |
| 224 |
this is a really, |
| 225 |
really, |
| 226 |
really long text]] |
| 227 |
|
| 228 |
Naming Conventions |
| 229 |
^^^^^^^^^^^^^^^^^^ |
| 230 |
|
| 231 |
Avoid using the characters ``l`` (lowercase letter el), |
| 232 |
``O`` (uppercase letter oh), or ``I`` (uppercase letter eye) |
| 233 |
as single character variable names. In some fonts, these characters |
| 234 |
are indistinguishable from the 1's and 0's. |
| 235 |
|
| 236 |
Constants |
| 237 |
""""""""" |
| 238 |
|
| 239 |
Constants are usually defined on a module level |
| 240 |
and written in all capital letters with underscores separating words. |
| 241 |
Examples include ``MAX_OVERFLOW`` and ``TOTAL``. |
| 242 |
|
| 243 |
Function and Variable Names |
| 244 |
""""""""""""""""""""""""""" |
| 245 |
|
| 246 |
Function names should be lowercase, with words separated by underscores |
| 247 |
as necessary to improve readability. |
| 248 |
|
| 249 |
Variable names follow the same convention as function names. |
| 250 |
|
| 251 |
When you find it difficult to give descriptive names, |
| 252 |
use the functions and variable anonymously. |
| 253 |
|
| 254 |
Performance Tips |
| 255 |
^^^^^^^^^^^^^^^^ |
| 256 |
|
| 257 |
Vicious is meant to be run as part of the Awesome window manager, |
| 258 |
thus any little overhead may defect the responsiveness of the UI. |
| 259 |
While Lua is famous for its performance, there are a few things |
| 260 |
one can do to make use of all of its power. |
| 261 |
|
| 262 |
**Never** use global variables. This includes the standard libraries, |
| 263 |
which, again, must be localized before use. Remember, every widget type |
| 264 |
is to be called repeatedly every few seconds. |
| 265 |
|
| 266 |
Use closures when possible: |
| 267 |
|
| 268 |
* Define constants on the module level. |
| 269 |
* Avoid re-fetching the values that are not not meant to change. |
| 270 |
|
| 271 |
However, declare a variable only when you need it, to avoid declaring it |
| 272 |
without an initial value (and therefore you seldom forget to initialize it). |
| 273 |
Moreover, you shorten the scope of the variable, which increases readability. |
| 274 |
|
| 275 |
Copyright Header |
| 276 |
^^^^^^^^^^^^^^^^ |
| 277 |
|
| 278 |
Vicious is released under the GNU GNU General Public License |
| 279 |
version 2 or later and each contributor holds the copyright |
| 280 |
on their contributions. To make this collective control effective, |
| 281 |
each source file must include a notice of the following format |
| 282 |
denoting the name of all authors |
| 283 |
|
| 284 |
.. code-block:: lua |
| 285 |
|
| 286 |
-- <one line to give the program's name and a brief idea of what it does.> |
| 287 |
-- Copyright (C) <year> <name of author> <<email that can be use for contact>> |
| 288 |
-- |
| 289 |
-- This file is part of Vicious. |
| 290 |
-- |
| 291 |
-- Vicious is free software: you can redistribute it and/or modify |
| 292 |
-- it under the terms of the GNU General Public License as |
| 293 |
-- published by the Free Software Foundation, either version 2 of the |
| 294 |
-- License, or (at your option) any later version. |
| 295 |
-- |
| 296 |
-- Vicious is distributed in the hope that it will be useful, |
| 297 |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 298 |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 299 |
-- GNU General Public License for more details. |
| 300 |
-- |
| 301 |
-- You should have received a copy of the GNU General Public License |
| 302 |
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 303 |
|
| 304 |
Comments |
| 305 |
^^^^^^^^ |
| 306 |
|
| 307 |
Comments that contradict the code are worse than no comments. |
| 308 |
Always make a priority of keeping the comments up-to-date when the code changes! |
| 309 |
|
| 310 |
You should use two spaces after a sentence-ending period |
| 311 |
in multi-sentence comments, except after the final sentence. |
| 312 |
|
| 313 |
Block Comments |
| 314 |
"""""""""""""" |
| 315 |
|
| 316 |
Block comments generally apply to some (or all) code that follows them, |
| 317 |
and are indented to the same level as that code. Each line of a block comment |
| 318 |
starts with ``--`` and a single space, unless text inside the comment |
| 319 |
is indented, or it is to comment out code. |
| 320 |
|
| 321 |
Paragraphs inside a block comment are separated by a line containing |
| 322 |
``--`` only. The best example is the copyright notice in the section above. |
| 323 |
|
| 324 |
The ``--[[...]]`` style may only be used for commenting out source code. |
| 325 |
|
| 326 |
Inline Comments |
| 327 |
""""""""""""""" |
| 328 |
|
| 329 |
An inline comment is a comment on the same line as a statement. |
| 330 |
Inline comments should be separated by at least two spaces from the statement. |
| 331 |
They should start with ``--`` and one single space. |
| 332 |
|
| 333 |
Influences |
| 334 |
---------- |
| 335 |
|
| 336 |
These contributing guideline are heavily influenced by that of ``youtube-dl``, |
| 337 |
PEP 8, Programming in Lua and the performance tips in Lua Programming Gems. |
| 338 |
|
| 339 |
.. _Fork this repository: https://github.com/vicious-widgets/vicious/fork |
| 340 |
.. _Add: https://git-scm.com/docs/git-add |
| 341 |
.. _commit: https://git-scm.com/docs/git-commit |
| 342 |
.. _push: https://git-scm.com/docs/git-push |
| 343 |
.. _create a pull request: |
| 344 |
https://help.github.com/articles/creating-a-pull-request |