vscode-yaml
vscode-yaml copied to clipboard
Disable schema detection for certain files
First of all, great extension. It is really useful to have yaml files validated (and auto-completed).
However, I have a file in my codebase called some.thing-sam.yml
and I get red squiggle marks (linting errors) on valid properties. I believe what happens is that this extension treats the file as a AWS CloudFormation Serverless Application Model (SAM) file, which it isn't.
I have found a similar issue #98 where the schemaStore validation is disabled completely. But this is not what I want. Ideally I could provide a re-mapping of the file extension, as I believe the filename pattern is the culprit. Renaming the file to anything else but *sam.yml
works.
Paraphrasing: Naming a yaml file *sam.yml
will trick this extension (or the yaml-language-server) into treating the file as an AWS CloudFormation Serverless Application Model. There should be a way to fix this for the user.
I tried to provide a mapping in my VSCode settings myself, but without any luck:
{
"yaml.schemas": {
"https://raw.githubusercontent.com/awslabs/goformation/master/schema/sam.schema.json": "foo.bar"
}
}
Also noteworthy, the catalog.json
has this configuration in place:
[...]
{
"name": "AWS CloudFormation Serverless Application Model (SAM)",
"description": "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.",
"fileMatch": [
"*.sam.json",
"*.sam.yml",
"*.sam.yaml",
"sam.json",
"sam.yml",
"sam.yaml"
],
"url": "https://raw.githubusercontent.com/awslabs/goformation/master/schema/sam.schema.json"
},
[...]
Judging from the glob patterns my file (some.thing-sam.yml
) shouldn't have been picked up for linting with that schema in the first place, should it?
[EDIT]
It seems the user configuration is merged. I can successfully create a file foo.bar
and change the file type to YAML
and the linting errors are the same. Changing the file extension mapping to foo.foo
makes the squiggle lines disappear.
I'm hitting a weirder one where a file named somethingcodegen.yaml
is detected as some other schema, probably this one:
{
"name": "GraphQL Code Generator",
"description": "JSON Schema for GraphQL Code Generator config file",
"url": "https://raw.githubusercontent.com/dotansimha/graphql-code-generator/master/website/static/config.schema.json",
"fileMatch": [
"codegen.yml",
"codegen.yaml",
"codegen.json",
"codegen.js",
".codegen.yml",
".codegen.yaml",
".codegen.json",
".codegen.js"
]
},
Despite the patterns not having a glob asterisk, and there doesn't seem to be a way to ignore that... Annoyingly codegen.yaml
is a rather generic name that conflicts with others but that's a problem with schemastore.
Same issue here with a file called something.deploy.yml
, seems to think my file should match "https://raw.githubusercontent.com/deployphp/deployer/master/src/schema.json", but it is just a GitHub Actions workflow...
Running into something similar as above with a file named docker-compose.deploy.yml
. It seems to register the Docker and DeployPHP schemas simultaneously. It would nice if I could just disable the DeployPHP schema for files with this name.
running into similar issue with golangci.yml would be nice if i can exclude this explicitly an example of the configuration could be found https://github.com/golangci/golangci-lint here
I have the same problem with file match from Ansible in a file structure for Concourse CI (like in https://github.com/redhat-developer/vscode-yaml/issues/145#issuecomment-478661866).
project
|- ci
|- pipeline.yml
|- tasks
|- task1.yml
|- task2.yml
Even if I add a more specific custom schema for tasks, it would stack both schemas and the error persists:
"yaml.schemas": {
"https://gist.githubusercontent.com/JohnLBevan/5580a2cb17eac18c646c7c87021e5169/raw/79a0bef617b8a88e2d4d2de41904a4f677abaf8f/concourse.task.schema.json": "ci/tasks/*.yml"
}
}
Have the ability to disable a specific schema, or override its path would be great. I also don't want to completely disable yaml.schemaStore.enable
by setting it as false
(that would work to get rid of the errors, but at the same time I lost the validation from all other schemas).
So I just tried setting the schema to itself and it worked (surprisingly), no more errors... and no need for a blank file.
# yaml-language-server: $schema=./[current file].yaml
build.yaml
# yaml-language-server: $schema=./build.yaml
targets: # before, this would show an error because of incorrect schema validation
$default:
builders:
# ... etc
According to the JSON Schema docs, a {}
schema will accept anything. So, as a workaround, I published this "schema" as a Gist and am using it when I want to disable schema detection for certain files.
// .vscode/settings.json
{
"yaml.schemas": {
"https://gist.githubusercontent.com/sargunv/c2ca41a08391cd06feaad97aece309e4/raw/empty-json-schema.json": "my/file/path/example.yaml"
}
}
I have this setting:
"yaml.schemas": {
"https://json.schemastore.org/yamllint.json": "*.yaml",
},
Forces ALL yaml file to just check yamllint.
When you open the yaml file in VS Code, you will see an option to select appropriate schema on the bottom right corner in the VSCode status bar.
The schema selector does not permit to select "none of defined schemas", this is extremelly annoying when deling with YAML files which store test-fixtures and thus uses very different schemas for each model which is stored.
So there is no way we can disable YAML schema per file or per file patterns?
Wow, that's annoying. Should allow to select lint or none for certain file types. Should be somewhat intuitive, but it is not. The lint suggestion above worked for me, but it shouldn't be this hard to figure out.
"yaml.schemas": {
"https://json.schemastore.org/yamllint.json": ["cluster.yaml"],
},