Sdk: Dart analyser on cli doesn't use analysis_options.yaml excludes files

Created on 3 Jan 2019  路  5Comments  路  Source: dart-lang/sdk

I have the following analysis_options.yaml:

include: package:flutter/analysis_options_user.yaml

analyzer:
  exclude:
    - 'bin/**'
    - 'lib/l10n/messages/**'
    - 'lib/**/*.*.dart'
    - 'ios/**'
    - 'android/**'
  errors:
    no_duplicate_case_values: error
    avoid_relative_lib_imports: error
    always_put_required_named_parameters_first: error
    always_declare_return_types: error
    invariant_booleans: error
    prefer_single_quotes: error
    avoid_init_to_null: error
    mixin_inherits_from_not_object: ignore

linter:
  rules:
    - always_declare_return_types
    - always_put_control_body_on_new_line
    - always_put_required_named_parameters_first
    - always_require_non_null_named_parameters
    - annotate_overrides
    - avoid_annotating_with_dynamic
    - avoid_as
    - avoid_bool_literals_in_conditional_expressions
    - avoid_catches_without_on_clauses
    - avoid_catching_errors
    - avoid_classes_with_only_static_members
    - avoid_double_and_int_checks
    - avoid_empty_else
    - avoid_field_initializers_in_const_classes
    - avoid_function_literals_in_foreach_calls
    - avoid_init_to_null
    - avoid_js_rounded_ints
    - avoid_null_checks_in_equality_operators
    - avoid_relative_lib_imports
    - avoid_return_types_on_setters
    - avoid_returning_null
    - avoid_returning_this
    - avoid_setters_without_getters
    - avoid_single_cascade_in_expression_statements
    - avoid_slow_async_io
    - avoid_types_as_parameter_names
    - avoid_types_on_closure_parameters
    - avoid_unused_constructor_parameters
    - camel_case_types
    - cancel_subscriptions
    - cascade_invocations
    - close_sinks
    - constant_identifier_names
    - control_flow_in_finally
    - directives_ordering
    - empty_catches
    - empty_constructor_bodies
    - empty_statements
    - hash_and_equals
    - implementation_imports
    - invariant_booleans
    - iterable_contains_unrelated_type
    - join_return_with_assignment
    - library_names
    - library_prefixes
    - list_remove_unrelated_type
    - literal_only_boolean_expressions
    - no_adjacent_strings_in_list
    - no_duplicate_case_values
    - non_constant_identifier_names
    - omit_local_variable_types
    - one_member_abstracts
    - only_throw_errors
    - overridden_fields
    - package_names
    - package_prefixed_library_names
    - parameter_assignments
    - prefer_adjacent_string_concatenation
    - prefer_asserts_in_initializer_lists
    - prefer_bool_in_asserts
    - prefer_collection_literals
    - prefer_conditional_assignment
    - prefer_const_declarations
    - prefer_constructors_over_static_methods
    - prefer_contains
    - prefer_equal_for_default_values
    - prefer_final_fields
    - prefer_final_locals
    - prefer_foreach
    - prefer_function_declarations_over_variables
    - prefer_generic_function_type_aliases
    - prefer_initializing_formals
    - prefer_interpolation_to_compose_strings
    - prefer_iterable_whereType
    - prefer_single_quotes
    - prefer_typing_uninitialized_variables
    - recursive_getters
    - slash_for_doc_comments
    - super_goes_last
    - test_types_in_equals
    - throw_in_finally
    - type_init_formals
    - unawaited_futures
    - unnecessary_brace_in_string_interps
    - unnecessary_getters_setters
    - unnecessary_lambdas
    - unnecessary_null_aware_assignments
    - unnecessary_new
    - unnecessary_null_in_if_null_operators
    - unnecessary_overrides
    - unnecessary_parenthesis
    - unnecessary_statements
    - unnecessary_this
    - unrelated_type_equality_checks
    - use_rethrow_when_possible
    - use_setters_to_change_properties
    - use_string_buffers
    - use_to_and_as_if_applicable
    - valid_regexps
    - void_checks

Everything is good on AS or IntelliJ (except when the file is open like already reported in https://github.com/dart-lang/sdk/issues/35475) but once I do it manually as command line:

dartanalyzer lib
or
dartanalyzer --options analysis_options.yaml lib

And both give me 1109 errors as it take into account my excludes files.
It's anoying as I can't use any CI except by removing my rules...

Env: Dart VM version: 2.1.0-dev.9.4.flutter-f9ebf21297 (Thu Nov 8 23:00:07 2018 +0100) on "macos_x64"

P2 area-analyzer type-bug

All 5 comments

I can confirm exactly this behavior. You have a lot of errors in the exluded files. After doing this: https://github.com/dart-lang/sdk/issues/33193#issuecomment-391030810 . Everything seems to work unless you open this file again in VS Code. Then you have do this: https://github.com/dart-lang/sdk/issues/33193#issuecomment-391030810 again.

Also I can confirm, that by calling analyzer by command line like this:

dartanalyzer lib
everything works as expected.

You don't have to open a file - it's enough to just call a method/class defined in the file to trigger analysis. It's especially annoying when dealing with generated JSON or Protocol Buffers. If a generated file relies on another generated file (e.g. classes and enums in protobuf), you have to explicitly open both files to get rid of errors (e.g. in the one that references enums).

Same issue here :

# analysis_options.yaml
analyzer:
  exclude:
    - lib/**.g.dart
    - lib/src/version.dart

No error reported by the analysis server (i.e. via an editor like VSCode or WebStorm). But if I run dartanalyzer from the command line:

$ dartanalyzer --options=analysis_options.yaml bin lib test

... some errors are reported on the excluded files (even after deleting the .dartServer cache folder):

Analyzing bin, lib, test...
  lint - Avoid using `as`. - lib\src\cli.g.dart:10:28 - avoid_as
  lint - Avoid using `as`. - lib\src\cli.g.dart:11:30 - avoid_as
  lint - Avoid using `as`. - lib\src\cli.g.dart:13:34 - avoid_as
  lint - Avoid using `as`. - lib\src\cli.g.dart:14:36 - avoid_as
  lint - Document all public members. - lib\src\cli.g.dart:34:9 - public_member_api_docs
5 lints found.

Dart VM version: 2.8.1 (stable) (Thu Apr 30 09:25:21 2020 +0200) on "windows_x64"

Thanks for reporting this issue! This was previously reported at https://github.com/dart-lang/sdk/issues/25551; please follow along there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bergwerf picture bergwerf  路  3Comments

DartBot picture DartBot  路  3Comments

brooth picture brooth  路  3Comments

DartBot picture DartBot  路  3Comments

DartBot picture DartBot  路  3Comments