Build out rule and fix serialisation#5364
Conversation
|
Thank you so much for your work on this! I've only read the changes, haven't tried running this code yet. One thing that seems a little bit confusing for me is a different formatting for positions. For lints, we get From your code for Would it be possible to get |
|
I assume you're referring to the Here is where the plugin of @dalgarins comes up with a range of text for IntelliJ to highlight.... in this case it appears that IntelliJ needs a starting character position and a length: https://github.com/anboralabs/sqlfluff-intellij-community/blob/08354f69b81f3e5ce83e5cdf6245d10a47bc210b/src/main/kotlin/co/anbora/labs/sqlfluff/lint/Linter.kt#L111 --- the existing code is assuming length "0" (since it doesn't know it), and a starting position calculated by using the getLineStartOffset function (https://github.com/anboralabs/sqlfluff-intellij-community/blob/08354f69b81f3e5ce83e5cdf6245d10a47bc210b/src/main/kotlin/co/anbora/labs/sqlfluff/lint/Linter.kt#L105 ) since SQLFluff only provides the line number. So it appears that maybe it's six one way and half a dozen the other in terms of whether it's most convenient to provide start/end line numbers & positions, as @golergka proposes, or overall offset values as your current commit does. Certainly, if we were writing a console app to write these offsets, it's easy to directly print the offsets as-is if the API is providing line numbers like @golergka says. At any rate, it appears that the IntelliJ SQLFluff plugin has a way to convert between the two as needed. |
|
I agree with @golergka to show this values |
Perhaps a trivial question, but one I'd love to be fairly consistent on: Would you expect these to be four "flat" values, or would you expect perhaps a more "nested" structure? We could do something like: Option 1: Flat {
"rule": "ABC123",
"other": "stuff...",
"start_line_no": 1,
"start_line_pos": 4,
"end_line_no": 3,
"end_line_pos": 7
}Option 2: Nested by start/end {
"rule": "ABC123",
"other": "stuff...",
"start": {
"line_no": 1,
"line_pos": 4,
"file_pos": 14
},
"end": {
"line_no": 3,
"line_pos": 7,
"file_pos": 23
}
}I'm erring toward the latter because we can include multiple options for how people want to locate things - but I realise it's both a more complicated structure, and also a bigger change from past behaviour. Doubly so in the fixes because it makes the structure much denser. |
|
@alanmcruickshank with flat version is ok. |
|
Second flat version just because it's how dicts for the errors already work |
044ffaa to
ee3751e
Compare
ee3751e to
dd69211
Compare
…57470911236860b48ee2eddb9e47da4dd854dd0' into ac/test_suite
…4f389916facc2ee55fedd195b3bf34358fe2f47' into ac/fix_serialisation
Coverage Results ✅ |
|
@golergka @james-johnston-thumbtack @dalgarins do you have any additional feedback on this version before I get it merged? When it's in, I'll push out another pre-release for people to beta-test. |
golergka
left a comment
There was a problem hiding this comment.
Thanks so much for your work on this. Reading this code, I just got a couple of small comments, but most importantly, the API that you expose for fixes and end positions is great.
|
Thank you, for your work, this PR will allow a better integration with other tools, I don't have any other comment. |
This resolves #5353 and resolves #4651. It also resolves #4238.
This PR significantly increases the amount of detail returned by the serialisation routines for violations and fixes. This means a lot more info is included in the non human output versions of
sqlfluff lint(including both start and end points for errors, and the initial fixes proposed). As a result, tests cases which specify the details of a violation are now also required to include that detail - so most of the increased lines of code from this PR are from increased detail in test cases (which I think leads to better test coverage in essence).Specfically it renames
get_info_dict()to justto_dict()and adds a parallelto_dict()method on theLintFixclass so that proposed fixes are shown in the output when linting issues are serialised. Warnings also come through now too - always with the check typenotice, so that the--annotation-typecli option only applies to violations. Given that warnings come through at that level, I've changed the default level towarning.Based on feedback from @golergka and @james-johnston-thumbtack, I've kept the format fairly flat rather than nesting starts and ends into some kind of combined structure.