phergie / phergie-irc-bot-react

IRC bot built on React
BSD 2-Clause "Simplified" License
81 stars 27 forks source link

Add CONTRIBUTING.md file #20

Closed elazar closed 9 years ago

Renegade334 commented 9 years ago

We need a style guide!

Established:

To be discussed:

elazar commented 9 years ago
Renegade334 commented 9 years ago

PSR-2#6 prescribes function ($args) use ($vars) {, which I personally prefer, rather than function($args) {.

With arrays, my own personal projects use array() for initialising and closing multi-line declarations (one key=>value pair per line, with commas, including the last pair), square braces for the empty array [] and single-line "list" array declarations, and avoid declaring single line associative arrays with key=>value pairs. I'm pretty sure this isn't very common, and I'm sure most would advocate using one syntax consistently.

Also, the empty array could be [], [ ], array() or array( ).

Oh, and we need an opinion on whether or not the double-arrow => should be aligned, and if so, how!

elazar commented 9 years ago

PSR-2#6 prescribes function ($args) use ($vars) {, which I personally prefer, rather than function($args) {.

Since pursuing that would allow us to use any PSR-2-compatible tools, I'm OK with that argument. If we want to pursue PSR-2 adherence, I'd suggest filing another issue that covers any changes resulting from running an evaluation tool against all the current repos and linking that issue from here.

With arrays, my own personal projects use array() for initialising and closing multi-line declarations (one key=>value pair per line, with commas, including the last pair), square braces for the empty array [] and single-line "list" array declarations, and avoid declaring single line associative arrays with key=>value pairs. I'm pretty sure this isn't very common, and I'm sure most would advocate using one syntax consistently.

I'd agree consistency using [] is probably best, but otherwise, we're in agreement: one line per pair, single line is permissible if an assigned array only contains a single pair, and for multi-line assignments all lines including the last should have a trailing comma.

Also, the empty array can be represented as [], [ ], array() and array( ). I use the first, but the second is suddenly appealing...

I've tended to use [] for empty arrays, [ 'key' => 'value' ] with spaces for single element assignments, but I'm open to switching to [ ] for consistency.

Oh, and we need an opinion on whether or not the double-arrow => should be aligned, and if so, how!

I've tended not to align it. I'm skeptical that it actually lends to readability well enough to justify the effort it takes to implement it. I'll entertain arguments for other views, though. :)

elazar commented 9 years ago

For issues that impact many or all repos (e.g. those affecting configuration files for testing common to all repos), we should probably specify that they should be filed against either this repo or some other repo dedicated to that purpose.

enebe-nb commented 9 years ago

I was configuring php-cs-fixer, since i have a few problems to follow others' standards, and got this configuration:

/*      // This must be used with 'header_comment', but then a config file is needed for each repository
$header = <<<EOF
Phergie (http://phergie.org)

@link http://github.com/phergie/phergie-irc-bot-react for the canonical source repository
@copyright Copyright (c) 2008-2015 Phergie Development Team (http://phergie.org)
@license http://phergie.org/license Simplified BSD License
@package Phergie\Irc\Bot\React
EOF;

Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);
*/

return Symfony\CS\Config\Config::create()
    // All PSR-1 and PSR-2 fixers are included here.
    ->level(Symfony\CS\FixerInterface::PSR2_LEVEL)

    ->fixers([
        //  Accepted styling
        'short_array_syntax',               // Arrays should use the PHP 5.4 short-syntax.
        'multiline_array_trailing_comma',   // Multi-line arrays should have a trailing comma.
        'single_array_no_trailing_comma',   // Single-line arrays should not have trailing comma.
        'unalign_double_arrow',             // Unalign double arrow symbols.

        //  Suggested styling
        //'single_quote',                   // ? Convert double quotes to single quotes for simple strings.
        'standardize_not_equal',            // Replace all <> with !=.
        'unalign_equals',                   // Unalign equals symbols.
        'unused_use',                       // Unused use statements must be removed.
        'whitespacy_lines',                 // Remove trailing whitespace at the end of blank lines.

        //  Non-essential styling
        //'header_comment',                 // ? Set header comment from this file on php files
        'phpdoc_order',                     // Annotations in phpdocs should be ordered so that param annotations come first, then throws annotations, then return annotations.
    ])

    ->finder(
        Symfony\CS\Finder\DefaultFinder::create()
            ->in(__DIR__.'/src')
    );

This is not a final configuration, and there others thing to add if you like, i just got the minimal structure based on this discutions and code reading. Also, i added some some coding stardard sugestions to be formally accepted, most of them are already use as i could see, the exception is 'single_quote' that was caught in some script's runs.

Finally the 'non-essential' are things that could be used in .php_cs, but don't need to be explained in a Contribuition file. In case of 'header_comment' i don't recommend use it, because this way must be a configuration file for every phergie project, i just thought this could get your interest.

Naming style can't be handled by the script and (probably) use the following style:

[NOTE] I don't think this configuration file must be in all projects, but maybe in scafolding this will help.

elazar commented 9 years ago

@enebe-nb Awesome, thanks for putting this together!

@phergie/owners Any comments from the peanut gallery?

svpernova09 commented 9 years ago

This looks good to me. We should include the cs-fixer-file in the repo IMHO and even configuring an .editorconfig file to show this stuff in real time.

matthewtrask commented 9 years ago

Im in agreement with @svpernova09

svpernova09 commented 9 years ago

Weighing in here. My personal preference is PSR-2 and outside of that whatever is best for readability, where that can be subjective I would lean towards established conventions unless otherwise talked out of it.

Established:

What I would like see us agree on:

To be discussed:

Should there be a unified convention for naming custom events, or should plugin developers be free to name them at their discretion?

I agree with @elazar on "event names follow the convention namespace.subnamespace.event"

Indentation of chained method calls ($foo->setBar($bar)->setBaz($baz)->setQuux($quux);)

IMHO I almost alwys prefer to chain these after the first chained call.

Example:

$foo->setBar($bar)
    ->setBaz($baz)
    ->setQuux($quux);

Should all setters be chainable as a convention?

I have no opinion here.

Indentation of multi-line condition statements? Should the parentheses of multi-line condition statements be inline, or be proceeded/preceded by newlines?

IMHO the parentheses of multi-line condition statements should be in line. The whitespace by newlines I find can be distracting.

Should the operator be appended to the end of the previous line, or prepended to the front of the next line?

I really prefer the operating prepended to the front of the next line so you can read left -> right -> top -> bottom and easily see what's happening.

Example:

$sentence = $greeting
    . $comma
    . $space
    . $name
    . $period;
svpernova09 commented 9 years ago

Once we've nailed down the code style we should look into https://styleci.io/ for automatic checking for PRs and such.

Might be easier / cheaper (since Style-CI isn't free) to add something to check via travis

enebe-nb commented 9 years ago
  • As stated in PSR-2#6 Closures would appear function ($args) use ($vars) {

I think this is already accepted, since everyone agrees we should follow PSR-2.

  • Array syntax is [] or [ 'key' => 'value' ]

About the empty array, both elazar and renegate are using [] so i see no reason to change to [ ] now. Also cs-fixer converts array() to [], so its easier to use this style.

Once we've nailed down the code style we should look into https://styleci.io/ for automatic checking for PRs and such.

Might be easier / cheaper (since Style-CI isn't free) to add something to check via travis

The cs-fixer already converts the coding, the only problem is run it after merge a pull request (or before). And we can create customs filters for it (when a builtin filter is not avaliable), i just don't recommend use filters that can change the code behaviour. Pick your choices on styling and on a moment i have time i can edit the configuration.

svpernova09 commented 9 years ago

Updating our progress so far:

Established:

To be discussed:

Indentation of chained method calls ($foo->setBar($bar)->setBaz($baz)->setQuux($quux);)

IMHO I almost alwys prefer to chain these after the first chained call.

Example:

$foo->setBar($bar)
    ->setBaz($baz)
    ->setQuux($quux);

If anyone would like to raise issue with anything we have established so far please feel free to do so.

localheinz commented 9 years ago

For reference, maybe have a look at this configuration here: https://github.com/refinery29/php-cs-fixer-config.

svpernova09 commented 9 years ago

Closing the discussion here, please review initial CONTRIBUTING.md contained here: https://github.com/phergie/phergie-irc-bot-react/pull/38