redhat-developer / vscode-yaml

YAML support for VS Code with built-in kubernetes syntax support
MIT License
654 stars 221 forks source link

Disable schema detection for certain files #245

Open riker09 opened 4 years ago

riker09 commented 4 years ago

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.barand 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.

segevfiner commented 4 years ago

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.

geirsagberg commented 3 years ago

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...

MrDiggles2 commented 3 years ago

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.

gopherine commented 3 years ago

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

gmsantos commented 3 years ago

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"
    }
}

image

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.enableby 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).

danielmahon commented 3 years ago

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
sargunv commented 1 year ago

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"
  }
}
ArcticSnowman commented 1 year ago

I have this setting:

    "yaml.schemas": {

        "https://json.schemastore.org/yamllint.json": "*.yaml",
    },

Forces ALL yaml file to just check yamllint.

vmuthusamy-nlg commented 1 year ago

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.

sevdog commented 1 year ago

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.

hadim commented 9 months ago

So there is no way we can disable YAML schema per file or per file patterns?

tgrushka commented 7 months ago

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"],
    },
sbliven commented 3 months ago

"https://json.schemastore.org/yamllint.json": "*.yaml",

The yamllint schema is describing the configuration file used by the yamllint tool. So if you happen to overlap with their fields you might see type errors still.

@sargunv's workaround of pointing to a {} schema seems to work. However pasting his gist link is not very user friendly. It would be nice if this could get added to the default list as a none option.