Skip to content

How to add a check?

Corentin Bettiol edited this page Nov 18, 2019 · 14 revisions

Each of our checks is a file located in the /path/to/your/site-packages/django-check-seo/checks/ folder (see wiki - How does it work?), and need to follow some guidelines:


Functions

importance()

This is the function that tells launch_checks if the current check must be performed before the others, or if it doesn't matter.

Its sole purpose is to return an int (the recommended use is between 1 and 5).

The higher the number, the faster the function will be executed.

Since check_keywords populates the site.keywords var, it need to be executed before all the functions that will use site.keywords var.

run()

This is the main function of your file, the one that will do the check and that will populate the site.warnings and/or site.problems lists.


Problems & warnings

coming soon (the code will soon change, I don't want to write something obsolete)


Custom checks

The launch_checks.py file tries to import the checks folder located in your django project.

If it does not exist, nothing happens.

If it exists, it will execute the important & run functions in each of the modules that start with checks.. To properly reference the modules, you will need to create a __init__.py file in your folder (otherwise there will be checks in sys.modules, and not checks.yourmodule).

__init__.py

# Standard Library
import glob
from os.path import basename, dirname, isfile, join
import sys, json

from django.conf import settings

# list files
modules = glob.glob(join(dirname(__file__), "*.py"))

__all__ = []

# add them to __all__ so they can be imported
for module in modules:
    if (
        isfile(module)
        and not module.endswith("__init__.py")
    ):
        __all__.append(basename(module)[:-3])

Example of configuration:

image


Wanna see a check example?

Take a look at the check_h1.py files to understand how checks are managed.


Content

If you want to know the reasons why we chose these checks in particular.

Checks that are not included inside the project


Code

Clone this wiki locally