# Main Convention Kossie main convention, this will rules out any conflicting rules. This rules will always prevail. ## Table of Contents 1. [Basic](#basic) 1. [Coding Convention](#coding-convention) 1. [React: Defining Javascript](#defining-javascript) 1. [React: Defining getserverside](#define-gerserverside-or-other-nextjs-server-function-before-creating-component) 1. [React: Declare Constant](#declare-constant) 1. [Python: Import python](#import-within-python) 1. [Python: don't use tab use space](#dont-use-tab-use-space) 1. [Python: Docstring](#docstring-and-documentation) ## Basic Basic graphql and admin: * for graphql sandbox: use `localhost:8000/sandbox/` * for create admin : `python manage.py createsuperuser` ## Coding Convention Unless stated, below are coding convention for respective language, you can find in this docs: * Python : PEP-8 * React : Airbnb coding convention https://airbnb.io/javascript/react/ # React ### Defining javascript Graphql code must defined under the query/mutation unless it takes a lot of lines (more than 10 lines) or will be reused ```js // ✓ YES client.query ({ query: gql` some graphql code`, // ... }) // X NO const someQuery=gql` ... ` client.query({ query: someQuery, // ... }) ``` ### Define gerServerSide or other nextjs server function before creating component Each function must be define on top of the code ```js // ✓ YES async function getServerSide(ctx){ //... } export default function SomeComponent{ //... } // X NO export default function SomeComponent{ //... } async function getServerSide(ctx){ //... } ``` ### Declare Constant Unless const is not for function or component , need to be defined with capital case ```js const DEFAULT_VALUE = 3 // ✓ YES const DEFAULT_FUNCTION = () => { ... } // X NO const defaultFunction = ()=>{ ... } // X NO ``` # Python ### import within python import python with rules: 1. python library import 1. django import (using `form ... import ...` ) 1. third party import 1. app model import This is to make sure easy to discern what libraries are imported and prevent duplication. ```python import datetime from django.conf import settings from django.contrib import auth from thirdparty.dev import dev from your.custom import models ``` ### Don't use tab use space Indentation always use 4 spaces instead of tab. ### docstring and documentation Documentation using google style docstring, as the following example ```python class ExampleClass(object): """The summary line for a class docstring should fit on one line. If the class has public attributes, they may be documented here in an ``Attributes`` section and follow the same formatting as a function's ``Args`` section. Alternatively, attributes may be documented inline with the attribute's declaration (see __init__ method below). Properties created with the ``@property`` decorator should be documented in the property's getter method. Attributes: attr1 (str): Description of `attr1`. attr2 (:obj:`int`, optional): Description of `attr2`. """ attr3 = "test" #: Doc comment *inline* with attribute #: list of str: Doc comment *before* attribute, with type specified attr4 = "test" def __init__(self, param1, param2, param3): # documented always after class declaration self.attr1 = param1 self.attr2 = param2 self.attr3 = param3 @property def readonly_property(self): """str: Properties should be documented in their getter method.""" return 'readonly_property' @property def readwrite_property(self): """:obj:`list` of :obj:`str`: Properties with both a getter and setter should only be documented in their getter method. If the setter method contains notable behavior, it should be mentioned here. """ return ['readwrite_property'] @readwrite_property.setter def readwrite_property(self, value): value def example_method(self, param1, param2): """Class methods are similar to regular functions. Note: Do not include the `self` parameter in the ``Args`` section. Args: param1: The first parameter. param2: The second parameter. Returns: True if successful, False otherwise. """ return True ```