todocheck

presmihaylovMIT活跃维护

扫描代码里带注解的 TODO 注释并做静态检查,帮团队把待办事项管起来,避免遗漏或格式混乱。

A static code analyser for annotated TODO comments

v0.6.1发布于 2023-10-14 10:23 UTC440star46fork同步于 2026-11-10 23:58 UTC

怎么上手

由 README 提炼,执行前请确认
brew install preslavmihaylov/taps/todocheck
docker run -it -v /path/to/project:/project -e TODOCHECK_AUTH_TOKEN=your_token ghcr.io/preslavmihaylov/todocheck --basepath /project
硬件要求按 README 说明

README 未说明;提供各操作系统预编译二进制与容器镜像,无需 GPU

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

静态扫描带 issue 编号的 TODO 注释,校验关联 issue 是否仍开放,防止代码里留下失效 TODO

扫描代码里带注解的 TODO 注释并做静态检查,帮团队把待办事项管起来,避免遗漏或格式混乱。

核心能力

  • 解析 TODO 注释中关联的 issue 编号并查询其状态
  • issue 已关闭或不存在时报告错误
  • 未标注 issue 的 TODO 视为 malformed 并报错
  • 支持 GitHub、GitLab、Jira、Redmine、YouTrack 等追踪器
  • 可接入 CI 流程,阻止带未完成 TODO 的 issue 被关闭

容易踩的坑

私有仓库需在 .todocheck.yaml 配置 auth 段并首次运行时输入 personal access token;从非项目根目录运行时须用 --basepath 指定项目路径,否则找不到配置;Redmine 需先在服务端启用 REST API 才能集成

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.6.1
  1. v0.6.1todocheck v0.6.1最新正式版2023-10-14 · 2023-10-14 10:23 UTC

    Features

    N/A

    Bug fixes

    N/A

    Breaking Changes

    N/A

    Internal Improvements

    • Fixed CI and upgraded to Go version
  2. v0.6.0todocheck v0.6.02022-10-09 · 2022-10-09 08:18 UTC
    查看更新说明

    Features

    • Added support for Dart source files (#186)
    • Added support for YAML source files (#194)
    • Setup a docker registry for the repo for easier integration into CI (#192)

    Bug fixes

    • Exit program when an unrecognized flag is passed (#181)
    • Auth Token Cache overrides tokens passed via an env variable (#175)
    • top-level domains with a dash ("-") were incorrectly considered invalid (#193)
    • Authentication didn't work for JIRA servers prior to v9 (#198)

    Breaking Changes

    N/A

    Internal Improvements

    • Add tests for validating token acquisition instructions (#130)
    • Fix issues with golangci-lint (#187)
    • Added unit tests for some internal packages (#185)
  3. v0.5.0todocheck v0.5.02022-02-12 · 2022-02-12 15:52 UTC
    查看更新说明

    Features

    • Add support for Kotlin (#156)
    • Add support for Nim (#160)
    • Add support for JIRA via API tokens (#174)
    • Extend JSON output to include linked issue & other metadata (#164)
    • Add support for case-insensitive TODOs (#167)

    Bug fixes

    N/A

    Breaking Changes

    N/A

    Internal Improvements

    • Add linter to CI job (#166)
  4. 0.4.1todocheck v0.4.12021-08-11 · 2021-08-11 06:49 UTC
    查看更新说明

    Features

    N/A

    Bug fixes

    • Fixed integration with YouTrack, which didn't work for all youtrack project instances (#159)

    Breaking Changes

    N/A

    Internal Improvements

    N/A

  5. v0.4.0todocheck v0.4.02021-07-24 · 2021-07-24 10:22 UTC
    查看更新说明

    Features

    • Support for custom TODO comment format is added! (#53)
    • Show warning for missing API token for github public projects (#63)
    • Added support for VueJS files (#107)
    • Added integration with YouTrack (#38)
    • Added integration with AzureBoards (#31)
    • Show an error for incorrect auth type in config (#71)
    • Enabled issue annotations with hashtag in TODO comments (#80)
    • Added flag --verbose for verbose logging (#95)
    • Add validation to ensure offline_url is specified when using offline authentication (#129)

    Bug fixes

    N/A

    Breaking Changes

    N/A

    Internal Improvements

    • Extended testing framework & added tests for JSON output (#23)
    • Added integration tests for verifying production integration with all supported issue trackers (#120)
    • Added Code of Conduct (#139)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    todocheck logo

    todocheck

    todocheck is a static code analyzer for annotated TODO comments.

    It let's you create actionable TODOs by annotating them with issues from any of the supported issue trackers.
    No longer will you discover arcane, undocumented TODO comments, scattered across your code base.

    See How it works for more info.

    Table of Contents

    How it works

    Here's an example of an annotated TODO:

    // TODO J123: Fix this typo
    func fuu() {
        ...
    }
    

    In case the linked issue J123 is open, todocheck will not report any error. In case it is closed or doesn't exist, todocheck will show an error:

    ERROR: Issue is closed.
    myproject/main.go:12: // TODO J123: Fix this typo
    
    ERROR: Issue doesn't exist.
    myproject/main.go:14: // TODO J321: A non-existent issue
    

    If there is an unannotated TODO in your code base, todocheck will also report it as a malformed TODO:

    ERROR: Malformed todo.
    myproject/main.go:16: // TODO - This is not a valid annotated todo
    

    todocheck demo gif

    Only TODOs with valid, open issues are allowed to exist in the codebase.

    By integrating todocheck in your development workflow & CI pipeline, you can ensure that there will be no half-baked issue closed with pending TODOs in the codebase.

    Installation

    Via homebrew

    brew install preslavmihaylov/taps/todocheck
    

    Download prebuilt binary

    Download the binary for your OS from the latest release.

    Optionally verify the sha256 checksum:

    • For macos, run shasum -a 256 <binary> & verify it's the same as <binary>.sha256
    • For linux, run sha256sum <binary>
    • For windows, use a SHA256 checksum utility

    Afterwards, verify the shasum is the same as <binary>.sha256.

    Place the binary in a folder, shined upon by your $PATH.

    • For macos & linux, that's typically /usr/local/bin/

    Using a Container

    Alternatively to installing the todocheck binary on your system you may use a prebuilt container image from the GitHub container registry, e.g.:

    docker run -it -v /path/to/project:/project -e TODOCHECK_AUTH_TOKEN=your_token ghcr.io/preslavmihaylov/todocheck --basepath /project
    

    For a complete list of container tags visit the Packages section on the GitHub project page. For a complete list of docker run options visit the Docker documentation.

    Quickstart

    First, you need to configure todocheck's integration with your issue tracker. This is done by creating a .todocheck.yaml file in the root of your project.

    For public github or gitlab repositories, you don't need to specify a config file, as long as you are using git, as todocheck will interpret your issue tracker from the git configuration.

    Alternatively, the explicit configuration for a public github repository would look like this:

    origin: github.com/user/repository
    issue_tracker: GITHUB
    

    See Supported Issue Trackers for more issue tracker options.

    After the config file is in place, simply run todocheck from the root of your project.

    In case you are running todocheck from a different directory, you can specify your project's path using the --basepath flag and the project configuration with --config:

    $ todocheck --basepath path/to/project --config path/to/config/.todocheck.yaml
    

    If the --config option is not specified, the configuration in the basepath will be used.
    In the example above, it would look for it in path/to/project/.todocheck.yaml.

    Supported Issue Trackers

    Currently, todocheck supports the following issue trackers:

    Issue TrackerDescription
    GithubBoth public & private repositories are supported
    GitlabBoth public & private repositories are supported
    JiraSupported via offline and API tokens
    Pivotal TrackerSupported via an API token
    RedmineSupports public access with no auth & private access via an API token
    YouTrackSupported via an API token
    Azure BoardsSupports public access with no auth & private access via an API token

    Github

    To integrate with a public github repository, there's no need to provide a .todocheck.yaml explicitly as it can automatically detect the issue tracker based on the git remote address. And if you want to be explicit, please specify the origin of your repo and the GITHUB issue tracker in your .todocheck.yaml configuration:

    origin: github.com/user/repository
    issue_tracker: GITHUB
    

    To integrate with a private github repository, you'll also need to specify the auth section with the apitoken type:

    origin: github.com/user/repository
    issue_tracker: GITHUB
    auth:
      type: apitoken
    

    The first time you run the application, it will ask for your personal access token: todocheck Github PAT Prompt

    After you've specified it, it will store it in the auth tokens cache for subsequent executions. See the Authentication section for more info.

    Gitlab

    To integrate with a public gitlab repository, there's no need to provide a .todocheck.yaml explicitly as it can automatically detect the issue tracker based on the git remote address. And if you want to be explicit, please specify the origin of your repo and the GITLAB issue tracker in your .todocheck.yaml configuration:

    origin: gitlab.com/user/repository
    issue_tracker: GITLAB
    

    To integrate with a private gitlab repository, you'll also need to specify the auth section with the apitoken type:

    origin: gitlab.com/user/repository
    issue_tracker: GITLAB
    auth:
      type: apitoken
    

    The first time you run the application, it will ask for your personal access token:

    After you've specified it, it will store it in the auth tokens cache for subsequent executions. See the Authentication section for more info.

    Jira

    To integrate with your organization's Jira, you'll need to specify JIRA as your issue tracker, the origin of your jira server instance.

    Along with that, you'll need to setup auth based on your preferred authentication method.

    API Token

    To use JIRA with an API token, you'll need to have an Atlassian user which you can use to issue an API token.
    You'll also need to specify your Atlassian username.

    Example:

    origin: https://myawesomeorg.atlassian.net
    issue_tracker: JIRA
    auth:
      type: apitoken
      options:
        username: [email protected]
    

    For more info on how authentication works, see the Authentication section.

    Offline Token

    For more info, see offline token.

    Example:

    origin: https://myjira.awesomeorg.com
    issue_tracker: JIRA
    auth:
      type: offline
      offline_url: https://myjira.awesomeorg.com/offline
    

    After you run todocheck for the first time, it will request your offline token: Offline token prompt example

    Example offline token page: Offline token page example

    After you've given the offline token to todocheck's prompt, it will store it in the auth tokens cache for subsequent executions.

    See the Authentication section for more info.

    Pivotal Tracker

    To integrate with a pivotal tracker project, specify the origin of your project and the PIVOTAL_TRACKER issue tracker in your .todocheck.yaml configuration.
    You should also specify the apitoken as an auth type:

    origin: pivotaltracker.com/projects/PROJECT_ID
    issue_tracker: PIVOTAL_TRACKER
    auth:
      type: apitoken
    

    The first time you run the application, it will ask for your API Token.

    After you've specified it, it will store it in the auth tokens cache for subsequent executions. See the Authentication section for more info.

    Redmine

    To integrate with a redmine issue tracker project, specify the origin of your installation (without project path) and the REDMINE issue tracker in your .todocheck.yaml configuration.

    You should also specify the apitoken as an auth type if you have authentication enabled on your server:

    origin: https://redmine.mycorp.com
    issue_tracker: REDMINE
    auth:
      type: apitoken
    

    Alternatively, if no authentication is required, don't include the auth section.

    The first time you run the application, it will ask for your API Token.

    After you've specified it, it will store it in the auth tokens cache for subsequent executions. See the Authentication section for more info.

    In order to integrate todocheck with your redmine server, you'll need to enable the server's rest API and, optionally, enable authentication - See Docs.

    YouTrack

    To integrate with a youtrack project, specify the origin of your project and the YOUTRACK issue tracker in your .todocheck.yaml configuration.
    You should also specify the apitoken as an auth type.

    For YouTrack InCloud:

    origin: youtrack-instance.myjetbrains.com
    issue_tracker: YOUTRACK
    auth:
      type: apitoken
    

    For YouTrack Standalone:

    origin: youtrack-instance.com
    issue_tracker: YOUTRACK
    auth:
      type: apitoken
    

    The first time you run the application, it will ask for your API Token.

    After you've specified it, it will store it in the auth tokens cache for subsequent executions. See the Authentication section for more info.

    Azure Boards

    To integrate with a public Azure Boards project, you should specify the origin of your project and 'AZURE' as an issue tracker in your .todocheck.yaml configuration.

    origin: https://dev.azure.com/your_user/your_public_project/
    issue_tracker: AZURE
    

    To integrate with a private Azure Boards project, you'll also need to specify the auth section with the apitoken type:

    origin: https://dev.azure.com/your_user/your_private_project/
    issue_tracker: AZURE
    auth:
      type: apitoken
    

    The first time you run the application, it will ask for your API Token.

    After you've specified it, it will store it in the auth tokens cache for subsequent executions. See the Authentication section for more info.

    Supported Programming Languages

    Currently, todocheck has parsers for three different types of comments:

    • Standard comments like // and /* */
    • Scripts using single-line comments #
    • Python with its # single-line and """ multi-line comments

    Based on this, here are the supported languages:

    Supported LanguagesDescription
    Bash/Zsh*.sh/*.bash/*.zsh extension. Supports # single-line comments
    C*.c extension. Supports single-line // comments and multi-line /* */ comments
    C++*.cpp extension. Supports single-line // comments and multi-line /* */ comments
    CSharp*.cs extension. Supports single-line // comments and multi-line /* */ comments
    Dart*.dart extension. Supports single-line // comments and multi-line /* */ comments
    Golang*.go extension. Supports single-line // comments and multi-line /* */ comments
    Groovy*.groovy, *.gvy, *.gy, *.gsh extensions. Supports single-line // comments and multi-line /* */ comments
    Java*.java extension. Supports single-line // comments and multi-line /* */ comments
    JavaScript/Typescript*.js/*.ts extension. Supports single-line // comments and multi-line /* */ comments
    Kotlin*.kt/*.kts/*.ktm extension. Supports single-line // comments and multi-line /* */ comments
    Nim*.{nim, nims, nimble} extension. Supports single-line # comments and multi-line #[ ]# comments
    PHP*.php extension. Supports single-line # and // comments and multi-line /* */ comments
    Python*.py extension. Supports single-line # comments and multi-line """ comments
    R*.R extension. Supports single-line // comments and multi-line /* */ comments
    Rust*.rs extension. Supports single-line // comments and multi-line /* */ comments
    Scala*.scala, *.sc extensions. Supports single-line // comments and multi-line /* */ comments
    Swift*.swift extension. Supports single-line // comments and multi-line /* */ comments
    Twig*.twig extension. Supports multi-line {# #} and HTML <!-- --> comments
    Vue*.vue extension. Supports single-line // comments, multi-line /* */ comments and multi-line <!-- --> HTML comments
    Yaml*.yaml, *.yml extension. Supports # single-line comments

    If you don't see your favorite language in this table, but it does use one of the supported comment formats, submit an issue here

    Ignored Files & Directories

    If you want certain project files not to be included for todocheck processing, you can specify that in an ignored section in the .todocheck.yaml configuration:

    origin: some.origin.com
    issue_tracker: JIRA
    ignored:
      - vendor-folder/
      - scripts/*.sh
    

    Ignored files/folders can be specified via standard pattern-matching. Hidden files (dotfiles, i.e. .git, .gitignore, etc) are ignored by default.

    Custom Todos

    By default, todocheck looks for todos in the format // TODO 231: ... Most projects stick to this format.

    However, if you have some special todo format, which is different from the default one, you can specify a list of custom todo formats in your .todocheck.yaml

    origin: some.origin.com
    issue_tracker: JIRA
    custom_todos:
      - "@fix"
      - ToDo
    

    Note that this list adds additional formats the tool should match, but doesn't substitute the default one - TODO.

    With the above configuration, todocheck will start matching todo comments in the following formats:

    // @fix 234: a leftover task...
    // ToDo 15: A funky-looking todo comment
    

    In addition to that, you can specify the match_case_insensitive flag to match TODOs in any casing:

    origin: some.origin.com
    issue_tracker: JIRA
    match_case_insensitive: true
    

    With this configuration, todocheck will match comments in similar formats:

    // TODO 15: some comment
    // ToDO 14: another comment
    // tOdO 13: yet another one
    

    Supported Output Formats

    Currently, todocheck supports two kinds of output - standard & json.

    The standard format is meant to be user-friendly & used in the normal day-to-day workflow.

    ERROR: Malformed todo
    tmp/main.groovy:2: // TODO: Invalid todo
            > TODO should match pattern - TODO {task_id}:
    
    ERROR: Malformed todo
    tmp/main.groovy:12: // TODO: Invalid todo
            > TODO should match pattern - TODO {task_id}:
    
    ERROR: Issue doesn't exist
    tmp/main.groovy:15: // TODO 3: A non-existent issue
    

    The json output is meant to be used for integrating todocheck in third-party systems, such as an IDE plugin.
    To use json output, use the --format json flag.

    [
       {
          "type":"Malformed todo",
          "filename":"tmp/main.groovy",
          "line":2,
          "message":"TODO should match pattern - TODO {task_id}:"
       },
       {
          "type":"Malformed todo",
          "filename":"tmp/main.groovy",
          "line":12,
          "message":"TODO should match pattern - TODO {task_id}:"
       },
       {
          "type":"Issue doesn't exist",
          "filename":"tmp/main.groovy",
          "line":15,
          "message":""
       }
    ]
    

    Authentication

    None

    For public repositories, todocheck requires no authentication as the issues in the issue tracker are publicly available. In this case, you need not specify any auth section in your configuration or explicitly set it as none:

    origin: github.com/user/repository
    issue_tracker: GITHUB
    auth: 
      type: none
    

    API Token/Offline Token

    For private repositories, todocheck requires an authentication token which the user specifies via a secure prompt.

    For github & gitlab, there is a personal access token one can get in his user settings & todocheck can use that to read your repository's issues. Github docs Gitlab docs

    To use this authentication type, configure the auth type as apitoken:

    origin: github.com/user/repository
    issue_tracker: GITHUB
    auth: 
      type: apitoken
    

    For Jira, you'll need to specify an offline token:

    origin: https://myjira.awesomeorg.com
    issue_tracker: JIRA
    auth:
      type: offline
      offline_url: https://myjira.awesomeorg.com/offline
    

    An offline token is one which your user can get by accessing a specific page, where your server generates an access token.

    Example offline token page: Offline token page example

    After you've received either an api token (github/gitlab) or an offline token, you can paste it in todocheck's secure prompt when asked.
    Example with github PAT prompt: todocheck Github PAT Prompt

    Afterwards, todocheck will not ask for your token again as it will store it in its tokens cache.

    Authentication Tokens Cache

    Whenever a user grants todocheck an auth token, the token will be stored in a file ~/.todocheck/authtokens.yaml.

    If that file doesn't already exist, it will be created with read/write permissions for current user only (permission 0700).

    This file stores a key-value mapping of project origin to auth token.
    Whenever todocheck runs, it first checks this file for an existing authentication token before contacting the issue tracker's server.

    If you want to specify a different tokens cache, you can set the tokens_cache section in your .todocheck.yaml configuration:

    # remainder omitted
    auth:
      # remainder omitted
      tokens_cache: path/to/tokens_cache
    

    Auth Token via Environment Variable

    If you need to pass an authentication token via an environment variable, use the TODOCHECK_AUTH_TOKEN environment variable.

    Example usage:

    TODOCHECK_AUTH_TOKEN=<secret-token> todocheck --basepath path/to/project
    

    This can be useful when you want to integrate todocheck in your CI pipeline.

    Configuration

    In your .todocheck.yaml configuration, you have the following configuration options:

    • origin - the origin of your remote repository/issue tracker (example: github.com/golang/go)
    • issue_tracker - the issue tracker type you're using. Possible options - GITHUB, GITLAB, JIRA
    • ignored - a list of directories/files todocheck should ignore. Supports pattern-macthing, e.g. *.sh.
    • custom_todos - a list of custom todos variables. TODO will always be added. (example: "@fix")
    • auth - the authentication configuration for your issue tracker. If not present, it defaults to auth type: none
      • type - the type of authentication. Possible options - none (default), offline, apitokenA
      • offline_url - the url for fetching offline tokens. Only used when type is offline
      • tokens_cache - the location of your auth tokens cache. Defaults to ~/.todocheck/authtokens.yaml

    In your tokens cache (default: ~/.todocheck/authtokens.yaml), authentication tokens are stored in the following format:

    tokens:
      github.com/user1/repo1: SECRET_TOKEN_1
      gitlab.com/user2/repo2: SECRET_TOKEN_2
      https://jira.awesomeorg.com/offline: SECRET_TOKEN_3
    

    If you'd like to explicitly specify an access token in this file, feel free to do so. This will let the user not have to manually input the token on the first todocheck execution.

    This can be used e.g. in a CI environment, in an initial laptop setup script, etc.
    Alternatively, use an Auth Token via Environment Variable

    Contributing

    If you want to report an issue, make improvement suggestions or open a pull request, refer to the Contributing guide

    Special thanks to all the project's contributors!