Skip to content
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

Multiple updates #253

Merged
merged 5 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/build_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
"os"
)

func BuildResults(rulesetFlag string, specBytes []byte, customFunctions map[string]model.RuleFunction) (*model.RuleResultSet, *motor.RuleSetExecutionResult, error) {
func BuildResults(
rulesetFlag string,
specBytes []byte,
customFunctions map[string]model.RuleFunction,
base string) (*model.RuleResultSet, *motor.RuleSetExecutionResult, error) {

// read spec and parse
defaultRuleSets := rulesets.BuildDefaultRuleSets()
Expand Down Expand Up @@ -36,6 +40,7 @@ func BuildResults(rulesetFlag string, specBytes []byte, customFunctions map[stri
RuleSet: selectedRS,
Spec: specBytes,
CustomFunctions: customFunctions,
Base: base,
})

resultSet := model.NewRuleResultSet(ruleset.Results)
Expand Down
2 changes: 1 addition & 1 deletion cmd/build_results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func TestBuildResults(t *testing.T) {
_, _, err := BuildResults("nuggets", nil, nil)
_, _, err := BuildResults("nuggets", nil, nil, "")
assert.Error(t, err)
}
18 changes: 16 additions & 2 deletions cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"net/url"
"time"
)

Expand All @@ -39,6 +40,7 @@ func GetDashboardCommand() *cobra.Command {
pterm.Println()
return errors.New(errText)
}
baseFlag, _ := cmd.Flags().GetString("base")

var err error
vacuumReport, specBytes, _ := vacuum_report.BuildVacuumReportFromFile(args[0])
Expand All @@ -59,7 +61,7 @@ func GetDashboardCommand() *cobra.Command {
customFunctions, _ := LoadCustomFunctions(functionsFlag)

rulesetFlag, _ := cmd.Flags().GetString("ruleset")
resultSet, ruleset, err = BuildResults(rulesetFlag, specBytes, customFunctions)
resultSet, ruleset, err = BuildResults(rulesetFlag, specBytes, customFunctions, baseFlag)
if err != nil {
pterm.Error.Printf("Failed to render dashboard: %v\n\n", err)
return err
Expand All @@ -82,7 +84,19 @@ func GetDashboardCommand() *cobra.Command {
return err
}

config := index.CreateOpenAPIIndexConfig()
config := index.CreateClosedAPIIndexConfig()
if baseFlag != "" {
u, e := url.Parse(baseFlag)
if e == nil && u.Scheme != "" && u.Host != "" {
config.BaseURL = u
config.BasePath = ""
} else {
config.BasePath = baseFlag
}
config.AllowFileLookup = true
config.AllowRemoteLookup = true
}

specIndex = index.NewSpecIndexWithConfig(&rootNode, config)

specInfo = vacuumReport.SpecInfo
Expand Down
3 changes: 2 additions & 1 deletion cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func GetHTMLReportCommand() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {

noStyleFlag, _ := cmd.Flags().GetBool("no-style")
baseFlag, _ := cmd.Flags().GetString("base")

// disable color and styling, for CI/CD use.
// https://github.com/daveshanley/vacuum/issues/234
Expand Down Expand Up @@ -91,7 +92,7 @@ func GetHTMLReportCommand() *cobra.Command {
customFunctions, _ := LoadCustomFunctions(functionsFlag)

rulesetFlag, _ := cmd.Flags().GetString("ruleset")
resultSet, ruleset, err = BuildResults(rulesetFlag, specBytes, customFunctions)
resultSet, ruleset, err = BuildResults(rulesetFlag, specBytes, customFunctions, baseFlag)
if err != nil {
pterm.Error.Printf("Failed to generate report: %v\n\n", err)
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func GetLintCommand() *cobra.Command {
functionsFlag, _ := cmd.Flags().GetString("functions")
failSeverityFlag, _ := cmd.Flags().GetString("fail-severity")
noStyleFlag, _ := cmd.Flags().GetBool("no-style")
baseFlag, _ := cmd.Flags().GetString("base")

// disable color and styling, for CI/CD use.
// https://github.com/daveshanley/vacuum/issues/234
Expand Down Expand Up @@ -106,6 +107,7 @@ func GetLintCommand() *cobra.Command {
RuleSet: selectedRS,
Spec: specBytes,
CustomFunctions: customFunctions,
Base: baseFlag,
})

results := result.Results
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func init() {
rootCmd.PersistentFlags().BoolP("time", "t", false, "Show how long vacuum took to run")
rootCmd.PersistentFlags().StringP("ruleset", "r", "", "Path to a spectral ruleset configuration")
rootCmd.PersistentFlags().StringP("functions", "f", "", "Path to custom functions")
rootCmd.PersistentFlags().StringP("base", "p", "", "Base URL or path to use for resolving relative or remote references")

regErr := rootCmd.RegisterFlagCompletionFunc("functions", cobra.FixedCompletions(
[]string{"so"}, cobra.ShellCompDirectiveFilterFileExt,
Expand Down
5 changes: 2 additions & 3 deletions cmd/shared_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ func CheckFailureSeverity(failSeverityFlag string, errors int, warnings int, inf
if failSeverityFlag != model.SeverityError {
switch failSeverityFlag {
case model.SeverityWarn:
if warnings > 0 {
if warnings > 0 || errors > 0 {
return fmt.Errorf("failed linting, with %d errors and %d warnings", errors, warnings)
}
return nil
case model.SeverityInfo:
if informs > 0 {
if informs > 0 || warnings > 0 || errors > 0 {
return fmt.Errorf("failed linting, with %d errors, %d warnings and %d informs",
errors, warnings, informs)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/spectral_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func GetSpectralReportCommand() *cobra.Command {
stdIn, _ := cmd.Flags().GetBool("stdin")
stdOut, _ := cmd.Flags().GetBool("stdout")
noStyleFlag, _ := cmd.Flags().GetBool("no-style")
baseFlag, _ := cmd.Flags().GetString("base")

// disable color and styling, for CI/CD use.
// https://github.com/daveshanley/vacuum/issues/234
Expand Down Expand Up @@ -133,6 +134,7 @@ func GetSpectralReportCommand() *cobra.Command {
Spec: specBytes,
CustomFunctions: customFunctions,
SilenceLogs: true,
Base: baseFlag,
})

resultSet := model.NewRuleResultSet(ruleset.Results)
Expand Down
28 changes: 28 additions & 0 deletions cmd/vacuum_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func GetVacuumReportCommand() *cobra.Command {
stdIn, _ := cmd.Flags().GetBool("stdin")
stdOut, _ := cmd.Flags().GetBool("stdout")
noStyleFlag, _ := cmd.Flags().GetBool("no-style")
baseFlag, _ := cmd.Flags().GetString("base")
junitFlag, _ := cmd.Flags().GetBool("junit")

// disable color and styling, for CI/CD use.
// https://github.com/daveshanley/vacuum/issues/234
Expand Down Expand Up @@ -134,13 +136,38 @@ func GetVacuumReportCommand() *cobra.Command {
Spec: specBytes,
CustomFunctions: customFunctions,
SilenceLogs: true,
Base: baseFlag,
})

resultSet := model.NewRuleResultSet(ruleset.Results)
resultSet.SortResultsByLineNumber()

duration := time.Since(start)

// if we want jUnit output, then build the report and be done with it.
if junitFlag {
junitXML := vacuum_report.BuildJUnitReport(resultSet, start)
if stdOut {
fmt.Print(string(junitXML))
return nil
} else {

reportOutputName := fmt.Sprintf("%s-%s%s",
reportOutput, time.Now().Format("01-02-06-15_04_05"), ".xml")

err := os.WriteFile(reportOutputName, junitXML, 0664)
if err != nil {
pterm.Error.Printf("Unable to write junit report file: '%s': %s\n", reportOutputName, err.Error())
pterm.Println()
return err
}

pterm.Success.Printf("JUnit Report generated for '%s', written to '%s'\n", args[0], reportOutputName)
pterm.Println()
return nil
}
}

// pre-render
resultSet.PrepareForSerialization(ruleset.SpecInfo)

Expand Down Expand Up @@ -208,6 +235,7 @@ func GetVacuumReportCommand() *cobra.Command {
}
cmd.Flags().BoolP("stdin", "i", false, "Use stdin as input, instead of a file")
cmd.Flags().BoolP("stdout", "o", false, "Use stdout as output, instead of a file")
cmd.Flags().BoolP("junit", "j", false, "Generate report in JUnit format (cannot be compressed)")
cmd.Flags().BoolP("compress", "c", false, "Compress results using gzip")
cmd.Flags().BoolP("no-pretty", "n", false, "Render JSON with no formatting")
cmd.Flags().BoolP("no-style", "q", false, "Disable styling and color output, just plain text (useful for CI/CD)")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gizak/termui/v3 v3.1.0
github.com/json-iterator/go v1.1.12
github.com/mitchellh/mapstructure v1.5.0
github.com/pb33f/libopenapi v0.6.1
github.com/pb33f/libopenapi v0.7.0
github.com/pterm/pterm v0.12.54
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0
github.com/spf13/cobra v1.6.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ github.com/pb33f/libopenapi v0.6.0 h1:omj3g89XbT/RaafrzdRQFEDsyLRZsnkV7Q+1zCEhFd
github.com/pb33f/libopenapi v0.6.0/go.mod h1:lvUmCtjgHUGVj6WzN3I5/CS9wkXtyN3Ykjh6ZZP5lrI=
github.com/pb33f/libopenapi v0.6.1 h1:AXnfXFVVK+bXgUeLYPJqLk8y/8Ow4Nercx1dabT2xog=
github.com/pb33f/libopenapi v0.6.1/go.mod h1:lvUmCtjgHUGVj6WzN3I5/CS9wkXtyN3Ykjh6ZZP5lrI=
github.com/pb33f/libopenapi v0.7.0 h1:2mQgDa0UQs8/5Hd2z+KbgWvoGx0++N3ihMKihcAS5Mw=
github.com/pb33f/libopenapi v0.7.0/go.mod h1:lvUmCtjgHUGVj6WzN3I5/CS9wkXtyN3Ykjh6ZZP5lrI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
50 changes: 25 additions & 25 deletions html-report/ui/build/static/js/vacuumReport.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions html-report/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
},
"devDependencies": {
"@open-wc/eslint-config": "^7.0.0",
"@open-wc/eslint-config": "^10.0.0",
"@types/chart.js": "^2.9.37",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@web/dev-server-esbuild": "^0.3.3",
"@web/test-runner": "^0.14.0",
"@web/test-runner": "^0.15.1",
"@web/test-runner-commands": "^0.6.5",
"@web/test-runner-playwright": "^0.8.10",
"@web/test-runner-playwright": "^0.9.0",
"copy-webpack-plugin": "^11.0.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -34,18 +34,18 @@
"mini-css-extract-plugin": "^2.6.1",
"prettier": "^2.7.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1"
},
"dependencies": {
"@open-wc/testing": "^3.1.7",
"chart.js": "^3.9.1",
"chart.js": "^4.2.1",
"css-loader": "^6.7.1",
"lit": "^2.4.1",
"style-loader": "^3.3.1",
"terminal.css": "^0.7.2",
"ts-loader": "^9.4.1",
"typescript": "^4.9.3"
"typescript": "^5.0.2"
},
"eslintConfig": {
"parser": "@typescript-eslint/parser",
Expand Down
Loading