【问题标题】:Configure Sorbet to treat all files without comment as if they had a typed: ignore comment配置 Sorbet 以将所有没有注释的文件视为输入:忽略注释
【发布时间】:2020-05-29 23:59:14
【问题描述】:

我的问题与1 有关,但我可以将类型 cmets 添加到具有类型注释的文件中。我们只是不想在数百个文件上自动生成 cmets,尽管这些文件中没有发生任何其他事情。有没有办法让 Sorbet 像这样工作?

【问题讨论】:

    标签: ruby sorbet


    【解决方案1】:

    使用以下 Sorbet 标志可能会大有帮助:

    $ srb tc --help
    Typechecker for Ruby
    Usage:
      sorbet [OPTION...] <path 1> <path 2> ...
    ...
          --ignore string           Ignores input files that contain the given
                                    string in their paths (relative to the input
                                    path passed to Sorbet). Strings beginning with /
                                    match against the prefix of these relative
                                    paths; others are substring matchs. Matches must
                                    be against whole folder and file names, so
                                    `foo` matches `/foo/bar.rb` and `/bar/foo/baz.rb`
                                    but not `/foo.rb` or `/foo2/bar.rb`.
    ...
          --typed-override filepath.yaml
                                    Yaml config that overrides strictness levels
                                    on files (default: "")
    ...
    

    如果您要忽略的所有文件都在一个文件夹中,或者可以通过某些路径匹配进行匹配,那么您的 sorbet/config 文件中的几行 --ignore 应该可以满足您的需求。

    否则,您可以使用 YAML 文件中的类型化覆盖来使 Sorbet 将您想要的文件解释为 typed: ignore。同样,您应该能够将此标志添加到您的 sorbet/config 文件中。

    【讨论】:

      【解决方案2】:

      According to the documentation:

      # typed: false 是没有标记的文件的默认

      所以你想要的行为应该已经到位了。

      【讨论】:

      • 感谢您的回答。不幸的是,我在标题中有一个类型,实际上应该是typed: ignore 而不是typed: false。我知道问题中的描述不足以单独澄清这一点。我已经相应地更新了问题的标题。
      • 根据您的描述,typed: false 作为 no-sigil-files 的默认值应该是合理的。 Sorbet 不会接触这些文件,只会检查缺少常量或拼写错误等内容。 typed: ignore 是非常严格的,很可能是您只想在极少数情况下使用的东西,您想从冰糕中隐藏一些代码。团队甚至建议不要忽略文件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      相关资源
      最近更新 更多