readonly

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 4 Imported by: 0

README

readonly

readonly is a Go linter that enforces the immutability of struct fields, preventing modifications from outside their package.

This tool offers a simpler alternative to getter methods.

Installation

go install github.com/devinalvaro/readonly/cmd/readonly@latest

Usage

readonly [package]

Example

Consider the following struct:

package example

type Config struct {
	Name  string `readonly:"enforce"`
	Value string
}

readonly will report an error if Config.Name is modified from outside the example package.

Another example:

package example

type Config struct {
	Name  string `readonly:"enforce_all"`
	Value string
}

readonly now enforces both Config.Name and Config.Value.

Testing

The test file shows all cases that readonly covers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnalyzer

func NewAnalyzer() *analysis.Analyzer

Types

This section is empty.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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