dart-lang / site-www

Source for Dart website
https://dart.dev
Other
969 stars 700 forks source link

Display linter rules with required boolean parameter #6100

Open egarson opened 1 month ago

egarson commented 1 month ago

Page URL

https://dart.dev/tools/linter-rules/avoid_classes_with_only_static_members.html

Page source

https://github.com/dart-lang/site-www/tree/main/src/content/tools/linter-rules/individual-rules.md

Describe the problem

I propose that the documentation for all linter rule "Usage" sections is misleading, because the rule is not activated without the boolean value following the key entry.

For example, here is the "Usage" section at the bottom of the avoid_classes_with_only_static_members rule:

    To enable the avoid_classes_with_only_static_members rule, add avoid_classes_with_only_static_members under linter > rules in your [analysis_options.yaml](https://dart.dev/tools/analysis) file:

        linter:
          rules:
            - avoid_classes_with_only_static_members

The problem is that without explicitly adding true to the end of the key, i.e. avoid_classes_with_only_static_members: true, the rule is not activated. Put another way, it is reasonable to assume that merely listing the value in the analysis_options.yaml file would be sufficient to activate it (as I mistakenly presumed).

Expected fix

I propose merely adding true to the end of every listed key_value. This would also imply that false is equally viable. Note that I would be happy to perform this rote task, presuming this change is deemed worthwhile.

Additional context

No response

I would like to fix this problem.

raul-sauco commented 1 month ago

I have seen the same issue in the individual linter rule pages, such as:

https://dart.dev/tools/linter-rules/prefer_relative_imports#details

The example there is:

 linter:
   rules:
     - prefer_relative_imports

However, in the current Dart SDK version I am using:

Dart SDK version: 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "macos_arm64"

This syntax no longer appears to work correctly, as it doesn't trigger lint errors for package imports. Updating the rule syntax to:

 linter:
   rules:
     - prefer_relative_imports: true

seems to resolve the issue. I think that earlier versions of the analyzer may have implicitly interpreted the first format correctly. However, it seems that newer versions of the Dart analyzer now require the boolean attribute to be explicit.