dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.2k stars 1.57k forks source link

Analyzer: unable to analyze only the file specified #35284

Closed lo-tp closed 1 year ago

lo-tp commented 5 years ago

When using the analyzer, we will always receive warnings caused by files imported by the package statement.
An option enabling us to avoid these imported warnings is necessary.

zoechi commented 5 years ago

Can you please post example code that causes the warning and the exact warning text?

You can disable warnings using https://www.dartlang.org/guides/language/analysis-options

or

// ignore: error_or_warning_or_linter_rule_name
// ignore_for_file: error_or_warning_or_linter_rule_name
lo-tp commented 5 years ago
import 'package:flutter/material.dart';

import 'package:rxdart/rxdart.dart';

import 'package:r2r/blocs/provider.dart';
import 'package:r2r/blocs/global.dart';
import 'package:r2r/i18n/index.dart';

import 'package:r2r/pages/query/search.dart';
import 'package:r2r/pages/learn.dart';

import 'package:r2r/widgets/loadingWrapper.dart';

class NavigationDrawer extends StatelessWidget {
  var onTap;
  final String currentName;
  NavigationDrawer({@required this.currentName, this.onTap});

  BehaviorSubject<bool> _loadingController =
      BehaviorSubject<bool>(seedValue: false);

  onTapHandlerMaker({@required routeName, @required context}) => () {
        if (onTap != null) {
          onTap(routeName);
        } else {
          Navigator.pushNamed(context, routeName);
        }
      };

  @override
  Widget build(BuildContext context) {
    return LoadingWrapper(
        stream: _loadingController.stream,
        child: Drawer(
            child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text(R2RLocalizations.of(context).drawerTitle),
              decoration: BoxDecoration(color: Theme.of(context).primaryColor),
            ),
            ListTile(
              title: Text(R2RLocalizations.of(context).drawerSearch),
              enabled: currentName != Search.routeName,
              onTap: onTapHandlerMaker(
                  routeName: Search.routeName, context: context),
            ),
            ExpansionTile(
                initiallyExpanded: true,
                title: Text(R2RLocalizations.of(context).drawerStudy),
                children: <Widget>[
                  ListTile(
                      enabled: currentName != LearnPage.reviewRouteName,
                      title: Text(R2RLocalizations.of(context).drawerReview),
                      onTap: onTapHandlerMaker(
                          routeName: LearnPage.reviewRouteName,
                          context: context)),
                  ListTile(
                    enabled: currentName != LearnPage.normalRouteName,
                    onTap: onTapHandlerMaker(
                        routeName: LearnPage.normalRouteName, context: context),
                    title: Text(R2RLocalizations.of(context).drawerNormal),
                  ),
                ]),
          ],
        )));
  }
}

And the output is like this:

  0 INFO|LINT|close_sinks|src/lib/widgets/navigationDrawer.dart|19|25|66|Close instances of `dart.core.Sink`.
  1 INFO|HINT|UNUSED_IMPORT|src/lib/widgets/navigationDrawer.dart|6|8|31|Unused import: 'package:r2r/blocs/global.dart'.
  2 INFO|HINT|MUST_BE_IMMUTABLE|src/lib/widgets/navigationDrawer.dart|14|7|16|This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final).
  3 INFO|HINT|UNUSED_IMPORT|src/lib/widgets/navigationDrawer.dart|5|8|33|Unused import: 'package:r2r/blocs/provider.dart'.
  4 INFO|HINT|UNUSED_IMPORT|src/lib/i18n/index.dart|4|8|58|Unused import: 'package:flutter_localizations/flutter_localizations.dart'.
  5 INFO|HINT|UNUSED_IMPORT|src/lib/blocs/query.dart|7|8|39|Unused import: 'package:r2r/services/mdict/mdict.dart'.
  6 INFO|LINT|avoid_init_to_null|src/lib/blocs/query.dart|11|7|14|Don't explicitly initialize variables to null.
  7 INFO|LINT|non_constant_identifier_names|src/lib/blocs/query.dart|30|39|17|Name non-constant identifiers using lowerCamelCase.
  8 INFO|LINT|non_constant_identifier_names|src/lib/blocs/query.dart|23|27|15|Name non-constant identifiers using lowerCamelCase.
  9 INFO|LINT|await_only_futures|src/lib/services/mdict/mdict.dart|132|5|5|Await only futures.
 10 INFO|LINT|avoid_init_to_null|src/lib/services/mdict/mdict.dart|81|9|10|Don't explicitly initialize variables to null.
 11 INFO|HINT|UNUSED_ELEMENT|src/lib/services/mdict/mdict.dart|108|7|5|The class '_Dict' isn't used.
 12 INFO|HINT|UNUSED_IMPORT|src/lib/services/mdict/mdict.dart|5|8|12|Unused import: './lib.dart'.
 13 INFO|HINT|UNUSED_LOCAL_VARIABLE|src/lib/services/mdict/mdict.dart|121|11|8|The value of the local variable 'keyIndex' isn't used.
 14 INFO|LINT|unnecessary_brace_in_string_interps|src/lib/services/mdict/mdict.dart|91|40|7|Avoid using braces in interpolation when not needed.
 15 INFO|LINT|await_only_futures|src/lib/services/mdict/mdict.dart|27|11|5|Await only futures.
 16 INFO|LINT|unnecessary_brace_in_string_interps|src/lib/services/mdict/mdict.dart|127|14|7|Avoid using braces in interpolation when not needed.
 17 INFO|LINT|unnecessary_brace_in_string_interps|src/lib/services/mdict/mdict.dart|125|14|7|Avoid using braces in interpolation when not needed.
 18 INFO|HINT|UNUSED_IMPORT|src/lib/services/mdict/parser.dart|2|8|14|Unused import: 'dart:convert'.
 19 INFO|HINT|UNUSED_LOCAL_VARIABLE|src/lib/services/mdict/parser.dart|237|9|5|The value of the local variable 'index' isn't used.
 20 INFO|HINT|UNUSED_IMPORT|src/lib/services/mdict/parser.dart|9|8|33|Unused import: 'package:flutter/foundation.dart'.
 21 INFO|HINT|MISSING_RETURN|src/lib/services/mdict/lib.dart|92|1|9|This function has a return type of 'List<int>', but doesn't end with a return statement.
 22 INFO|HINT|UNUSED_IMPORT|src/lib/services/mdict/lib.dart|4|8|12|Unused import: 'dart:async'.
 23 INFO|HINT|MISSING_RETURN|src/lib/services/mdict/lib.dart|68|3|6|This function has a return type of 'String', but doesn't end with a return statement.
 24 INFO|HINT|UNUSED_IMPORT|src/lib/services/mdict/lib.dart|8|8|33|Unused import: 'package:flutter/foundation.dart'.
 25 INFO|HINT|UNUSED_LOCAL_VARIABLE|src/lib/services/mdict/lib.dart|103|17|7|The value of the local variable 'decoder' isn't used.
 26 INFO|LINT|await_only_futures|src/lib/services/mdict/mdictWithCache.dart|155|5|5|Await only futures.
 27 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|21|14|23|Name non-constant identifiers using lowerCamelCase.
 28 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|20|14|20|Name non-constant identifiers using lowerCamelCase.
 29 INFO|LINT|await_only_futures|src/lib/services/mdict/mdictWithCache.dart|132|9|5|Await only futures.
 30 INFO|LINT|await_only_futures|src/lib/services/mdict/mdictWithCache.dart|151|5|5|Await only futures.
 31 INFO|LINT|await_only_futures|src/lib/services/mdict/mdictWithCache.dart|137|9|5|Await only futures.
 32 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|23|14|26|Name non-constant identifiers using lowerCamelCase.
 33 INFO|LINT|await_only_futures|src/lib/services/mdict/mdictWithCache.dart|52|5|5|Await only futures.
 34 INFO|LINT|unnecessary_brace_in_string_interps|src/lib/services/mdict/mdictWithCache.dart|121|14|7|Avoid using braces in interpolation when not needed.
 35 INFO|LINT|unnecessary_brace_in_string_interps|src/lib/services/mdict/mdictWithCache.dart|123|14|7|Avoid using braces in interpolation when not needed.
 36 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|19|14|22|Name non-constant identifiers using lowerCamelCase.
 37 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|22|14|24|Name non-constant identifiers using lowerCamelCase.
 38 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|18|14|20|Name non-constant identifiers using lowerCamelCase.
 39 INFO|HINT|UNUSED_LOCAL_VARIABLE|src/lib/services/mdict/mdictWithCache.dart|117|11|8|The value of the local variable 'keyIndex' isn't used.
 40 INFO|LINT|non_constant_identifier_names|src/lib/services/mdict/mdictWithCache.dart|24|14|14|Name non-constant identifiers using lowerCamelCase.
 41 INFO|LINT|await_only_futures|src/lib/services/mdict/mdictWithCache.dart|68|5|5|Await only futures.
 42 INFO|HINT|UNUSED_IMPORT|src/lib/services/mdict/query.dart|1|8|12|Unused import: 'dart:async'.
 43 INFO|LINT|non_constant_identifier_names|src/lib/blocs/study.dart|27|33|21|Name non-constant identifiers using lowerCamelCase.
 44 INFO|HINT|UNUSED_IMPORT|src/lib/services/record.dart|1|8|9|Unused import: 'dart:io'.
 45 INFO|HINT|MUST_BE_IMMUTABLE|src/lib/pages/query/result.dart|16|7|15|This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final).
 46 ERROR|COMPILE_TIME_ERROR|INCONSISTENT_CASE_EXPRESSION_TYPES|src/lib/pages/query/result.dart|95|18|4|Case expressions must have the same types, 'null' isn't a 'AsyncStatus'.
 47 INFO|HINT|MISSING_RETURN|src/lib/pages/query/result.dart|21|3|12|This function has a return type of '() ? void', but doesn't end with a return statement.
 48 INFO|HINT|MUST_BE_IMMUTABLE|src/lib/widgets/btnScaffold.dart|3|7|17|This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final).
 49 INFO|HINT|MUST_BE_IMMUTABLE|src/lib/widgets/bottomAppBar.dart|3|7|18|This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final).
 50 INFO|HINT|UNUSED_IMPORT|src/lib/pages/learn.dart|13|8|29|Unused import: 'package:r2r/utils/enum.dart'.
 51 ERROR|COMPILE_TIME_ERROR|IMPLICIT_THIS_REFERENCE_IN_INITIALIZER|src/lib/pages/learn.dart|19|39|3|Only static members can be accessed in initializers.
 52 INFO|HINT|UNUSED_IMPORT|src/lib/pages/learn.dart|3|8|28|Unused import: 'package:rxdart/rxdart.dart'.

Most of the output is relevant and can by fixed by modifying the corresponding source file while some lines makes little sense since it is not cause by the source file directly.

Take line 36 to 38 as an example, these lines has nothing to do with the target source file as they are caused by another file

srawlins commented 1 year ago

Closing as stale. Please comment if you encounter this on a recent version of Dart.