Skip to content

manifest-depends-unsorted (ODC9501)

Preview (since 0.16.3.33) · Related issues · View source

Derived from the odoo linter.

Fix is sometimes available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for the depends key of an Odoo module's __manifest__.py listing its modules in an order other than alphabetical.

Why is this bad?

Odoo resolves the dependency graph itself, so the order of depends carries no meaning: it is purely a reading aid. Keeping the list alphabetical makes a module easy to look up by eye, and keeps merge conflicts down — two branches adding a dependency both append to the end of an unsorted list and collide on the same line, while a sorted list spreads the additions out.

Entries are ordered lexicographically, the order Python's own sorted() gives, so sale_stock comes before salemodule.

Example

{
    "depends": [
        "sale",
        # needed for the analytic distribution widget
        "account",
        "base",
    ],
}

Use instead:

{
    "depends": [
        # needed for the analytic distribution widget
        "account",
        "base",
        "sale",
    ],
}

Fix safety

A list written across several lines is rewritten one entry per line, always with a trailing comma, whatever layout it had before. A comment written on its own line above an entry travels with that entry, and so does a comment trailing it on the same line; no comment is ever dropped. A list written entirely on one line is only reordered — its layout and its lack of a trailing comma are left alone.

Note that a comment introducing a group of entries moves with the single entry right below it, which is rarely what a group header means — review the fix when the list is organized in commented sections.

No fix is offered when the list cannot be rewritten without guessing: - a blank line groups the entries, and reordering across it would scramble the grouping; - a line holds several entries and a trailing comment, so there is no telling which entry the comment belongs to; - an entry spans more than one line (implicit concatenation).