Skip to content

Adding more data to lints/hints? #2342

@bollwyvl

Description

@bollwyvl

Comment:

elevator pitch

Provide a richer data model for conda recipe-lint findings.

references

motivation

As always, thanks for all the hard work on conda-smithy!

In looking into wrapping conda-smithy in a language server, my naive approach was just to look through the raw output and do the best I could with regexen. It's... not very fun.

While it would take rather a lot to get to real line numbers (#2274), a near term step to improve downstream use would be to make the lints/hints into more structured objects.

design ideas

Using just stdlib, and not pre-disposing to any particular output format (e.g. SARIF, LSP, code-quality, GitHub log parsers):

@dataclass
class Finding:
    #: a human readable string
    message: str
    #: a URL-friendly identifier
    code: str | None = None
    #: the tool that generated the finding
    source: str = "conda-smithy"
    #: an absolute POSIX path to the file
    path: str | None = None
    #: a list of dict/list indexes to the finding
    pointer: list[str | int] | None = None
    #: the line number in the file
    line: int | None = None
    #: the column the file
    col: int | None = None
    #: extra URLs describing the finding
    links: list[str] | None = None

Then, incrementally each (lints|hint).append could be incrementally enriched with better data as it became available.

Alternately, the lints and hints could be combined into a single list with a severity discriminator.

In the first pass, adding code to all the findings would make it much easier to fill in some of those gaps in downstream tools.

As to the form of these, there seem to be a few styles, sometimes both of which are used:

  • very short alpha followed by zero-padded numeric: CS0001
  • descriptive, URL-friendly some-short-id

I'm kind of leaning towards the latter, so something like:

hints += (
    "PyPI default URL is now pypi.org, and not pypi.io."
    " You may want to update the default source url."
)

Would become, initially:

hints += Finding(
    "PyPI default URL is now pypi.org, and not pypi.io."
    " You may want to update the default source url.",
    code="sources-should-not-mention-pypi-io-but-pypi-org"
)

The display of these codes could then be toggled via CLI:

$> conda recipe-lint recipe --show-codes

recipe has some suggestions:
  PyPI default URL is now pypi.org, and not pypi.io. You may want to update the default source url. [sources-should-not-mention-pypi-io-but-pypi-org]

... or be replaced with a --format=json output format.

$> conda recipe-lint recipe --format=json

{
  "lints": [],
  "hints": [
    {
        "message": "PyPI default URL is now pypi.org, and not pypi.io. You may want to update the default source url. ",
        "code": "sources-should-not-mention-pypi-io-but-pypi-org"
    }
  ]
}

... with subsequent, backwards-compatible API changes in conda_smithy.lint_recipe.main.

Follow-on work could then start filling in the rest of the data, as it became feasible to discover.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions