lint: convert snake to camel case

This commit is contained in:
2026-10-24 18:56:45 -07:00
parent f8d79761f4
commit ef71828ce2
12 changed files with 100 additions and 101 deletions

View File

@@ -16,19 +16,19 @@ const (
)
func main() {
root_cmd := &cobra.Command{
rootCmd := &cobra.Command{
Use: "gas",
Version: version.String(),
SilenceErrors: true,
SilenceUsage: true,
}
// Print a bare version string ("v0.0.4"), rather than cobra's "gas version v0.0.4".
root_cmd.SetVersionTemplate("{{.Version}}\n")
root_cmd.AddCommand(sqlite_lint)
root_cmd.AddCommand(cmd_init)
root_cmd.AddCommand(generate_model)
root_cmd.AddCommand(cmd_version)
if err := root_cmd.Execute(); err != nil {
rootCmd.SetVersionTemplate("{{.Version}}\n")
rootCmd.AddCommand(sqliteLint)
rootCmd.AddCommand(cmdInit)
rootCmd.AddCommand(generateModel)
rootCmd.AddCommand(cmdVersion)
if err := rootCmd.Execute(); err != nil {
fmt.Println(RED + err.Error() + RESET)
os.Exit(1)
}

View File

@@ -17,7 +17,7 @@ import (
var ErrNoSuchTable = errors.New("no such table")
var generate_model = &cobra.Command{
var generateModel = &cobra.Command{
Use: "generate <model_name>",
Short: "Generate a model type",
@@ -119,7 +119,7 @@ var generate_model = &cobra.Command{
}
func init() {
generate_model.Flags().String("schema", "pkg/db/schema.sql", "Path to SQL schema file")
generate_model.Flags().String("modname", "mymodule", "Name of project's Go module (TODO: detect automatically)")
generate_model.Flags().Bool("test", false, "Generate test file instead of regular file")
generateModel.Flags().String("schema", "pkg/db/schema.sql", "Path to SQL schema file")
generateModel.Flags().String("modname", "mymodule", "Name of project's Go module (TODO: detect automatically)")
generateModel.Flags().Bool("test", false, "Generate test file instead of regular file")
}

View File

@@ -12,7 +12,7 @@ import (
"git.offline-twitter.com/offline-labs/gas-stack/pkg/must"
)
var cmd_init = &cobra.Command{
var cmdInit = &cobra.Command{
Use: "init [path]",
Short: "Initialize a new project",
Long: "Initialize a new Gas Stack project at the given path. If no path is given, defaults to current directory.",
@@ -31,7 +31,7 @@ var cmd_init = &cobra.Command{
}
// Get all the config values
get_val := func(prompt string, val *string) {
getVal := func(prompt string, val *string) {
fmt.Printf("%s (%q): ", prompt, *val)
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
@@ -40,31 +40,31 @@ var cmd_init = &cobra.Command{
*val = input
}
}
pkg_opts := codegen.PkgOpts{
pkgOpts := codegen.PkgOpts{
ModuleName: must.Get(cmd.Flags().GetString("module")),
DBFilename: must.Get(cmd.Flags().GetString("db")),
BinaryName: must.Get(cmd.Flags().GetString("binary")),
}
if pkg_opts.ModuleName == "" {
pkg_opts.ModuleName = filepath.Base(target)
get_val("module name", &pkg_opts.ModuleName)
if pkgOpts.ModuleName == "" {
pkgOpts.ModuleName = filepath.Base(target)
getVal("module name", &pkgOpts.ModuleName)
}
if pkg_opts.DBFilename == "" {
pkg_opts.DBFilename = pkg_opts.ModuleName + ".db"
get_val("db name", &pkg_opts.DBFilename)
if pkgOpts.DBFilename == "" {
pkgOpts.DBFilename = pkgOpts.ModuleName + ".db"
getVal("db name", &pkgOpts.DBFilename)
}
if pkg_opts.BinaryName == "" {
pkg_opts.BinaryName = pkg_opts.ModuleName
get_val("binary name", &pkg_opts.BinaryName)
if pkgOpts.BinaryName == "" {
pkgOpts.BinaryName = pkgOpts.ModuleName
getVal("binary name", &pkgOpts.BinaryName)
}
// Run project initialization
codegen.InitPkg(pkg_opts)
codegen.InitPkg(pkgOpts)
},
}
func init() {
cmd_init.Flags().String("module", "", "Module name")
cmd_init.Flags().String("db", "", "Database filename")
cmd_init.Flags().String("binary", "", "Binary name")
cmdInit.Flags().String("module", "", "Module name")
cmdInit.Flags().String("db", "", "Database filename")
cmdInit.Flags().String("binary", "", "Binary name")
}

View File

@@ -12,7 +12,7 @@ import (
"git.offline-twitter.com/offline-labs/gas-stack/pkg/schema/lint"
)
var sqlite_lint = &cobra.Command{
var sqliteLint = &cobra.Command{
Use: "sqlite_lint <path/to/schema.sql>",
Short: "Lint a SQLite schema",
@@ -32,18 +32,18 @@ var sqlite_lint = &cobra.Command{
os.Exit(1)
}
is_failure := false
isFailure := false
// Execute each check against the database
for _, check := range lint.Checks {
// Checks can be disabled via Github config / environment variables
if !is_check_enabled(check) {
if !isCheckEnabled(check) {
continue
}
results := check.Execute(schema)
// If there are results, print them as lint errors
if len(results) > 0 {
is_failure = true
isFailure = true
fmt.Printf(RED+"Check '%s' failed:\n"+RESET, check.Name)
for _, result := range results {
fmt.Printf(RED+"- %s: %s.%s\n"+RESET, result.ErrorMsg, result.TableName, result.ColumnName)
@@ -51,7 +51,7 @@ var sqlite_lint = &cobra.Command{
fmt.Printf(RED+"Explanation: %s\n\n"+RESET, check.Explanation)
}
}
if is_failure {
if isFailure {
fmt.Println(RED + "Errors found" + RESET)
os.Exit(1)
}
@@ -61,16 +61,16 @@ var sqlite_lint = &cobra.Command{
// github_actions_input_env_var converts an input name to the corresponding
// environment variable name used by GitHub Actions.
func github_actions_input_env_var(name string) string {
func githubActionsInputEnvVar(name string) string {
// GitHub normalizes both hyphens and underscores to underscores, then uppercases the name
normalized := strings.NewReplacer("-", "_", " ", "_").Replace(name)
return "INPUT_" + strings.ToUpper(normalized)
}
// Setting the environment variable INPUT_REQUIRE_NOT_NULL="false" disables the "require_not_null" check
func is_check_enabled(c lint.Check) bool {
val, is_set := os.LookupEnv(github_actions_input_env_var(c.Name))
if !is_set {
func isCheckEnabled(c lint.Check) bool {
val, isSet := os.LookupEnv(githubActionsInputEnvVar(c.Name))
if !isSet {
// Enable all checks by default
return true
}

View File

@@ -8,7 +8,7 @@ import (
"git.offline-twitter.com/offline-labs/gas-stack/pkg/version"
)
var cmd_version = &cobra.Command{
var cmdVersion = &cobra.Command{
Use: "version",
Short: "Print the version of `gas`",
Args: cobra.NoArgs,