Help us shape the future of Go! Take the 2026 Go Developer Survey

codemod

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package codemod provides helpers for codemods and project automation.

Package codemod provides helpers for codemods and project automation. This file contains the copilot command and related functionality.

Package codemod provides helpers for codemods and project automation. This file contains the lint-setup command and related functionality.

Package codemod provides helpers for codemods and project automation. This file contains the prettier formatting command.

Index

Constants

This section is empty.

Variables

View Source
var CodemodCmd = &cobra.Command{
	Use:   "codemod",
	Short: "Helpers for codemods and project automation",
	Long:  `Run codemods or setup helpers for various project types.`,
}

CodemodCmd is the root command for codemod-related helpers and automation.

View Source
var CopilotSetupCmd = &cobra.Command{
	Use:   "copilot",
	Short: "Setup custom Copilot instructions file",
	Long:  `Create a base custom Copilot instructions file at .github/copilot-instructions.md. By default, this command assumes you are in the root of a Git repository. Use --force to bypass this check.`,
	Run: func(cmd *cobra.Command, _args []string) {
		force, _ := cmd.Flags().GetBool("force")

		if !force {
			if !isGitRepository() {
				log.Error("Not in a Git repository. Use --force to bypass this check.")
				return
			}
		}

		if err := createCopilotInstructions(); err != nil {
			log.Error("Failed to create Copilot instructions: %v", err)
			return
		}

		log.Success("Copilot instructions file created at .github/copilot-instructions.md")
	},
}

CopilotSetupCmd creates a base custom Copilot instructions file in .github/copilot-instructions.md.

View Source
var LintSetupCmd = &cobra.Command{
	Use:   "lint-setup",
	Short: "Setup linting and formatting for a Node.js project",
	Long:  `Install and configure linting, formatting, and pre-commit hooks for a Node.js project (eslint, prettier, husky, etc).`,
	Run: func(cmd *cobra.Command, _args []string) {
		if _, err := os.Stat("package.json"); errors.Is(err, os.ErrNotExist) {
			log.Error("package.json not found in current directory")
			return
		}

		if err := installLintDependencies(echo); err != nil {
			log.Error("npm install failed: %v", err)
			return
		}

		if err := writeESLintConfig(echo); err != nil {
			log.Error("Failed to write eslint.config.mjs: %v", err)
			return
		}

		if err := updatePackageJSON(); err != nil {
			log.Error("Failed to update package.json: %v", err)
			return
		}

		if err := setupHusky(); err != nil {
			log.Error("Failed to set up Husky: %v", err)
			return
		}

		log.Success("Linting, formatting, and pre-commit hooks are set up!")
	},
}

LintSetupCmd sets up linting, formatting, and pre-commit hooks for a Node.js project.

View Source
var PrettierCmd = &cobra.Command{
	Use:   "prettier [path]",
	Short: "Format code with prettier using @eng618/prettier-config",
	Long: `Format code with prettier, automatically installing @eng618/prettier-config if not available.
If no path is provided, formats the current directory.`,
	Run: func(cmd *cobra.Command, args []string) {

		targetPath := "."
		if len(args) > 0 {
			targetPath = args[0]
		}

		if err := runPrettier(targetPath); err != nil {
			log.Error("Failed to run prettier: %v", err)
			return
		}

		log.Success("Prettier formatting completed!")
	},
}

PrettierCmd formats the current directory with prettier, installing @eng618/prettier-config if needed.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL