Skip to content

Latest commit

 

History

History
121 lines (103 loc) · 3.37 KB

CONTRIBUTING.md

File metadata and controls

121 lines (103 loc) · 3.37 KB

Gnome.org requires that extensions have roughly the same styles.

Here are a few important ones and their explanations.
NOTE: This doc is best viewed in markdown and not as plaintext

  1. Statements must end a semicolon (even if it runs properly without it)
  2. Lines must not have any extra space at the end (including blank lines)
  3. Use 4 spaces instead of tabs
  4. Switch statements and their cases must be at the same indent level
    // good
    switch (direction) {
    case 'left':
        doStuff();
    }
    
    // bad
    switch (direction) {
        case 'left':
            doStuff();
    }
        
  5. If statements and their curly braces must have a space between them
  6. If statements and their else block that only have a single command must not be surrounded with curly braces.
    // good
    if ( user.age > 21 )
        user.canDrink = true;
    
    // bad
    if ( user.age > 18 ) {
        user.canSmoke = true;
    }
  7. Multi-line objects must have a trailing comma as if there was another element
    var goodObject = {
        firstElement: 1, // <--- trailing comma
    };
    
    var badObject = {
        onlyElement: 1
    }
  8. Use camelCase names instead of snake_case_names
    var goodName; // good
    var bad_name; // bad
  9. Strings MUST be single quoted
    var blah = 'I\'m a single quoted string'; // good
    var blah = "I'm a double quoted string"; // bad 
  10. Use backtick interpolation instead of concatenation
    var builtString = `Hello, ${useName}!`; // good
    var concatString = 'Hello, ' + userName + '!'; // bad
  11. Functions must have jsdoc strings that give the variable name, type, and explanation for EACH variable
    // good example
    /**
     *
     * @param {object} app - the window object
     * @param {number} x - desired x value
     * @param {number} y - desired y value
     * @param {number} w - desired width
     * @param {number} h - desired height
     */
    function moveAppCoordinates(app, x, y, w, h) {
    .....
  12. Comparisons must use 3 signs instead of 2. ( === and !== instead of == and != )
    // good
    log( firstName === 'Weadababy' );
    
    // bad
    log( lastName == 'Eetzaboi' );

It's highly suggested that you lint your code with the .eslintrc.yml we included in the base of the repo with the --fix option before submitting Pull requests. Pull requests that fail the lint test will not be accepted and must be fixed before consideration.

I also suggest adding this .git/hooks/pre-commit to your copy of the repo.

#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
ESLINT="node_modules/.bin/eslint"
pwd

if [[ ! -x "$ESLINT" ]]; then
  printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n"
  exit 1
fi

STAGED_FILES=($(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$"))

echo "ESLint'ing ${#STAGED_FILES[@]} files"

if [[ "$STAGED_FILES" = "" ]]; then
  exit 0
fi

$ESLINT "${STAGED_FILES[@]}" --fix

ESLINT_EXIT="$?"

# Re-add files since they may have been fixed
git add "${STAGED_FILES[@]}"

if [[ "${ESLINT_EXIT}" == 0 ]]; then
  printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n"
else
  printf "\n\033[41mCOMMIT FAILED:\033[0m Fix eslint errors and try again\n"
  exit 1
fi

exit $?