2

I have been looking off and on for a few days now and I'm trying to customize the rules for linting my flutter project. I'd like to turn off the obvious warnings like unused local variables. Yet when I enter it into the rules section it doesn't work amongst other rules. Yet some do work.

I'm also confused as to the formatting. I see some answers on the internet that use a hyphen then the rule where others are stating the rule with a colon and a true or false. I tried the hyphen and I get a block mapping type of error thrown at me.

Here is my file right now...

include: package:flutter_lints/flutter.yaml
# include: package:lint/analysis_options.yaml

linter:
  rules:
    always_declare_return_types: false
    use_key_in_widget_constructors: false
    unused_element: false
    unused_local_variable: true
    unused_import: false
    avoid_print: false
    prefer_const_constructors: false
    require_trailing_commas: true
    always_use_package_imports: false

The trailing commas one worked but the more annoying and obvious warnings I cant seem to suppress.

Can someone please clarify the structure and maybe why the some rules are working and some arent?

If I do the quick fixes inside the files to ignore them it works but I want them project wide.

EDIT well the unused_local_variable is the warning that started me on this quest for information and understanding of how the analysis_options file works.

Unused_local_variables

Technorocker
  • 103
  • 14
  • 1
    https://dart.dev/guides/language/analysis-options#the-analysis-options-file documents the file and the format. The linter rules can be either a YAML list or a map of lint names to boolean values, but not both. I don't see anything obviously wrong with what you have. Could you be more specific about which lints aren't being disabled properly, perhaps with code examples that trigger them? – jamesdlin Jan 05 '22 at 12:10
  • I have edited my question. but thank you for the insight on the "either or" for the rule structure. I hover over the warning message and wait for the lint rule to pop up and than use that rule name in the analysis file. Most of them have been working but there are a few that I enter into the rules list and they dont seem to make a difference whether true or false. – Technorocker Jan 05 '22 at 13:23
  • Your screenshot shows you triggering the `unused_local_variable` lint, but the `analysis_options.yaml` file you posted enables that lint with `unused_local_variable: true`. – jamesdlin Jan 05 '22 at 20:26
  • My apologies and sorry for late reply, That was just a screenshot at the time. I was trying and testing if changing the bool was working or not. I did try and had it set to false. I just decided to use the ignore suggestion in each file and not waste anymore time on trying to figure it out. – Technorocker Jan 23 '22 at 16:38

0 Answers0