【问题标题】:jquery.d.ts compilation failed: TsLint: exceeds maximum line lengthjquery.d.ts 编译失败:TsLint:超过最大行长
【发布时间】:2014-03-19 02:04:10
【问题描述】:

我正在使用带有 0.95 版 TypeScript 的 VS 2013,但 linter 未能通过 TS 编译并出现错误:

TsLint:已检查 app.ts。 TsLint:jquery.d.ts 编译失败: TsLint:超过最大行长 140

jquery.d.ts 文件确实有超过 140 行的长度,但我找不到 tslint 配置文件来编辑 max-line-length 值。

我使用的是 WebEssentials 2013,我没有将 tslint 作为包(NPM 或 Nuget)的一部分安装。

谁能指出我正确的方向?我认为现在在 VS 之外设置编译/linting 可能更容易..

谢谢。

【问题讨论】:

    标签: visual-studio-2013 typescript web-essentials


    【解决方案1】:

    您可以修改 tslint 配置文件来更改最大行长度阈值。它使用分层配置系统,因此您可以根据创建/修改 tslint.conf 文件的位置确定更改范围。

    默认情况下,配置从 tslint.json 加载,如果它存在于 当前路径或用户的主目录,按此顺序。 (source...)

    在我的 Windows 计算机上,全局配置文件位于C:\Users\My.Username,此处的更改将应用​​于所有项目。在 Visual Studio 的根目录中创建或修改文件意味着配置设置将仅适用于该项目并将覆盖全局配置文件。

    您需要为最大行长修改的特定配置选项称为max-line-length,如下所示:

    "max-line-length": [true, 140]
    

    更改140 值以扩展允许的行长度或将true 更改为false 以禁用最大行长度规则。


    或者,您可以执行史蒂夫在另一个答案中建议的操作,但您不需要完全禁用 tslint,因为您可以禁用特定规则。其语法是:

    /*tslint:disable:rule1 rule2 rule3*/
    

    所以你会使用:

    /*tslint:disable:max-line-length*/
    

    禁用该文件的最大行长规则。

    tslint website 上全面解释了所有配置选项和特定于规则的禁用。

    【讨论】:

      【解决方案2】:

      我相信max-line-length 警告是针对单行的长度,而不是针对文件中的行数。

      您可以将长行拆分以使其更小,或者直接忽略不是“您的代码”的文件。

      /* tslint:disable */
      // the jquery type definition
      /* tslint:enable */
      

      或设置您自己的配置:

      -c, --config:
          The location of the configuration file that tslint will use to
          determine which rules are activated and what options to provide
          to the rules. If no option is specified, the config file named
          tslint.json is used, so long as it exists in the path.
          The format of the file is { rules: { /* rules list */ } },
          where /* rules list */ is a key: value comma-seperated list of
          rulename: rule-options pairs. Rule-options can be either a
          boolean true/false value denoting whether the rule is used or not,
          or a list [boolean, ...] where the boolean provides the same role
          as in the non-list case, and the rest of the list are options passed
          to the rule that will determine what it checks for (such as number
          of characters for the max-line-length rule, or what functions to ban
          for the ban rule).
      

      来自https://www.npmjs.org/package/tslint

      【讨论】:

      • 对不起,史蒂夫,你误解了我的问题。 1)我知道它是线长(“线的长度超过 140” - 从上面)。 2) 我没有更改 jquery.d.ts 文件,因为它是创建并存储在 DefinitiveTyped 存储库 ([link]github.com/borisyankov/DefinitelyTyped) 上的第 3 方标准。 3) 它在 Visual Studio 2013 中并且没有 --config 开关。
      • 嗨,史蒂夫,我想我会尝试在 Github 上编辑该文件并开始拉取请求,但没有 TS 理解来重构几个接口定义。我优先考虑不必更改默认值(因为,为什么)和开箱即用的 W.E. 2013 年整合。
      • 如果 TSLint 获得关注,也许项目会愿意默认将忽略规则添加到 .d.ts 文件中。您希望 TSLint 检查您的代码而不是外部代码和定义,对吗?
      • 这是一个公平的观点。但是,如果根本没有必要检查它们,那么 TSLint 应该完全忽略它们。我的猜测是,您会知道定义文件正在完成它们的工作(在 VS 中提供智能感知等),但不会以每次构建时在所有外部资源上运行 linter 为代价。我现在将使用排除注释绕过它:/* tslint:disable:max-line-length */。您能否更新您的答案以包含它(作为以 VS 为中心的解决方案),我会给您点头?谢谢。
      猜你喜欢
      • 2017-07-30
      • 2017-04-23
      • 2018-07-24
      • 2018-07-01
      • 2019-10-10
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多