ossf / ossf/package-analysis

Make approach to defining enums consistent across the project

Open
#663 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

go internal cleanup needs discussion
Dominant language
Go
Stars
912
Forks
74
PR merge metrics
No merged PRs in 30d

Description

#654 introduces the enum type Ecosystem implemented differently to other enums (e.g. analysis.Mode and staticanalysis.Task and analysisrun.DynamicPhase)

We should develop a consistent approach to how we define enums:

Some areas that should be covered:

  • should the base type be string vs numeric
  • how do we handle lists of enums
  • how do enums interact with flags
  • how do enums handle serialization (JSON)

Both:

  • require String()

Numeric based enums:

  • can use iota
  • can consume as little as 8bits (byte)
  • very fast to compare equality
  • encoding.TextMarshaler and encoding.TextUnmarshaler needed to support flag.TextVar and json serialization
  • requires strings to be specified for marshaling and unmarshaling (although an array of strings may make this easier)

String based enums:

  • consume 128 bits per enum
  • simpler String() function and serialization
  • equality is more costly (at minimum two comparisons, maximum the size of the shortest string)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the enum definitions introduced by #654 for Ecosystem with analysis.Mode, staticanalysis.Task, and analysisrun.DynamicPhase. Review how each handles strings, lists, flags, JSON serialization, and String(), then agree on a single documented approach covering numeric versus string bases and required marshaling behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.