如何忽略整个项目的used_local_variable警告?

iDe*_*ode 2 dart flutter

我有一些变量没有在项目中的任何地方使用/引用,因此我收到警告unused_local_variable

目前我正在使用

// ignore_for_file: unused_local_variable
Run Code Online (Sandbox Code Playgroud)

忽略该文件的那些警告,但我有很多文件,我不想在每个文件中都写相同的内容。那么,如何才能抑制整个项目的这个警告呢?

将其添加到analysis_options.yaml文件中不起作用:

linter:
  rules:
     unused_local_variable: false
Run Code Online (Sandbox Code Playgroud)

jam*_*lin 5

unused_local_variables不是 lint 规则( https://dart.dev/tools/linter-ruleshttps://github.com/dart-lang/linter/blob/main/example/all.yaml中未列出) ,因此禁用它linter: rules:不会有任何效果。

unused_local_variables相反是一个分析器代码。根据https://dart.dev/guides/language/analysis-options#ignoring-rules,您可以编辑analysis_options.yaml文件并添加:

analyzer:
  errors:
    unused_local_variable: ignore
Run Code Online (Sandbox Code Playgroud)

也就是说,实际上您应该删除未使用的局部变量。