Nonbreaking Space in Units

Description

This rule checks for proper spacing between numbers and their units of measurement. It ensures that numbers and their corresponding units (like MB, GB, or time units) are connected with a nonbreaking space. This is important because it prevents awkward line breaks where the number and its unit might get separated across different lines, which can harm readability and potentially cause confusion.

The rule follows the Google Developer Documentation Style Guide's recommendations for handling units of measure, ensuring consistency and professional presentation in technical documentation.

Examples

Will flag these (incorrect):

  • 500MB (needs nonbreaking space)
  • 10s (needs nonbreaking space)
  • 2GB (needs nonbreaking space)
  • 30min (needs nonbreaking space)

Should be written as:

  • 500 MB (with nonbreaking space)
  • 10 s (with nonbreaking space)
  • 2 GB (with nonbreaking space)
  • 30 min (with nonbreaking space)

The rule checks for both data units (B, kB, MB, GB, TB) and time units (ns, ms, s, min, h, d).

Rule Source

This rule comes from: https://github.com/jump-dev/JuMP.jl

Rule Definition

extends: existence
message: "Put a nonbreaking space between the number and the unit in '%s'."
link: 'https://developers.google.com/style/units-of-measure'
nonword: true
level: error
tokens:
  - \d+(?:B|kB|MB|GB|TB)
  - \d+(?:ns|ms|s|min|h|d)