Skip to content

float-style

GitHub ActionsYAMLstylefix: safedefault: off

Restricts how plain floats are written. Every option is off until set: require_numeral_before_decimal reports .5, forbid_scientific_notation reports 1e3, forbid_nan reports .nan and forbid_inf reports .inf. Quoted and tagged scalars are not checked. The fix for .5 is 0.5.

YAML 1.1 and 1.2 parsers read some float spellings differently (1e3 is a string in YAML 1.1, since it requires a dot), and .5 is hard to see. A project can choose the spellings that every parser it uses reads the same way.

Reported
x: .5
y: 0.5
z: 1e3
After the fix
x: 0.5
y: 0.5
z: 1e3
github-actions:
lint:
rules:
float-style:
level: warn # off (default), warn, error
options:
require_numeral_before_decimal: false
forbid_scientific_notation: false
forbid_nan: false
forbid_inf: false
yaml:
lint:
rules:
float-style:
level: warn # off (default), warn, error
options:
require_numeral_before_decimal: false
forbid_scientific_notation: false
forbid_nan: false
forbid_inf: false
Option Type Default Description
require_numeral_before_decimal bool false Report .5, -.5e3: a digit must come before the decimal point.
forbid_scientific_notation bool false Report 1e3, 1.5E-2, .5e3.
forbid_nan bool false Report .nan, .NaN, .NAN.
forbid_inf bool false Report .inf, -.Inf, +.INF.

Suppress one line with sudsy-disable-next-line float-style in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
yamllint float-values full
yamllint float-values.forbid-inf / forbid-nan / forbid-scientific-notation / require-numeral-before-decimal full