Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML files with directives #30

Open
adam-moss opened this issue Feb 3, 2023 · 2 comments
Open

YAML files with directives #30

adam-moss opened this issue Feb 3, 2023 · 2 comments

Comments

@adam-moss
Copy link

This is probably more a stylistic thing but if you have a yaml file

%YAML 1.2
# yaml-language-server: $schema=https://json.schemastore.org/pre-commit-config.json
---
default_install_hook_types:
  - pre-commit
...

and update it with copywrite headers you end up with

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

%YAML 1.2
# yaml-language-server: $schema=https://json.schemastore.org/pre-commit-config.json
---
default_install_hook_types:
  - pre-commit
...

This contrasts with the behaviour of shell scripts which maintain the shebang as the first line.

I don't think it particularly matters for TAG directives but in the case of the YAML directive should this be handled similarly?

@CalebAlbers
Copy link
Member

Hmm, this is an interesting one, and I get the stylistic desire. The part of the code that handles language headers can be found here, and historically has only been used in places where the language itself requires the directive/header to be at the very top of the file.

In your experience, do you see situations where %YAML directives are accompanied by comments? e.g.:

# This file needs 1.2 because...
%YAML 1.2

or this (taken from the YAML spec example)

%YAML 1.3 # Attempt parsing 
          # with a warning
---
"foo"

I admittedly haven't done much with YAML directives, so I'm not sure what is common there. I see the Linux project and a few others put SPDX IDs before the directive based on this GitHub Code Search, but I'm not against the idea.

@adam-moss
Copy link
Author

adam-moss commented Feb 4, 2023

Looking at a similar search with sourcegraph I see almost no comments on or preceding the %YAML directive.

Some eclipse repos have the full license text in them, e.g. this site.yaml, and some nvidia ones like this, do the same but using a copyright SPDX header.

I don't think there is a right or wrong way here, but my preference would be that if the %YAML 1.2 header is present it remained at the top of the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants