Better position information
laughedelic opened this issue · comments
Right now all errors are reposted with position 1:1. As I see from the travis lint
output, it gives you information about the location in terms of the YAML structure. So I guess with some simple YAML parsing this could be translated to a line:column position for the linter..
I don't see this kind of information in 1.8.8. Could you show an example?
Here's an example config:
sudo: false
language: scala
jdk: oraclejdk8
scala: 2.12.3
script: sbt test
notifications:
webhooks:
urls: https://webhooks.gitter.im/e/foo
on_start: false # <-- problem here
cache:
directorie: # <-- problem here
- $HOME/.ivy2/cache
- $HOME/.sbt/boot/
And here is the linter's output:
> travis lint --no-interactive .travis.yml
Warnings for .travis.yml:
[x] in notifications.webhooks section: dropping on_start section: illegal value false
[x] value for cache section is empty, dropping
[x] in cache section: unexpected key directorie, dropping
As you every warning has some clue about location:
- in
notifications.webhooks
section,on_start
section - value for
cache
section - in
cache
section
So typically the way we do these Atom linter packages is to parse the linter output information for line/col information and then convert it back into an int
for display.
What you are proposing is:
- Regexp out the section name.
- Use a YAML parser to grab the line information for the key.
- Display the line information.
1 and 3 are certainly possible. I have not done YAML parsing in node.js before, so I do not know what kind of support the YAML module has. If I can return line info for a key in a file, then it is certainly possible.
Thanks for the suggestion. Let me know if any of this sounds off from what you are suggesting. I will look into this feature.
@mschuchard you completely understood my point. I realise that this is probably not an easy feature to request, but just wanted to submit this idea. Also I'm pretty sure there are plenty npm packages for parsing YAML..
I found out that somebody already tried to request better linter output for the travis CLI, but it didn't result in anything: travis-ci/travis.rb#203. Although the idea of querying API directly is probably worth further investigating.
By calling the API directly you can at least eliminate step 1 (matching sections names in the linter output). Calling
curl -T .travis.yml api-staging.travis-ci.org/lint
on the example config from above returns this JSON:
{
"lint": {
"warnings": [
{
"key": [
"notifications",
"webhooks"
],
"message": "dropping \"on_start\" section: illegal value \"false\""
},
{
"key": [],
"message": "value for \"cache\" section is empty, dropping"
},
{
"key": [
"cache"
],
"message": "unexpected key \"directorie\", dropping"
}
]
}
}
So key
array gives you the path in the YAML structure.