Skip to content
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
4 changes: 2 additions & 2 deletions commands/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func commandAuth(c *cli.Context) error {
SetupLogger(configDir)

// Generate JSON schema for IDE autocompletion
schemaFile := configDir + "/config.schema.json"
schemaFile := configDir + "/config-schema.json"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

To ensure platform-independent path construction, you should use filepath.Join instead of string concatenation with /. This will prevent potential issues on operating systems like Windows that use a different path separator. This follows the repository's general rule for path handling.

You'll need to add "path/filepath" to your imports.

Suggested change
schemaFile := configDir + "/config-schema.json"
schemaFile := filepath.Join(configDir, "config-schema.json")
References
  1. Use filepath.Join to combine path segments for platform independence, rather than hardcoding path separators.

if err := generateSchemaFile(schemaFile); err != nil {
slog.Warn("Failed to generate schema file", slog.Any("err", err))
}
Expand All @@ -58,7 +58,7 @@ func commandAuth(c *cli.Context) error {
return fmt.Errorf("failed to marshal default config: %w", err)
}
// Prepend $schema for IDE autocompletion support
schemaHeader := "# yaml-language-server: $schema=" + schemaFile + "\n"
schemaHeader := "# yaml-language-server: $schema=./config-schema.json\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The schema filename config-schema.json is hardcoded here, but it's already used to construct schemaFile on line 48. To avoid this duplication and improve maintainability, you can dynamically get the filename from the schemaFile path using filepath.Base().

This will require importing the path/filepath package.

Suggested change
schemaHeader := "# yaml-language-server: $schema=./config-schema.json\n"
schemaHeader := fmt.Sprintf("# yaml-language-server: $schema=./%s\n", filepath.Base(schemaFile))

content = append([]byte(schemaHeader), content...)
err = os.WriteFile(configFile, content, 0644)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type ShellTimeConfig struct {
DataMasking *bool `toml:"dataMasking" yaml:"dataMasking" json:"dataMasking"`

// for debug purpose
Endpoints []Endpoint `toml:"ENDPOINTS" yaml:"endpoints" json:"endpoints"`
Endpoints []Endpoint `toml:"ENDPOINTS,omitempty" yaml:"endpoints,omitempty" json:"endpoints,omitempty"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The TOML tag ENDPOINTS is in uppercase, which is inconsistent with the YAML and JSON tags (endpoints). More importantly, it contradicts your own documentation in docs/CONFIG.md (line 308) which uses [[endpoints]] (lowercase). To ensure consistency and align with your documentation, you should use a lowercase tag for TOML as well.

Suggested change
Endpoints []Endpoint `toml:"ENDPOINTS,omitempty" yaml:"endpoints,omitempty" json:"endpoints,omitempty"`
Endpoints []Endpoint `toml:"endpoints,omitempty" yaml:"endpoints,omitempty" json:"endpoints,omitempty"`


// WARNING
// This config will track each command metrics you run in current shell.
Expand Down