Configuring Spotless

Spotless is configured using a JSON object called the config.

It is structured as follows:

An example rule to process a single field called "Name", and remove blanks records is shown below:

config = {

"rules": [
	{
		"rule_type": "String",
		"field": "Name"
		"params": {
			"fallback_mode": "remove_record",
			"maximum_length": 65536,
			"minimum_length": 1
		},
	}
]

},

The parameters vary according to the type of rule. The following values for "rule_type" are supported:

Validating basic data types

The basic data type validation rules are String, Number, and Date.

rule_type: "String"

String rules validates a field as a string, according to its length and optionally using a regular expression.

It takes the following parameters:

The example below validates that a string is between 1 and 40 characters and contains only alphanumeric characters:

config = {"rules": [
	{
		"rule_type": "String",
		"field": "Name"
		"params": {
			"fallback_mode": "remove_record",
			"maximum_length": 65536,
			"minimum_length": 1,
			"regex": "[/w/d]*"
		},
	}
]},

rule_type: "Number"

Number rules validates a field as a number, according to the number of decimal places and its size.

It takes the following parameters:

The example below validates that a number is between 0 and 255 and contains no decimal places. Any invalid decimal places are fixed automatically.

config = {"rules": [
	{
		"rule_type": "Number",
		"field": "Name"
		"params": {
			"fallback_mode": "remove_record",
			"minimum_value": 0,
			"maximum_value": 255,
			"decimal_places": 0,
			"fix_decimal_places": True
		},
	}
]},

rule_type: "Date"

Date rules validate the field as a date, date format and the range of the dates.

It takes the following parameters:

The example below validates that a date is in epoch time and within the last week of whenever the rule is run:

config = {"rules": [
	{
		"rule_type": "Date",
		"field": "Name"
		"params": {
			"fallback_mode": "remove_record",
			"date_format": "%s",
			"range_check": "rolling",
			"range_minimum": -7,
			"range_maximum": 0
		},
	}
]},