Skip to content

Conversation

@slipknois
Copy link

A compliant report need to output lines on "location" object to work properly as doc in link show us: https://docs.gitlab.com/ci/testing/code_quality/

This commit write de "lines" property properly. If "location" object don't output the line, the gitlab show a message saying "Failed to load Code Quality report"

Issue: #272

@braydonk
Copy link
Collaborator

braydonk commented Dec 3, 2025

This PR currently undoes some of my requested changes on #294. Please go back through those and ensure they are all done.

In addition, I can tell just by looking that the given test will fail. Please run the tests and fix the failure.

@tiheat
Copy link

tiheat commented Dec 10, 2025

Hello, @braydonk.
There are updates about this?
I'm waiting this too for use in my CI

@braydonk
Copy link
Collaborator

I still don't see evidence that the author of this PR actually ran the tests (I know they will fail by reading). In addition, old comments I made on the PR were undone in this reopen.

@slipknois
Copy link
Author

Hi @braydonk , the local test output:

marciovieira@MacBook-Pro-de-Marcio yamlfmt % make test
go test ./...
ok github.com/google/yamlfmt 0.767s
? github.com/google/yamlfmt/cmd/yamlfmt [no test files]
ok github.com/google/yamlfmt/command 1.165s
? github.com/google/yamlfmt/engine [no test files]
ok github.com/google/yamlfmt/formatters/basic 2.140s
ok github.com/google/yamlfmt/formatters/basic/features 2.529s
ok github.com/google/yamlfmt/internal/assert 1.637s
ok github.com/google/yamlfmt/internal/collections 2.901s
? github.com/google/yamlfmt/internal/features [no test files]
ok github.com/google/yamlfmt/internal/gitlab 3.314s
? github.com/google/yamlfmt/internal/hotfix [no test files]
ok github.com/google/yamlfmt/internal/jsonschema 3.588s
? github.com/google/yamlfmt/internal/logger [no test files]
? github.com/google/yamlfmt/internal/multilinediff [no test files]
? github.com/google/yamlfmt/internal/tempfile [no test files]
ok github.com/google/yamlfmt/pkg/yaml 5.572s
ok github.com/google/yamlfmt/pkg/yaml/formattest 4.417s
marciovieira@MacBook-Pro-de-Marcio yamlfmt % make test_v
=== RUN TestBasicContentAnalyzer
=== RUN TestBasicContentAnalyzer/has_ignore_metadata
=== PAUSE TestBasicContentAnalyzer/has_ignore_metadata
=== RUN TestBasicContentAnalyzer/matches_regex_pattern
=== PAUSE TestBasicContentAnalyzer/matches_regex_pattern
=== CONT TestBasicContentAnalyzer/has_ignore_metadata
=== CONT TestBasicContentAnalyzer/matches_regex_pattern
--- PASS: TestBasicContentAnalyzer (0.00s)
--- PASS: TestBasicContentAnalyzer/matches_regex_pattern (0.00s)
--- PASS: TestBasicContentAnalyzer/has_ignore_metadata (0.00s)
=== RUN TestBadNewContentAnalyzer
--- PASS: TestBadNewContentAnalyzer (0.00s)
=== RUN TestReadMetadata
=== RUN TestReadMetadata/contains_no_metadata
metadata_test.go:89: got error: []
=== RUN TestReadMetadata/has_ignore_metadata
metadata_test.go:89: got error: []
=== RUN TestReadMetadata/has_bad_metadata
metadata_test.go:89: got error: [metadata: malformed string: test.yaml:1:# !yamlfmt!fjghgh]
=== RUN TestReadMetadata/has_unrecognized_metadata_type
metadata_test.go:89: got error: [metadata: unrecognized type: test.yaml:1:# !yamlfmt!:lulsorandom]
--- PASS: TestReadMetadata (0.00s)
--- PASS: TestReadMetadata/contains_no_metadata (0.00s)
--- PASS: TestReadMetadata/has_ignore_metadata (0.00s)
--- PASS: TestReadMetadata/has_bad_metadata (0.00s)
--- PASS: TestReadMetadata/has_unrecognized_metadata_type (0.00s)
=== RUN TestFilepathCollector
=== RUN TestFilepathCollector/finds_direct_paths
=== RUN TestFilepathCollector/finds_all_in_directory_one_layer
=== RUN TestFilepathCollector/finds_direct_path_to_subdirectory
=== RUN TestFilepathCollector/finds_all_in_layered_directories
=== RUN TestFilepathCollector/exclude_files
=== RUN TestFilepathCollector/exclude_directory
=== RUN TestFilepathCollector/don't_get_files_with_wrong_extension
=== RUN TestFilepathCollector/multi-part_extension
--- PASS: TestFilepathCollector (0.01s)
--- PASS: TestFilepathCollector/finds_direct_paths (0.00s)
--- PASS: TestFilepathCollector/finds_all_in_directory_one_layer (0.00s)
--- PASS: TestFilepathCollector/finds_direct_path_to_subdirectory (0.00s)
--- PASS: TestFilepathCollector/finds_all_in_layered_directories (0.00s)
--- PASS: TestFilepathCollector/exclude_files (0.00s)
--- PASS: TestFilepathCollector/exclude_directory (0.00s)
--- PASS: TestFilepathCollector/don't_get_files_with_wrong_extension (0.00s)
--- PASS: TestFilepathCollector/multi-part_extension (0.00s)
=== RUN TestDoublestarCollectorBasic
=== RUN TestDoublestarCollectorBasic/no_excludes
--- PASS: TestDoublestarCollectorBasic (0.00s)
--- PASS: TestDoublestarCollectorBasic/no_excludes (0.00s)
=== RUN TestDoublestarCollectorExcludeDirectory
=== RUN TestDoublestarCollectorExcludeDirectory/exclude_directory/start_with_doublestar
=== RUN TestDoublestarCollectorExcludeDirectory/exclude_directory/relative_include_and_exclude
=== RUN TestDoublestarCollectorExcludeDirectory/exclude_directory/absolute_include_and_exclude
=== RUN TestDoublestarCollectorExcludeDirectory/exclude_directory/absolute_include_relative_exclude
path_collector_test.go:381:
=== RUN TestDoublestarCollectorExcludeDirectory/exclude_directory/relative_include_absolute_exclude
path_collector_test.go:381:
--- PASS: TestDoublestarCollectorExcludeDirectory (0.00s)
--- PASS: TestDoublestarCollectorExcludeDirectory/exclude_directory/start_with_doublestar (0.00s)
--- PASS: TestDoublestarCollectorExcludeDirectory/exclude_directory/relative_include_and_exclude (0.00s)
--- PASS: TestDoublestarCollectorExcludeDirectory/exclude_directory/absolute_include_and_exclude (0.00s)
--- SKIP: TestDoublestarCollectorExcludeDirectory/exclude_directory/absolute_include_relative_exclude (0.00s)
--- SKIP: TestDoublestarCollectorExcludeDirectory/exclude_directory/relative_include_absolute_exclude (0.00s)
=== RUN TestPatternFile
=== PAUSE TestPatternFile
=== CONT TestPatternFile
=== RUN TestPatternFile/yaml_and_yml_files
=== PAUSE TestPatternFile/yaml_and_yml_files
=== RUN TestPatternFile/ignore_pattern
=== PAUSE TestPatternFile/ignore_pattern
=== RUN TestPatternFile/descent_into_directories
=== PAUSE TestPatternFile/descent_into_directories
=== RUN TestPatternFile/exclude_directories
=== PAUSE TestPatternFile/exclude_directories
=== RUN TestPatternFile/matches_are_rooted_at_the_working_directory
=== PAUSE TestPatternFile/matches_are_rooted_at_the_working_directory
=== CONT TestPatternFile/exclude_directories
=== CONT TestPatternFile/matches_are_rooted_at_the_working_directory
=== CONT TestPatternFile/yaml_and_yml_files
=== CONT TestPatternFile/descent_into_directories
=== CONT TestPatternFile/ignore_pattern
--- PASS: TestPatternFile (0.00s)
--- PASS: TestPatternFile/yaml_and_yml_files (0.00s)
--- PASS: TestPatternFile/matches_are_rooted_at_the_working_directory (0.00s)
--- PASS: TestPatternFile/exclude_directories (0.00s)
--- PASS: TestPatternFile/descent_into_directories (0.00s)
--- PASS: TestPatternFile/ignore_pattern (0.00s)
PASS
ok github.com/google/yamlfmt 0.219s
? github.com/google/yamlfmt/cmd/yamlfmt [no test files]
=== RUN TestLineEndingFormatterVsGlobal
--- PASS: TestLineEndingFormatterVsGlobal (0.00s)
PASS
ok github.com/google/yamlfmt/command 0.365s
? github.com/google/yamlfmt/engine [no test files]
=== RUN TestNewWithConfigRetainsDefaultValues
=== RUN TestNewWithConfigRetainsDefaultValues/only_indent_specified
=== RUN TestNewWithConfigRetainsDefaultValues/only_include_document_start_specified
=== RUN TestNewWithConfigRetainsDefaultValues/only_line_ending_style_specified
=== RUN TestNewWithConfigRetainsDefaultValues/only_pad_line_comments_specified
=== RUN TestNewWithConfigRetainsDefaultValues/only_indentless_arrays_specified
=== RUN TestNewWithConfigRetainsDefaultValues/all_specified
--- PASS: TestNewWithConfigRetainsDefaultValues (0.00s)
--- PASS: TestNewWithConfigRetainsDefaultValues/only_indent_specified (0.00s)
--- PASS: TestNewWithConfigRetainsDefaultValues/only_include_document_start_specified (0.00s)
--- PASS: TestNewWithConfigRetainsDefaultValues/only_line_ending_style_specified (0.00s)
--- PASS: TestNewWithConfigRetainsDefaultValues/only_pad_line_comments_specified (0.00s)
--- PASS: TestNewWithConfigRetainsDefaultValues/only_indentless_arrays_specified (0.00s)
--- PASS: TestNewWithConfigRetainsDefaultValues/all_specified (0.00s)
=== RUN TestFormatterRetainsComments
--- PASS: TestFormatterRetainsComments (0.00s)
=== RUN TestFormatterPreservesKeyOrder
--- PASS: TestFormatterPreservesKeyOrder (0.00s)
=== RUN TestFormatterParsesMultipleDocuments
--- PASS: TestFormatterParsesMultipleDocuments (0.00s)
=== RUN TestWithDocumentStart
--- PASS: TestWithDocumentStart (0.00s)
=== RUN TestCRLFLineEnding
--- PASS: TestCRLFLineEnding (0.00s)
=== RUN TestEmojiSupport
--- PASS: TestEmojiSupport (0.00s)
=== RUN TestRetainLineBreaks
=== RUN TestRetainLineBreaks/basic
=== RUN TestRetainLineBreaks/multi-doc
=== RUN TestRetainLineBreaks/literal_string
=== RUN TestRetainLineBreaks/multi_level_nested_literal_string
=== RUN TestRetainLineBreaks/retain_single_line_break
--- PASS: TestRetainLineBreaks (0.00s)
--- PASS: TestRetainLineBreaks/basic (0.00s)
--- PASS: TestRetainLineBreaks/multi-doc (0.00s)
--- PASS: TestRetainLineBreaks/literal_string (0.00s)
--- PASS: TestRetainLineBreaks/multi_level_nested_literal_string (0.00s)
--- PASS: TestRetainLineBreaks/retain_single_line_break (0.00s)
=== RUN TestScanFoldedAsLiteral
--- PASS: TestScanFoldedAsLiteral (0.00s)
=== RUN TestIndentlessArrays
--- PASS: TestIndentlessArrays (0.00s)
=== RUN TestDropMergeTag
--- PASS: TestDropMergeTag (0.00s)
=== RUN TestPadLineComments
--- PASS: TestPadLineComments (0.00s)
=== RUN TestTrimTrailingWhitespace
--- PASS: TestTrimTrailingWhitespace (0.00s)
=== RUN TestEOFNewline
--- PASS: TestEOFNewline (0.00s)
=== RUN TestStripDirectives
--- PASS: TestStripDirectives (0.00s)
=== RUN TestArrayIndent
--- PASS: TestArrayIndent (0.00s)
=== RUN TestIndentRootArray
--- PASS: TestIndentRootArray (0.00s)
=== RUN TestForceFlowSequence
--- PASS: TestForceFlowSequence (0.00s)
=== RUN TestForceBlockSequence
--- PASS: TestForceBlockSequence (0.00s)
=== RUN TestJustComments
--- PASS: TestJustComments (0.00s)
PASS
ok github.com/google/yamlfmt/formatters/basic 0.689s
=== RUN TestCheck
=== RUN TestCheck/no_anchors
=== RUN TestCheck/anchor
--- PASS: TestCheck (0.00s)
--- PASS: TestCheck/no_anchors (0.00s)
--- PASS: TestCheck/anchor (0.00s)
PASS
ok github.com/google/yamlfmt/formatters/basic/features 0.840s
=== RUN TestAssertFail
--- PASS: TestAssertFail (0.00s)
=== RUN TestEqualFail
--- PASS: TestEqualFail (0.00s)
=== RUN TestDereferenceEqualErr
--- PASS: TestDereferenceEqualErr (0.00s)
=== RUN TestDereferenceEqualFail
--- PASS: TestDereferenceEqualFail (0.00s)
=== RUN TestDereferenceEqualPass
--- PASS: TestDereferenceEqualPass (0.00s)
=== RUN TestSliceEqualFailDiffSize
--- PASS: TestSliceEqualFailDiffSize (0.00s)
=== RUN TestSliceEqualMismatch
--- PASS: TestSliceEqualMismatch (0.00s)
PASS
ok github.com/google/yamlfmt/internal/assert 0.523s
=== RUN TestErrorsCombine
--- PASS: TestErrorsCombine (0.00s)
=== RUN TestErrorsCombineEmpty
--- PASS: TestErrorsCombineEmpty (0.00s)
=== RUN TestErrorsCombineNilElements
--- PASS: TestErrorsCombineNilElements (0.00s)
PASS
ok github.com/google/yamlfmt/internal/collections 0.995s
? github.com/google/yamlfmt/internal/features [no test files]
=== RUN TestCodeQuality
=== PAUSE TestCodeQuality
=== RUN TestCodeQuality_DetectChangedLine
=== PAUSE TestCodeQuality_DetectChangedLine
=== RUN TestCodeQuality_DetectChangedLines_MultipleCases
=== PAUSE TestCodeQuality_DetectChangedLines_MultipleCases
=== CONT TestCodeQuality
=== RUN TestCodeQuality/no_diff
=== PAUSE TestCodeQuality/no_diff
=== RUN TestCodeQuality/with_diff
=== PAUSE TestCodeQuality/with_diff
=== CONT TestCodeQuality/no_diff
=== CONT TestCodeQuality_DetectChangedLines_MultipleCases
=== RUN TestCodeQuality_DetectChangedLines_MultipleCases/single_line_change
=== CONT TestCodeQuality_DetectChangedLine
../../testdata/gitlab/changed_line=== CONT TestCodeQuality/with_diff
=== PAUSE TestCodeQuality_DetectChangedLines_MultipleCases/single_line_change
=== RUN TestCodeQuality_DetectChangedLines_MultipleCases/multiple_consecutive_lines
=== PAUSE TestCodeQuality_DetectChangedLines_MultipleCases/multiple_consecutive_lines
=== RUN TestCodeQuality_DetectChangedLines_MultipleCases/non-consecutive_changes
=== PAUSE TestCodeQuality_DetectChangedLines_MultipleCases/non-consecutive_changes
=== RUN TestCodeQuality_DetectChangedLines_MultipleCases/change_at_beginning
=== PAUSE TestCodeQuality_DetectChangedLines_MultipleCases/change_at_beginning
=== RUN TestCodeQuality_DetectChangedLines_MultipleCases/change_at_end
=== PAUSE TestCodeQuality_DetectChangedLines_MultipleCases/change_at_end
=== CONT TestCodeQuality_DetectChangedLines_MultipleCases/single_line_change
=== CONT TestCodeQuality_DetectChangedLines_MultipleCases/non-consecutive_changes
=== CONT TestCodeQuality_DetectChangedLines_MultipleCases/multiple_consecutive_lines
=== CONT TestCodeQuality_DetectChangedLines_MultipleCases/change_at_end
--- PASS: TestCodeQuality (0.00s)
--- PASS: TestCodeQuality/no_diff (0.00s)
--- PASS: TestCodeQuality/with_diff (0.00s)
=== CONT TestCodeQuality_DetectChangedLines_MultipleCases/change_at_beginning
--- PASS: TestCodeQuality_DetectChangedLines_MultipleCases (0.00s)
--- PASS: TestCodeQuality_DetectChangedLines_MultipleCases/single_line_change (0.00s)
--- PASS: TestCodeQuality_DetectChangedLines_MultipleCases/non-consecutive_changes (0.00s)
--- PASS: TestCodeQuality_DetectChangedLines_MultipleCases/multiple_consecutive_lines (0.00s)
--- PASS: TestCodeQuality_DetectChangedLines_MultipleCases/change_at_end (0.00s)
--- PASS: TestCodeQuality_DetectChangedLines_MultipleCases/change_at_beginning (0.00s)
--- PASS: TestCodeQuality_DetectChangedLine (0.00s)
PASS
ok github.com/google/yamlfmt/internal/gitlab 1.156s
? github.com/google/yamlfmt/internal/hotfix [no test files]
=== RUN TestJSONSchemaIsValid
--- PASS: TestJSONSchemaIsValid (0.00s)
PASS
ok github.com/google/yamlfmt/internal/jsonschema 1.194s
? github.com/google/yamlfmt/internal/logger [no test files]
? github.com/google/yamlfmt/internal/multilinediff [no test files]
? github.com/google/yamlfmt/internal/tempfile [no test files]
ok github.com/google/yamlfmt/pkg/yaml/formattest 0.210s

@slipknois
Copy link
Author

Regarding the comments you mentioned in the other PR, I believe I've resolved them; I'm not understanding what the points in question are.

@braydonk
Copy link
Collaborator

Regarding the comments you mentioned in the other PR, I believe I've resolved them; I'm not understanding what the points in question are.

The particular comment that was undone was referring the begin and end both being returned from detectLinesChanged, see #294 (comment)

the local test output

Thanks for the test output. I'm sorry for sounding accusatory, I have to be cautious with the influx of AI Slop PRs.

The problem is that your local branch is not properly based on latest main. I approved the GitHub Actions on your latest commit so you can see the failure related to the code error I saw.

@slipknois
Copy link
Author

@braydonk can you review again please?

@braydonk
Copy link
Collaborator

2 things:

  1. Local branch still isn't rebased.
  2. How did you do the stdout.txt update? Did you use make integrationtest_update? If not, please do it with that (the diff might end up being the same)

@slipknois
Copy link
Author

  1. How did you do the stdout.txt update? Did you use make integrationtest_update? If not, please do it with that (the diff might end up being the same)

I used make integrationtest_update

@slipknois slipknois force-pushed the fix-gitlab-report-lines branch from d128552 to 32ee3ef Compare December 11, 2025 18:53
@slipknois
Copy link
Author

@braydonk Rebased

@slipknois slipknois requested a review from Hazer December 11, 2025 18:59
@slipknois
Copy link
Author

@braydonk can you review again? Still Waiting ur answer

Copy link
Collaborator

@braydonk braydonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to validate that this new codequality result will be properly loaded by Gitlab? I don't use Gitlab so I don't know and have no way of verifying.

t.Parallel()

testdataDir := "../../testdata/gitlab/changed_line"
print(testdataDir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

func TestCodeQuality_DetectChangedLine(t *testing.T) {
t.Parallel()

testdataDir := "../../testdata/gitlab/changed_line"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a new testdata directory in this package, rather than a new folder in the testdata package at the root of the project. So the path should just be ./testdata/changed_line from here.

begin = i + 1
}
lineNum := i + 1
end = &lineNum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will generate a lot of unnecessary heap garbage. This function should just return an int instead of *int so you can avoid that complexity.

original := strings.Split(string(diff.Diff.Original), "\n")
formatted := strings.Split(string(diff.Diff.Formatted), "\n")

max := len(original)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just use math.Max instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math.Max ​​is for float64, so you'll be entering int to float64 to int instructions without clearly gaining anything. I can't say if this is the best way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, perhaps we can use the max builtin` then.

formattedPath := filepath.Join(testdataDir, "formatted.yaml")

original, err := os.ReadFile(originalPath)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these tests should use the internal/assert package to assert their results instead of this if -> t.Fatal pattern.

}
}

func TestCodeQuality_DetectChangedLine(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a table test with more test cases. The testdata directory should have multiple different examples of changed lines. Some edge cases I would like to see:

  • No lines changed
  • All lines changed
  • One line changed
  • Only final line changed
  • Only change is one final line added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants