Objects serialization

Some plugins like jmespath apply their actions against object-serialized version of files. Also, the style files itself parsed by project-config to execute the rules are serialized to objects.

This is really convenient for configuration files because the most common files formats like JSON, TOML or YAML can be converted into a map (dictionary in Python, object in Javascript) to perform operations against the structured nodes.

The serialization process of project-config converts strings to Python dictionaries using loader functions depending on the format of the files. The format is discovered, based mostly on file names, using identify.

The next formats are currently supported:

JSON

JSON5

YAML (v1.2)

TOML (v1)

INI

Editorconfig

The root directive, if exists, will be added in an empty string key "" object:

root = true

[*]
end_of_line = lf
charset = utf-8
indent_style = space
trim_trailing_whitespace = true

Python

For Python files, the global namespace is exposed after executing the file in a Python dictionary, including the key __file__ with the script file path.

bar = "baz"

Tip

project-config CLI sets the environment variable PROJECT_CONFIG while is running, which is useful if you want to expose the global namespaces of scripts only when the tool is running.

Text

Fallback for all serialized files. Just converts the string to an array of lines, excluding line endings.

bar
baz