-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Incorrect line # called out with issue found #625
Comments
It's very interesting that the auto-formatter here called out the correct line. I wonder if my implementation of YamlDotNet is incorrect. I'll supply that shortly. |
Here is how I am implementing YamlDotNet. Ideally, I would like to point the user to the correct offending line, which I have not been able to do. Right now I am posting a github comment on the first changed line in their Pull Request, which is far from ideal. namespace TestApp.BusinessLayer.Analysis.Utilities
{
public class YamlChecker : IYamlChecker
{
public void CheckYaml(string fileData, string fileName, int positionNumber, string commitSha, List<ScanResult> issues)
{
ValidateYaml(fileData, fileName, positionNumber, commitSha, issues);
}
public static void ValidateYaml(string fileData, string fileName, int positionNumber, string commitSha, List<ScanResult> issues)
{
try
{
var deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.WithNodeTypeResolver(new MapTagsToObject())
.Build();
deserializer.Deserialize<object>(fileData);
}
catch (Exception e)
{
// capture failed deserialization information
var result = new ScanResult
{
FileName = fileName,
Issue = "SYNTAX ERROR: YAML failed to validate - **please check entire file (not just this line).**<br/>",
Commit = commitSha,
IssueContext = e.Message,
LineNumber = positionNumber,
PositionNumber = positionNumber
};
issues.Add(result);
}
}
}
// Provided by YamlDotNet owner to help ignore custom tags for things like MKdocs
// https://github.com/aaubry/YamlDotNet/issues/615#issuecomment-861575357
internal class MapTagsToObject : INodeTypeResolver
{
public bool Resolve(NodeEvent? nodeEvent, ref Type currentType)
{
if (nodeEvent != null && !nodeEvent.Tag.IsEmpty)
{
currentType = typeof(object);
return true;
}
return false;
}
}
} |
This YAML snippet appears to be invalid.
|
1 similar comment
This YAML snippet appears to be invalid.
|
This exposed a larger issue than just showing the incorrect line #. It also showed that multi-line single quote scalars were handled incorrectly. They require a space at the beginning of a line with content, which a double quote does not. Both a single and double were handled the same with regards to that. I'll be creating a PR to fix this when my current PR gets merged in. You can take a look at my PR/test cases if you would like in this commit: |
Mostly a note to me. This is caused by a difference between the yaml spec 1.1 and 1.2. Requiring the space at the front will violate the 1.1 spec and most likely break current users that rely on 1.1. This needs to be a feature that is turned on by user code, probably a 1.2 enforcement option. At least until we possibly default to 1.2 parsing. I’ll work on this more when I’ve completed more of the smaller low hanging fruit bugs. |
After rechecking my thoughts on what was expected in the spec, in 1.1, it is expected that the value be indented by an additional space when the value was already indented. a:
b: 'c
d' 'hello
world' We should be good once the PR is approved. |
Describe the bug
I have some sample yaml that has an issue (missing quote) on line 16, however the callout supplied by YamlDotNet is for line 34.
To Reproduce
See below for the sample
Sample
output:
the exact same yaml on yamllint.com providing the correct line number with the issue:
The text was updated successfully, but these errors were encountered: