Skip to content

Development Guidelines

Steve Hillier edited this page Mar 22, 2018 · 6 revisions

GWELLS Development Guidelines

To ensure that future additions to the code base are continuously improving the overall code quality, please follow these guidelines:

Python

  • Follow PEP-8 Style Guide for basic guidelines on style and organization. This includes using 4 spaces instead of tabs for indents, using upper case for class names (e.g. MyClassName()), and using lower case with underscores for functions and variables (e.g. my_function_name() and my_variable_name).
  • Enable PEP-8 linting in your IDE.
  • Further suggestions:
    • PEP-8 suggests a 79 character line limit, but that is difficult to work within. GitHub can display up to 110-120 characters per line for reviewing changes (depending on browser), so please wrap long lines before reaching this length.

Django

  • In general, follow conventions in Django's official documentation or Two Scoops of Django 1.11 (a copy available in lab)
  • Project-specific guidelines (common things that might come up working on GWELLS):
    • Model fields: blank=True, null=True - do not set both at once. Please set blank=True for CharFields instead of null=True.
    • Model ForeignKey relationship: on_delete - in general, use models.SET_NULL unless the table absolutely depends on the parent's existence.

Django unit tests

  • Tests: to run Django tests, use python manage.py test -c nose.cfg. When submitting any new code or features, please include unit tests in your pull request.

Vue / JavaScript

  • The Vue community tends to use the "Standard" style guide. Some of the most obvious differences between Standard and AirBNB are no semi-colons, and a space between function names and parentheses - e.g., function () { ... }. Running npm install in the frontend folder will automatically install a linter with Standard rules.
  • Use single file components when it makes sense. For example, a modal that can be re-used on other pages, or clearly separated sections of a single page (header, footer etc).
  • Run tests with npm run test or npm run watch (auto-watch files and run tests on files that you change)

Vue unit tests

  • Vue unit tests use Jest and vue-test-utils. Refer to the current tests or the documentation for each for guidance on writing more.
  • The general workflow for writing a test is to shallow render a component (render one component and its immediate child components only), then search for the tag or id's in the HTML (wrapper.find("p")) or inspect the Vue instance data (wrapper.vm.myVariable).
Clone this wiki locally