-
Notifications
You must be signed in to change notification settings - Fork 2
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
Lint YAML files (OSOE-188) #11
Comments
This should perhaps be addressed not from NE but a new project, to allow standalone YAML-using projects like our GitHub Actions to utilize it too (similar to what we've done with PowerShell Analyzers and Utility Scripts. However, if an ESLint plugin is the way to go then there's no point in reinventing the wheel and indeed it should be part of NE. |
Do you think this is still viable, @BenedekFarkas, @Piedone, @DAud-IcI ? |
Yes, I'd love to have it, but I'd prefer a standalone feature, not tied to OSOCE or this repo, like Zoltán said. |
I've looked up possible alternatives. There is yamllint, which is a Python-based application. There are already existing workflows that wrap this tool on the marketplace, but I'm not sure how configurable that is. There is also yaml-lint, which is Typescript-based. @0liver could you run the ESLint plugin you suggested on the same files, to compare what warnings are produced by it? Whichever gives the richest critique should be used. |
A standalone CLI tool would be great, even better if you don't have to install Python or any other dependency that we don't already use. While the final check here would be in GHA, and that's how we'd ultimately enforce rules, you should also be able to run it locally without much hassle. |
Interesting: https://www.npmjs.com/package/eslint-plugin-yml trips over strings without delimiters. So I've wrapped the Seems pretty ... annoying to me. |
Here's another one that's also available as a GitHub action: https://github.com/mikefarah/yq. I'll give it a shot. UPDATE: Let's call that not useful for our use case 😏 |
Here a some more tools: https://faun.pub/cli-tools-for-validating-and-linting-yaml-files-5627b66849b1. |
https://prettier.io/ can be used to check YAML formatting, but I don't know if it lacks what a full linter may provide. Related: #70 |
As the first use case of this, lint Lombiq GitHub Actions and the other YML files in OSOCE. We'll need to settle on a quote style, for example. |
The unofficial VS Code plugin for GitHub Actions uses https://github.com/redhat-developer/yaml-language-server, the official one uses https://github.com/actions/languageservices, so we should try to use the latter to get consistent results. |
In order to better estimate this task, I need to narrow down the scope a little bit. The discussion here got extended, and the following are subject to be tackled:
Do we want for now to implement this standalone tool and be able to run it locally on OSOCE or Lombiq GHA and then integrate it into our GHA pipelines in a future issue? Or tackle these two together as part of this issue? |
On that note, I've been trying out If Docker is an option, we could use this image or build our own to bypass the hassle of setting it up with Python. Is Docker something we've run before in our GHA pipelines? |
Docker is definitely an option. We use it in our |
Yeah, we could build the image on our own. |
Thanks for summarizing, Tegua! Two adjustments to your points:
Docker is definitely an option, though building our own image seems an overkill. For CI though we most possibly wouldn't need it, since GHA images already contain everything we may need for the environment, including Python. The linter tool itself will need to be installed via whatever package manager it uses on the fly, but that's no problem if it's just a few seconds. Also: an inspiration can be how we do PowerShell static code analysis with https://github.com/Lombiq/PowerShell-Analyzers. That's also available as a local tool as well as a CI workflow (and used in OSOCE here). But since the local tool needs manual execution via the CLI (instead of automatically integrating into an IDE or MSBuild, the latter which of course wouldn't be applicable to projects just containing scripts) people rarely use that and only rely on the CI's results. This is fine, since the volume of PS we write compared to C# is small (and YML is smaller still). |
To expand on that, tightening the feedback loop (integrating the linting into the editor) is important for the developer experience, so having it available as an external tool is great, but less convenient to use. In the case of PS analysis, you can run the analysis on any file/folder (as an external tool), but you can also apply the same analyzer rules to VS Code (I just updated our internal instructions with that), so you see the warnings immediately. As for YAML linting, I would assume that the linting tool/logic itself makes less of a difference (although I'd rather use the same as what the IDE uses to get the same results for sure) and the schemas you validate against matter more. VS Code reads schemas from https://www.schemastore.org/api/json/catalog.json, including those related to GitHub Actions (search for |
Thanks a lot for the answers above, I can say that everything is much clearer. The only dots I'm not able to connect yet is what @BenedekFarkas mentioned at the end of the response above. So, we not only want a tool that helps standardize coding styles when writing YAML files (inspecting things like key duplicates, indentation levels, etc), but also a tool that provides intellisense capabilities when coding such files from an editor like VSCode (and YAML files that are specific to GHA in this case)?
|
Not exactly, what I meant is that choosing an option that is also compatible with IDE-integration makes it more convenient to use locally as a developer. That is important, because having to run an external tool separately from your normal development workflow is a loss of productivity. I just mentioned IntelliSense as a nice extra for the developer experience, but that's directly relevant for automated linting. What we use for automated linting doesn't have to be same tool as what's integrated into the IDE (whatever library the extension is using), but they need to work based on the same rules (e.g., JSON-manifest). |
For JS linting, for example, such integration is configurable like this. Something like this would be ideal, i.e. have a tool to do the lining, the same locally and in CI, and use its configuration in IDEs too. |
After some research, I stumbled upon Trunk Check, a VSCode extension that integrates the latest version of The good thing about this extension is that it can pull the defined However, it looks like this extension doesn't allow to define schemas. Regarding this, it would be great if yamllint was integrated into YAML by Red Hat, so that we could use the latter to enable IntelliSense capabilities as discussed above. Hopefully this question here may get answered. If usage of Trunk Check is legit for our purposes, I will further investigate if it can be used along with YAML by Red Hat, so the developer experience can incorporate both linting and schema validation/IntelliSense capabilities for our YAML files.
|
This looks great! And yes, a VS Code plugin is suitable for the local development story. BTW another plugin here is |
Any news here, Tegua? |
Yeap, opening a PR very soon. @Piedone |
The number of YAML files we are writing constantly increases, mostly in our GitHub-Actions repository.
Let's lint them and fix common issues before code review happens and to be consistent.
This ESLint plugin looks like a decent choice, but there may be others.
Jira issue
The text was updated successfully, but these errors were encountered: