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

Fix 108 #109

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# tekton-lint

A linter for Tekton resource definitions - **v1 beta now available!!**
A linter for Tekton resource definitions
<!-- TOC -->

- [tekton-lint](#tekton-lint)
- [Quick Start](#quick-start)
- [History](#history)
- [Usage - CLI](#usage---cli)
- [What yaml files to include?](#what-yaml-files-to-include)
- [Rules](#rules)
- [Detecting errors](#detecting-errors)
- [Best practices](#best-practices)
- [Configuring tekton-lint](#configuring-tekton-lint)
- [Creating custom rules](#custom-rules)
- [Custom Rules](#custom-rules)
- [Configuring](#configuring)
- [Reporting](#reporting)
- [Issues?](#issues)

<!-- /TOC -->
Expand Down Expand Up @@ -40,7 +43,16 @@ example-task.yaml

```

You can use the tool as a regular lint tool from the CLI or scripts; alternatively you can use it as a [library via it's API](./_docs/usage_api.md) or from an [IDE such as VScode](./_docs/usage_ide.md).
You can use the tool as a regular lint tool from the CLI or scripts; alternatively you can use it as a [library via it's API](./_docs/usage_api.md) or from an [IDE such as VScode](./_docs/usage_ide.md). (please consider both the API and IDE use as experimental features.)

## History

When I first started using Tekton a few years ago, I found one of the harder things was keeping track of the dependencies between the YAML files. Comparing to say github actions, or travis, Tekton is a lot more verbose. The comparison isn't quite fair as the tools do work at slightly different levels.

Nevertheless, I was pleased to find this TektonLint tool; it was able to spot a number of the 'gotchas' before pushing the pipelines for execution.
After a brief hiatus, I was using Tekton again. Bence Dányi the original author was no longer at IBM; as the tool had been useful for me I decided to take on the repo.

I've updated typescript versions, added in additional features such as custom rules, allowed for caching of standard components. Theres more still I'd like to do; but of a MVP it's at v1.


## Usage - CLI
Expand Down Expand Up @@ -114,7 +126,7 @@ external-tasks:
path: kubernetes-service
```

This will clone the repos specified and extract the various directories to a local cache. When you lint your tools these external tasks and definitions will be included. This will prevent any errors about tasks missing; but also imnportantly ensure your use of the tasks is correct, eg no missed parameters.
This will clone the repos specified and extract the various directories to a local cache. When you lint your tools these external tasks and definitions will be included. This will prevent any errors about tasks missing; but also importantly ensure your use of the tasks is correct, eg no missed parameters.

Note that these cached files won't be linted themselves.

Expand All @@ -123,6 +135,10 @@ The cache is defined to be put to `~/.tektonlint` If you wish to clear the cach

## Rules

**Please note** that the tool assumes that the files are syntax correct YAML files, and they are following the established schema for Tekton. For example referring to a field with the wrong spelling or case will confuse the rules.

If you see an error like ` Pipeline 'pipeline-test-perf-tag' references task 'undefined' but the referenced task cannot be found. ` referencing 'undefined' this more than likely means there is a syntax error in the yaml file. This can be easily seen with casing, so using `Name: ..` rather than `name: .. `

### Detecting errors

> These rules are straightforward, violations indicate that there's a good
Expand Down Expand Up @@ -267,14 +283,17 @@ Running on the `example-task.yaml` file with the example configured adds a 4th r
✖ 4 problems (3 errors, 1 warning)
```

Within the representation of the rule name here `my_rules#no-tasks-called-task`; if you want to turn off this rule, then you can adjust the list of rules in the `.tektonrc.yaml` as for another rule
Within the representation of the rule name here `my_rules#no-tasks-called-task`; if you want to turn off this rule, then you can adjust the list of rules in the `.tektonrc.yaml` as for another rule; Note that `#` in the name.

```
rules:
...
my_rules#no-tasks-called-task: off
```




## Issues?

Please raise an issue in the usual manner, please try and include a short sample Tekton file that shows the problem.
Expand Down
4 changes: 0 additions & 4 deletions TODO.md

This file was deleted.

32 changes: 17 additions & 15 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,24 @@ class Reporter {

_getLocation(m, node, prop): Location | {} {
if (!m.has(node)) return {};

const k = m.get(node);

const chars: string[] = Array.from(k.doc.raw);
let n = prop ? k.node.get(prop, true) : k.node;
if (!n) n = k.node.items.find((pair) => pair.key.value === prop).key;
return {
path: k.doc.path,
loc: {
range: n.range,
startLine: this._getLine(chars, n.range[0]),
startColumn: this._getCol(chars, n.range[0]),
endLine: this._getLine(chars, n.range[1]),
endColumn: this._getCol(chars, n.range[1]),
},
};
try {
const chars: string[] = Array.from(k.doc.raw);
let n = prop ? k.node.get(prop, true) : k.node;
if (!n) n = k.node.items.find((pair) => pair.key.value === prop).key;
return {
path: k.doc.path,
loc: {
range: n.range,
startLine: this._getLine(chars, n.range[0]),
startColumn: this._getCol(chars, n.range[0]),
endLine: this._getLine(chars, n.range[1]),
endColumn: this._getCol(chars, n.range[1]),
},
};
} catch (e) {
return { path: k.doc.path, loc: {} };
}
}
}

Expand Down
Loading