Skip to content

miyamo2/tagcase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

tagcase - the Go struct tag formatter/linter/analyzer

GitHub stars Go Reference GitHub go.mod Go version Go Report Card Release Version License: MIT Ask DeepWiki GitMCP

Table of Contents

🎯 What is tagcase?

tagcase makes struct tags naming consistent throughout your Go project. Whether you are working with JSON APIs, databases, configurations, or anything else.

# yaml-language-server: $schema=https://raw.githubusercontent.com/miyamo2/tagcase/main/schema.json
tags:
  json:
    case: snake_case
  dynamodbav:
    case: camelCase
tagcase -w path/to/file.go
type User struct {
-    ID       int    `json:"user_id" dynamodbav:"UserID"`
-    Name     string `json:"userName" dynamodbav:"user_name"`  
-    Email    string `json:"Email" dynamodbav:"email"`
+    ID       int    `json:"user_id" dynamodbav:"userID"`
+    Name     string `json:"user_name" dynamodbav:"userName"`
+    Email    string `json:"email" dynamodbav:"email"`
}

✨ Key Features

  • 6 Case Formats
  • Flexible configuration
  • golangci-lint Plugin support
  • go vet Analyzer

⏳ Quick Start

▢️ Standalone CLI

Installation

# Go
go install github.com/miyamo2/tagcase@latest

# Homebrew
brew install miyamo2/tap/tagcase

Usage

# Check files for tag inconsistencies (shows diff)
tagcase -d path/to/file.go

# Fix formatting issues automatically
tagcase -w path/to/file.go

# Initialize configuration file
tagcase --init

πŸ”Ž Analyzer

Installation

# Go
go install github.com/miyamo2/tagcase/cmd/tagcase-analyzer@latest

# Homebrew
brew install miyamo2/tap/tagcase-analyzer

Usage

# Run analyzer on your Go project
go vet -vettool=$(which tagcase-analyzer) ./...

βš™οΈ Configuration

Create a .tagcase.yaml file to customize rules for your project:

# yaml-language-server: $schema=https://raw.githubusercontent.com/miyamo2/tagcase/main/schema.json
# Specify case conventions for different tag types
tags:
  json:
    # Supported cases: snake_case, camelCase, PascalCase, kebab-case, SNAKE_CASE, KEBAB-CASE
    case: snake_case
  db: 
    case: snake_case
  yaml:
    case: camelCase
  xml:
    case: PascalCase
# Custom initialism handling
initialism:
  enable:
    - API
    - UUID
  disable:
    - ID

πŸ§— Advance

golangci-lint Integration

  1. Add .custom-gcl.yml to your project root
version: v2.2.0
plugins:
  - module: 'github.com/miyamo2/tagcase'
    import: 'github.com/miyamo2/tagcase/pkg/golangci-lint/plugin'
    version: latest
  1. Build the custom golangci-lint
golangci-lint custom
  1. Add tagcase to your .golangci.yaml:
version: "2"
linters:
  settings:
    custom:
      tagcase:
        type: "module"
        settings:
          tags:
            db:
              case: snake_case
  1. Run the custom golangci-lint
./custom-gcl run ./...

🀝 Contributing

We welcome contributions! tagcase is built by the community, for the community.

πŸ“„ License

tagcase is released under the MIT License

About

Checking and standardizing the case conventions used in naming Go struct tags.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages