HamzaHassanain/polyman

Simplify Config.json by Auto-Deriving Names from File Paths

開放

#12 建立於 2025年11月24日

 (0 則留言) (0 個反應) (0 位負責人)TypeScript (2 個分叉)auto 404
bugdocumentationenhancementgood first issuehelp wanted

倉庫指標

星標
 (33 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Currently, the Config.json file requires explicitly specifying a name field for solutions, generators, checkers, and validators, even though this name can be automatically derived from the file path. This creates unnecessary verbosity, increases the chance of typos/inconsistencies, and makes configuration more error-prone.

Current Configuration (Verbose):

{
  "solutions": [
    {
      "name": "main",
      "source": "./solutions/main.cpp",
      "tag": "MA",
      "sourceType": "cpp.g++17"
    },
    {
      "name": "correct2",
      "source": "./solutions/correct2.java",
      "tag": "OK",
      "sourceType": "java.11"
    }
  ],
  "generators": [
    {
      "name": "gen-random",
      "source": "./generators/gen-random.cpp"
    },
    {
      "name": "gen-edge",
      "source": "./generators/gen-edge.cpp"
    }
  ],
  "validator": {
    "name": "validator",
    "source": "./validator/validator.cpp"
  }
}

Derived names (automatic):

  • ./solutions/main.cpp → name: main
  • ./solutions/correct2.java → name: correct2
  • ./generators/gen-random.cpp → name: gen-random
  • ./validator/validator.cpp → name: validator

Keep name as optional

  • If name is present, use it (backward compatible)
  • If name is absent, derive it from source
  • Display deprecation warning if name is specified
interface LocalSolution {
  name?: string; // Optional now
  source: string;
  tag: SolutionTag;
  sourceType: SolutionSourceType;
}

function getSolutionName(solution: LocalSolution): string {
  if (solution.name) {
    // Deprecated: show warning
    console.warn(`[DEPRECATED] Explicit 'name' field is no longer needed for ${solution.source}`);
    return solution.name;
  }
  return deriveNameFromPath(solution.source);
}

貢獻者指南