Docs
Checks
conditional

conditional

Learn about the conditional extension point.

NameTypeDescription
ignorecaseboolMakes all matches case-insensitive.
firststringThe antecedent of the statement.
secondstringThe consequent of the statement.
vocabboolIf false, disables all active vocabularies for this rule (default: true).
exceptionsarrayAn array of strings to be ignored.
yaml
extends: conditional message: "'%s' has no definition" level: error scope: text ignorecase: false # Ensures that the existence of 'first' # implies the existence of 'second'. first: '([A-Z]{3,5})' second: '(?:[A-Z][a-z]+ )+(([A-Z]{3,5}))' # ... with the exception of these: exceptions: - ABC - ADD

For example, consider the following text:

According to Wikipedia, the World Health Organization (WHO) is a specialized agency of the United Nations that is concerned with international public health. We can now use WHO because it has been defined, but we can’t use DAFB because people may not know what it represents. We can use DAFB when it’s presented as code, though.

Using the above text with our example rule yields the following:

bash
test.md:1:224:style.UnexpandedAcronyms:'DAFB' has no definition

conditional also takes an optional exceptions list. Any token listed as an exception won’t be flagged.

Lookarounds

Regular expression lookarounds can be used to restrict the capture of the rule, allowing for more complex conditional statements. For example, the following rule will flag any MDX-style import that is not used:

yaml
extends: conditional message: "'%s' has been imported but not used." level: error scope: raw first: "(?<=import )(w+)(?= from)" second: '(?<=<)(w+)'

See the regex guide for more information.