Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated depsusage docs #25

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/depsusage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Dependency Usage Plugin
The depsusage plugin helps identify and analyze if and where dependencies are used within your codebase. The plugin scans codebase and identifies the imports and corresponding identifiers. It uses this identifier -> import association to identify actual usage of dependencies in rest of the code.

The depsusage plugin accepts a `depsusage.DependencyUsageCallback` which is invoked on capturing any evidence in the codebase. It has two parameters, `context.Context` and [depsusage.UsageEvidence](usageevidence.md)


### Usage example with plugin executor
```go
// callback to consume usage evidences
var usageCallback depsusage.DependencyUsageCallback = func(ctx context.Context, evidence *depsusage.UsageEvidence) error {
fmt.Println(evidence)
return nil
}

// Plugin instance
pluginExecutor, err := plugin.NewTreeWalkPluginExecutor(treeWalker, []core.Plugin{
depsusage.NewDependencyUsagePlugin(usageCallback),
})

// Execute plugin
pluginExecutor.Execute(context.Background(), fileSystem)

```

4 changes: 2 additions & 2 deletions docs/usageevidence.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Usag evidence
# Usage evidence

`UsageEvidence` represents the evidence of usage of a module item in a file. Fields -
`depsusage.UsageEvidence` represents the evidence of usage of a module in a file. It is generated in [depsusage](depsusage.md) plugin. Fields -

- PackageHint - string