Skip to content

Move from File-Level to Pacakge-Level Parsing for Improved Linting #130

@notJoon

Description

@notJoon

Description

Currently, tlin's linting process handles .gno files by converting them into temporary .go files (see, prepareFile function) and parsing them one by one. This file-by-file approach has several drawbacks:

  1. Reduced Accuracy:
    • Parsing files in isolation can miss important cross-file references and package-level contexts.
  2. Performance Overhead:
    • Repeatedly creating temporary .go files and parsing each file separately is inefficient.
    • Analyzing multiple .gno files within the same package context would reduce parsing overhead and improve overall speed.

Proposed Solution

  1. Create a Temporary Directory Structure

    • Instead of generating a single .go temp file per .gno file, copy or convert all .gno files in a package into a temporary directory, renaming them with a .go extension.
    • Preserve the directory/package structure so golangci-lint can parse them as it would standard go files.
  2. Parse Using Package-Level APIs

    • Switch from go/parser.ParseFile (file-centric) to go/parser.ParseDir or similar package-level APIs to load all files in a directory at once.
    • This allows cross-file symbol resolution and more accurate AST analysis.
  3. Maintain nolint and Ignore Logic

    • Ensure that nolint comments and path ignores still apply correctly across multiple files within the package.

Note

Before proceeding with the task, benchmarks related to current file processing and parsing should be added first. Then the results should be compared after the modifications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-performanceLint: performanceT-engineType: related with engine (or internal)good first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions