taplo
taplo copied to clipboard
Throws error about unknown license
Specifying LGPL-3.0-only license in my Cargo.toml has Even Better Toml complain:
"LGPL-3.0-only" is not valid under any of the given schemas
That doesn't seem correct, as Cargo uses SPDX identifiers, and this is the correct SPDX identifier for LGPL v3.0.
Same problem here, using MIT
Came to also comment I am getting this error.
Just to add some additional debug/troubleshooting information, the following commands are run with taplo --version = taplo 0.8.1.
Steps to reproduce:
- Create a new project (
cargo new foo) - Add
license = "MIT"tofoo/Cargo.toml - Observe error upon running
taplo --verbose check --default-schema-catalogs foo/Cargo.toml
Possible root cause
Digging through the cli source, it looks like --default-schema-catalogs points to https://www.schemastore.org/api/json/catalog.json, which in turn uses https://json.schemastore.org/cargo.json. This schema has the following for the license key:
"license": {
"anyOf": [
{
"$ref": "#/definitions/License"
},
{
"$ref": "#/definitions/WorkspaceInheritance"
}
]
},
Following the references around eventually leads to https://json.schemastore.org/base.json#/definitions/license, which does indeed have the correct schema (the osi-license reference is just a list of all valid identifiers):
"license": {
"$id": "license",
"anyOf": [
{
"$ref": "https://json.schemastore.org/base.json#/definitions/osi-license"
},
{
"type": "string"
}
]
},
Perhaps there's something going wrong with the $ref chain? I haven't dug too far into the cli source to see how the schemas are resolved.
Test cases
Description: Using the default schema catalogs, I get the error.
Command: taplo --verbose check --default-schema-catalogs Cargo.toml.json Cargo.toml
Output:
2024-01-31T03:04:12.401559Z INFO taplo_cli: found files, total: 1, excluded: 0
at crates\taplo-cli\src\lib.rs:139
in taplo_cli::collect_files with cwd="X:/foo"
in taplo_cli::commands::lint::lint_files
in taplo::taplo
error: "MIT" is not valid under any of the schemas listed in the 'anyOf' keyword
┌─ X:/foo/Cargo.toml:7:11
│
7 │ license = "MIT"
│ ^^^^^ "MIT" is not valid under any of the schemas listed in the 'anyOf' keyword
2024-01-31T03:04:13.092740Z ERROR taplo_cli::commands::lint: invalid file, error: schema validation failed, path: "X:/foo/Cargo.toml"
at crates\taplo-cli\src\commands\lint.rs:87
in taplo_cli::commands::lint::lint_files
in taplo::taplo
2024-01-31T03:04:13.092774Z ERROR taplo: operation failed, error: some files were not valid
at crates\taplo-cli\bin/taplo.rs:33
Description: Using the current Cargo.toml.json schema on the master branch I don't get any errors.
Command: taplo --verbose check --schema https://raw.githubusercontent.com/tamasfe/taplo/268c8b1de41c105324b8c667460aeb5e23b0b6da/site/site/public/schemas/Cargo.toml.json Cargo.toml
Output:
2024-01-31T03:08:00.766020Z INFO taplo_cli: found files, total: 1, excluded: 0
at crates\taplo-cli\src\lib.rs:139
in taplo_cli::collect_files with cwd="X:/foo"
in taplo_cli::commands::lint::lint_files
in taplo::taplo
From the verbose output, it's not clear if the check is actually running or not, but assuming no errors/warnings is a good thing.
Apologies to double post but on a more positive note: it seems like using the schema directive works, so this can be a temporary workaround for those with Cargo.toml issues.
Add the previously mentioned schema file at the top of Cargo.toml:
#:schema https://raw.githubusercontent.com/tamasfe/taplo/268c8b1de41c105324b8c667460aeb5e23b0b6da/site/site/public/schemas/Cargo.toml.json
[package]
# ...
license = "MIT"
You can verify the lint/check works correctly by setting license to a non-string value, e.g., license = 5. As a side note, you can also create the schema file locally and reference it with #:schema ./foo.json (note the path is relative to Cargo.toml).
Same issue for license = "MIT OR Apache-2.0".
Same issue for
license = "MIT OR Apache-2.0".
Also started having issues with this recently.
This is most likely caused by https://github.com/SchemaStore/schemastore/pull/3519
I went ahead and reverted https://github.com/SchemaStore/schemastore/pull/3519 out of caution (https://github.com/SchemaStore/schemastore/pull/3568). I suspect that has something to do with it, even though it passed the test suite we have there and I also included a fallback for "any string".
it might be what validate-pyproject reported, which is not loading nested referenced schemas