【问题标题】:How to fix a specific lint warning for the entire project?如何修复整个项目的特定 lint 警告?
【发布时间】:2022-01-02 14:27:29
【问题描述】:

我的项目的不同文件中有许多 lint 警告,例如:

Prefer const with constant constructors.
Use key in widget constructors.
...
Unnecessary string interpolation. 

有没有办法只修复特定的警告,比如

dart fix prefer_const_constructors 

PS:我不想修复所有警告,因为我可以运行dart fix --apply

【问题讨论】:

    标签: flutter android-studio dart


    【解决方案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
    

    更多信息请参考这里

    【讨论】:

    • 谢谢,但这不是问题所在。我不想suppress the warning
    • 根据official documentation,他们没有提到使用一个代码行修复特定选择的 lint 警告的方法。
    • 是的,我知道这就是我问这个问题的原因,如果有任何方法解决方法可以做到这一点。
    猜你喜欢
    • 2019-02-08
    • 2020-10-29
    • 2016-07-07
    • 2020-07-14
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多