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

feat: Deprecated Function Checker #85

Merged
merged 3 commits into from
Oct 8, 2024
Merged

feat: Deprecated Function Checker #85

merged 3 commits into from
Oct 8, 2024

Conversation

notJoon
Copy link
Contributor

@notJoon notJoon commented Oct 7, 2024

Description

Add a deprecated functon checker that identifies the usage and suggests a alternative functions if possible.

Implementation Details

The core of this implementation is the DeprecatedFuncChecker struct type, which maintains a map of deprecated functions along with their alternative functions.

How Deprecated Functions are Recognized

  1. Registration: Deprecated functions are registered using thr Register method, which takes three parameters
    • Package name
    • Function name
    • Alternative function (packageName.funcName format)
  2. Function Call Identification: For each AST node, the checker looks for *ast.CallExpr nodes, which represent function calls.
  3. Selector Expression Analysis: It then checks if the function call is a selector expression (*ast.SelectorExpr), which is typical for package.Function() calls.
  4. Package and Function Matching: The checker extracts the package name and function name from the selector expression and compares them against the registered deprecated functions.

Usage Example

checker := NewDeprecatedFuncChecker()
checker.Register("fmt", "Println", "fmt.Print")
checker.Register("os", "Remove", "os.RemoveAll")

deprecated, err := checker.Check(filename, astNode, fileSet)
if err != nil {
    // Handle error
}

for _, dep := range deprecated {
    fmt.Printf("Deprecated function %s.%s used. Consider using %s instead.\n",
        dep.Package, dep.Function, dep.Alternative)
}

@notJoon notJoon added AST Require: working with AST or static analysis T-engine Type: related with engine (or internal) labels Oct 7, 2024
@notJoon notJoon marked this pull request as ready for review October 8, 2024 02:50
@notJoon notJoon added A-lint Adding or updating lint T-format Type: related with formatter labels Oct 8, 2024
@notJoon notJoon merged commit acccdf1 into main Oct 8, 2024
5 checks passed
@notJoon notJoon deleted the deprecated branch October 8, 2024 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Adding or updating lint AST Require: working with AST or static analysis T-engine Type: related with engine (or internal) T-format Type: related with formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant