cargo-semver-checks icon indicating copy to clipboard operation
cargo-semver-checks copied to clipboard

Separate checks for "missing import" vs "the item itself is missing"

Open obi1kenobi opened this issue 2 years ago • 0 comments

Needs Trustfall support for tagging a value inside a @fold and then using it outside the fold.

The query for "the import specifically is missing, but the item is present" would look something like:

{
    CrateDiff {
        baseline {
            item {
                ... on Enum {
                    visibility_limit @filter(op: "=", value: ["$public"]) @output
                    name @output @tag

                    # this is the part that isn't supported at the moment:
                    # we currently can't use this tag outside of its own @fold scope
                    importable_path @fold {
                        path @tag
                    }

                    importable_path {
                        missing_path: path @tag
                    }

                    span_: span @optional {
                        filename @output
                        begin_line @output
                    }
                }
            }
        }
        current {
            item {
                ... on Enum {
                    visibility_limit @filter(op: "=", value: ["$public"])
                    name @filter(op: "=", value: ["%name"])

                    # at least one of the importable paths matches, so we know this should be the same enum
                    importable_path @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
                        path @filter(op: "one_of", value: ["%path"])  # tagged value is list-typed because of fold
                    }

                    # but some importable path is also missing from the current paths, which is the error
                    importable_path @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
                        path @filter(op: "=", value: ["%missing_path"])
                    }
                }
            }
        }
    }
}

The query for "the item itself is gone, it's not just imports" would look like this:

{
    CrateDiff {
        baseline {
            item {
                ... on Enum {
                    visibility_limit @filter(op: "=", value: ["$public"]) @output
                    name @output @tag

                    importable_path @fold {
                        path @tag
                    }

                    span_: span @optional {
                        filename @output
                        begin_line @output
                    }
                }
            }
        }
        current @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
            item {
                ... on Enum {
                    visibility_limit @filter(op: "=", value: ["$public"])
                    name @filter(op: "=", value: ["%name"])

                    # at least one of the importable paths matches, so we know this should be the same enum
                    importable_path @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
                        path @filter(op: "one_of", value: ["%path"])  # tagged value is list-typed because of fold
                    }
                }
            }
        }
    }
}

obi1kenobi avatar Aug 08 '22 19:08 obi1kenobi