### Configure yamlfix via pyproject.toml Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Shows an example of how to configure yamlfix using the `pyproject.toml` file. Settings are placed under the `[tool.yamlfix]` section. ```toml # pyproject.toml [tool.yamlfix] allow_duplicate_keys = true line_length = 80 none_representation = "null" ``` -------------------------------- ### Toggle Explicit Document Start Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Enables or disables the inclusion of the '---' document start marker in the generated YAML output. ```bash export YAMLFIX_EXPLICIT_START="true" ``` -------------------------------- ### Configure yamlfix via .yamlfix.toml Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Provides an example of configuring yamlfix using a dedicated `.yamlfix.toml` file. This file should contain only yamlfix-specific settings without section headers. ```toml # .yamlfix.toml allow_duplicate_keys = true line_length = 80 none_representation = "null" ``` -------------------------------- ### Set configuration via environment variables Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Examples of overriding default yamlfix settings using environment variables. ```bash export YAMLFIX_ALLOW_DUPLICATE_KEYS="true" export YAMLFIX_COMMENTS_MIN_SPACES_FROM_CONTENT="2" export YAMLFIX_COMMENTS_REQUIRE_STARTING_SPACE="true" export YAMLFIX_WHITELINES="0" ``` -------------------------------- ### Example: Preserve Quotes with Quote Keys and Basic Values Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Illustrates the combined effect of preserve_quotes and quote_keys_and_basic_values. This example shows how keys and values are quoted while attempting to respect existing quotes. ```yaml # original key: [value, 'value with spaces'] ``` ```yaml # preserve_quotes = true # quote_keys_and_basic_values = true # quote_representation = " "key": ["value", 'value with spaces'] ``` -------------------------------- ### Install yamlfix using pip Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Installs the yamlfix package using pip. This is the standard way to add the tool to your Python environment. ```bash pip install yamlfix ``` -------------------------------- ### Configure pre-commit hook for yamlfix Source: https://github.com/lyz-code/yamlfix/blob/main/docs/editor_integration.md Add the yamlfix hook to your project's .pre-commit-config.yaml file to automatically format YAML files before committing. This requires the pre-commit framework to be installed and configured in your repository. ```yaml repos: - repo: https://github.com/lyz-code/yamlfix/ rev: main hooks: - id: yamlfix ``` -------------------------------- ### Configuration override example Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Illustrates the configuration precedence in yamlfix: `.yamlfix.toml` overrides `yamlfix.toml`, which overrides `pyproject.toml`. Environment variables have the highest priority. ```toml # pyproject.toml allow_duplicate_keys = false line_length = 100 preserve_quotes = false # yamlfix.toml allow_duplicate_keys = true preserve_quotes = true ``` -------------------------------- ### Example: Preserve Quotes with Quote Basic Values Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Demonstrates the interaction between preserve_quotes and quote_basic_values when both are enabled. The output aims to preserve original quotes while also quoting basic values as per the quote_basic_values setting. ```yaml # original key: [value, 'value with spaces'] ``` ```yaml # preserve_quotes = true # quote_basic_values = true # quote_representation = " key: ["value", 'value with spaces'] ``` -------------------------------- ### Execute yamlfix with CLI arguments Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Shows how to run the yamlfix CLI while specifying custom configuration files and environment prefixes. ```bash yamlfix -c base.toml --config-file environment.toml file.yaml ``` ```bash export YAMLFIX_LINE_LENGTH="300" export MY_PREFIX_NONE_REPRESENTATION="~" yamlfix --env-prefix "MY_PREFIX" file.yaml ``` -------------------------------- ### Configure yamlfix via TOML files Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Demonstrates how to define configuration settings in TOML files and how multiple files are merged, with rightmost files overriding previous ones. ```toml # .yamlfix.toml preserve_quotes = true ``` ```toml # base.toml allow_duplicate_keys = false line_length = 100 ``` ```toml # environment.toml allow_duplicate_keys = true ``` -------------------------------- ### Format individual YAML files with yamlfix CLI Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Demonstrates how to use the yamlfix command-line interface to format one or more YAML files. It takes file paths as arguments. ```bash yamlfix file.yaml file2.yml ``` -------------------------------- ### Recursively format YAML files with yamlfix CLI Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Shows how to use the yamlfix command-line tool to recursively format all YAML files within a directory and its subdirectories. The '.' argument specifies the current directory. ```bash yamlfix . ``` -------------------------------- ### Configure YAML Configuration Path Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Sets the base directory where yamlfix searches for configuration files like pyproject.toml or .yamlfix.toml. ```bash export YAMLFIX_CONFIG_PATH="/etc/yamlfix/" ``` -------------------------------- ### Configure Indentation Settings Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Defines the indentation levels for mappings, sequences, and offsets using ruyaml configuration parameters. ```bash export YAMLFIX_INDENT_MAPPING="2" export YAMLFIX_INDENT_OFFSET="2" export YAMLFIX_INDENT_SEQUENCE="4" ``` -------------------------------- ### Environment Variable Override for quote_keys_and_basic_values Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Demonstrates overriding the `quote_keys_and_basic_values` configuration option via an environment variable. ```bash export YAMLFIX_quote_keys_and_basic_values="false" ``` -------------------------------- ### Configure Sequence Style Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Determines the formatting style for lists, choosing between flow-style (inline) or block-style (indented). ```bash export YAMLFIX_SEQUENCE_STYLE="flow_style" ``` -------------------------------- ### Environment Variable Override for quote_basic_values Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Shows how to override the default `quote_basic_values` setting using an environment variable. ```bash export YAMLFIX_quote_basic_values="false" ``` -------------------------------- ### Configure Line Length Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Sets the maximum line width for the output, triggering wrapping for long strings or conversion of flow-style lists to block-style. ```bash export YAMLFIX_LINE_LENGTH="80" ``` -------------------------------- ### Format YAML files programmatically with yamlfix Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Illustrates how to use the `fix_files` function from the yamlfix library in Python to format a list of YAML files. This is useful for integrating yamlfix into larger Python applications. ```python from yamlfix import fix_files fix_files(["file.py"]) ``` -------------------------------- ### Configure Quoting of Keys and Basic Values in YAML Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md In addition to quoting basic values, this option also quotes the keys in mappings and sequences. Defaults to False. Can be overridden by the YAMLFIX_quote_keys_and_basic_values environment variable. ```yaml # option set to false key: value list: [item, item] ``` ```yaml # option set to true "key": "value" "list": ["item", "item"] ``` -------------------------------- ### Configure None Representation Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Enforces a specific string representation for null values in the YAML output, such as 'null', '~', or an empty string. ```bash export YAMLFIX_LINE_LENGTH="" ``` -------------------------------- ### Environment Variable Override for quote_representation Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Illustrates how to set the `quote_representation` option using an environment variable. ```bash export YAMLFIX_quote_representation="'" ``` -------------------------------- ### Format YAML code string programmatically with yamlfix Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Demonstrates how to use the `fix_code` function from the yamlfix library to format a YAML code string directly within a Python script. This avoids the need to read from or write to files. ```python # Assuming examples/fix_code.py contains the implementation # from yamlfix import fix_code # # yaml_string = "..." # fixed_yaml = fix_code(yaml_string) ``` -------------------------------- ### Configure Comments and Section Whitelines Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Sets the number of consecutive whitelines before comment-only lines or YAML sections. These settings control the vertical spacing layout of the output YAML file. ```bash export YAMLFIX_COMMENTS_WHITELINES="1" export YAMLFIX_SECTION_WHITELINES="1" ``` -------------------------------- ### Configure Quoting of Basic Values in YAML Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Controls whether all simple values in mappings and sequences are quoted to ensure a uniform appearance. Defaults to False. Can be overridden by the YAMLFIX_quote_basic_values environment variable. ```yaml # option set to false stringKey1: abc stringKey2: "123" stringList: [abc, "123"] ``` ```yaml # option set to true stringKey1: "abc" stringKey2: "123" stringList: ["abc", "123"] ``` -------------------------------- ### Environment Variable Override for preserve_quotes Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Shows how to use an environment variable to control the `preserve_quotes` setting. ```bash export YAMLFIX_preserve_quotes="false" ``` -------------------------------- ### Configure Quote Representation for YAML Values Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Specifies the quotation string used for quoting values. Defaults to a single quote ('). Can be overridden by the YAMLFIX_quote_representation environment variable. ```yaml # Option set to: ' key: 'value' ``` ```yaml # Option set to: " key: "value" ``` -------------------------------- ### Configure Preservation of Quotes in YAML Source: https://github.com/lyz-code/yamlfix/blob/main/docs/index.md Determines whether existing quotes in the YAML file should be preserved. Defaults to False. When set to True, quotes are kept as they are. This option may conflict with quote_basic_values and quote_keys_and_basic_values for uniform output. ```yaml # original key: [value, 'value with spaces'] ``` ```yaml # Option set to: false key: [value, value with spaces] ``` ```yaml # Option set to: true key: [value, 'value with spaces'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.