FontBakery uses dependency injection to pass objects to your check functions. The check runner looks at your function's parameter names and matches them to 'conditions' (cached properties) on the Testable object (like Font or Ufo) or the CheckRunContext.
Recommended Patterns
While you can use 'clever' short-cuts, it is best practice to be explicit to avoid undefined behavior when multiple testable types share condition names.
- Explicit (Recommended): Use
font or ufo as parameters and call conditions as methods on them. - Short-cut (Common): Use
ttFont as a parameter to receive the parsed TTFont object directly. - Context-wide checks: Use parameters like
fonts or ttFonts to receive collections of files from the CheckRunContext for cross-file validation. - Context awareness: Use
context as a parameter to access the CheckRunContext from within a specific testable object.
# Explicit pattern (Recommended)
@check(id="my_check")
def check_my_logic(font: Font):
ttFont = font.ttFont
# ...
# Short-cut pattern (Common for TTFont checks)
@check(id="my_check")
def check_my_logic(ttFont):
# ...
# Collection pattern (For checking all files)
@check(id="check_all")
def check_all_same_family(fonts):
# 'fonts' is a list of Font objects
pass
# Context pattern
@check(id="check_context")
def check_with_context(ttFont, context):
# 'context' is the CheckRunContext
pass