Suppress hint about use of protected member

北城以北 提交于 2019-11-28 04:28:34

问题


The meta package provides a @protected annotation (besides others) to get analyzer hints or warnings about the use of protected members outside of direct subclasses.

INFO: The member 'selectedChildrenChanged' can only be used within instance members of subclasses of 'MenuItem' ([bwu_ng_quick_nav] test/menu_item_test.dart:108)

I'm not interested in these hints in my unit tests.

How can I suppress such hints?


回答1:


The suppression code for the @protected hint is INVALID_USE_OF_PROTECTED_MEMBER. Add a suppression comment like:

  // ignore: INVALID_USE_OF_PROTECTED_MEMBER
  app.quickNav.keyDownHandler(ctrlKeyDown);

or

   // ignore_for_file: INVALID_USE_OF_PROTECTED_MEMBER

The codes for other hints can be found in

  • https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/error/codes.dart
  • https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/dart/error/hint_codes.dart
  • https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/dart/error/lint_codes.dart
  • https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/dart/error/todo_codes.dart

This works with Dart VM version: 1.16.0-edge. I don't know with what version this was released.

Hopefully these IDs will be part of the warnings soon to not have to look them up.



来源:https://stackoverflow.com/questions/35969619/suppress-hint-about-use-of-protected-member

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!