【问题标题】:How to disable a linting rule inline in flutter如何在颤动中内联禁用 linting 规则
【发布时间】:2019-10-16 07:51:27
【问题描述】:

有没有办法在颤动中禁用一条线的 linting 规则?

我有一个特定的用例,我想禁用两行的 linting。 我已经写了很多业务逻辑,所以我无法更改代码。

abstract class ReviewName {
  static final NEW = 'NEW';
  static final OLD = 'OLD';
}

上面的代码会有 linting 错误:Name non-constant identifiers using lowerCamelCase.dart(non_constant_identifier_names)

有什么方法可以避免仅针对两行的 lint 错误?

【问题讨论】:

    标签: flutter dart inline lint disable


    【解决方案1】:

    一般答案

    要忽略单个,您可以在该行上方添加注释:

    // ignore: non_constant_identifier_names
    final NEW = 'NEW';
    

    要忽略整个文件,您可以在文件顶部添加注释:

    // ignore_for_file: non_constant_identifier_names
    

    要忽略整个项目,您可以在 analysis_options.yaml 文件中set the rule to false

    include: package:lints/recommended.yaml
    
    linter:
      rules:
        non_constant_identifier_names: false
    

    另见

    【讨论】:

      【解决方案2】:

      使用// ignore: 语法,例如:

      abstract class ReviewName {
        // ignore: non_constant_identifier_names
        static final NEW = 'NEW';
      
        // ignore: non_constant_identifier_names
        static final OLD = 'OLD';
      }
      

      规则名称列表为here

      【讨论】:

      • 我在这里找到了文档:dart.dev/guides/language/…
      • 我希望有更全球化的东西。我喜欢snake_case,但飞镖社区不同意。
      • OP 只需要两行。全局方式是更改analysis.yaml。在可能的情况下,尽量尊重代码可读性的社区约定。
      • 任何方式只需为整个班级添加一个//ignore?如果我有 50 个静态字符串,我不想添加额外的 50 cmets。
      猜你喜欢
      • 1970-01-01
      • 2015-11-26
      • 2019-05-22
      • 2019-10-22
      • 2018-09-05
      • 2020-06-07
      • 1970-01-01
      • 2013-06-02
      • 2020-10-17
      相关资源
      最近更新 更多