fix: implement missing diagnostics-format options in validate command (#2007)#2070
Closed
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
Closed
fix: implement missing diagnostics-format options in validate command (#2007)#2070chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
Conversation
…asyncapi#2007) The validate command advertised 12 --diagnostics-format options in its help text (github-actions, sarif, code-climate, gitlab, markdown) but these formats were not handled in formatDiagnosticsOutput() and fell through to the default stylish formatter, producing unexpected output. Changes: - Import codeClimate, githubActions, sarif, markdown from @stoplight/spectral-formatters - Add github-actions, sarif, code-climate, gitlab, markdown cases to the switch statement in formatDiagnosticsOutput() - Add the missing formats to DiagnosticsFormat type in interfaces/index.ts - Add file extensions for new formats in formatExtensions map (.txt, .json, .md) - Add formats to the validFormats list Note: gitlab format is not a distinct formatter in @stoplight/spectral-formatters; GitLab CI natively consumes Code Climate JSON, so gitlab falls back to codeClimate. Fixes asyncapi#2007
🦋 Changeset detectedLatest commit: 2b696c1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes #2007
The
validatecommand's--diagnostics-formatflag advertises 12 format options in its--helpoutput (github-actions,sarif,code-climate,gitlab,markdown), but these 5 formats were silently falling through to thedefaultcase informatDiagnosticsOutput(), producingstylishoutput regardless of what the user specified.Root Cause
formatDiagnosticsOutput()invalidation.service.tsonly handled 7 of the 12 formats in itsswitchstatement. The other 5 fell todefault: return stylish(...). Additionally,DiagnosticsFormattype andformatExtensionsmap did not include the missing formats.Changes
src/domains/services/validation.service.ts:codeClimate,githubActions,sarif,markdownfrom@stoplight/spectral-formatterscase 'github-actions',case 'sarif',case 'code-climate',case 'gitlab',case 'markdown'to theformatDiagnosticsOutput()switchformatExtensions(github-actions: .txt,sarif: .json,code-climate: .json,gitlab: .json,markdown: .md)validFormatslistsrc/interfaces/index.ts:DiagnosticsFormattype union with the 5 missing formatsNotes
gitlabformat is not a distinct function in@stoplight/spectral-formatters— GitLab CI natively ingests Code Climate JSON, sogitlabdelegates tocodeClimategithubActions,sarif,codeClimate,markdown) are already present and exported from@stoplight/spectral-formatters(already a dependency) — no new dependencies addedTest plan
asyncapi validate spec.yaml --diagnostics-format=github-actionsproduces GitHub Actions annotation formatasyncapi validate spec.yaml --diagnostics-format=sarifproduces SARIF JSON outputasyncapi validate spec.yaml --diagnostics-format=code-climateproduces Code Climate JSONasyncapi validate spec.yaml --diagnostics-format=gitlabproduces Code Climate JSON (GitLab format)asyncapi validate spec.yaml --diagnostics-format=markdownproduces Markdown output