dart-lang / pana

Package ANAlysis for Dart
https://pub.dev/packages/pana
BSD 3-Clause "New" or "Revised" License
207 stars 44 forks source link

dart analyze fails with "Output exceeded n bytes" #1205

Closed swift-kim closed 1 year ago

swift-kim commented 1 year ago

https://pub.dev/packages/tizen_interop/score

I'm a maintainer of the above package but I can't understand why the static analysis always fails with "Running dart analyze produced too large output".

The issue can be reproduced locally with pana.

$ cd tizen_interop
$ git clean -xdf
$ ~/.pub-cache/bin/pana --no-warning
INFO       Running `/home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics --version`...
INFO       Running `flutter --suppress-analytics --no-version-check --version --machine`...
INFO       Running `git rev-parse --show-toplevel`...
INFO       Running `/home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics pub get --no-example`...
INFO       Running `/home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics pub outdated --json --up-to-date --no-dev-dependencies --no-dependency-overrides`...
INFO       Analyzing package...
INFO       Running `/home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics analyze --format machine lib`...
SEVERE     Killing `/home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics analyze --format machine lib` Output exceeded 10485760 bytes.
INFO       killed `/home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics analyze --format machine lib` - true
INFO       Running `git init`...
...

But the error is not reproduced when I run dart analyze directly with the exact same command used by pana.

$ /home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --no-analytics analyze --format machine lib
### No issues! ###

My Dart SDK version:

$ /home/swift/Git/flutter-tizen/flutter/bin/cache/dart-sdk/bin/dart --version
Dart SDK version: 2.19.1 (stable) (Tue Jan 31 12:25:35 2023 +0000) on "linux_x64"

The package (tizen_interop) is obviously large in code size (about 1M lines) but this fact doesn't explain why pana fails. What would be the real cause of the issue and how should I deal with it?

sigurdm commented 1 year ago

The documentation logs can be seen here: https://pub.dev/documentation/tizen_interop/latest/log.txt

sigurdm commented 1 year ago

The documentation logs can be seen here: https://pub.dev/documentation/tizen_interop/latest/log.txt

Sorry, that was a red herring.

I ran a manual pana run, without the limit on output size, and here is the relevant section:

## ✗ Pass static analysis (20 / 30)
### [~] 20/30 points: code has no errors, warnings, lints, or formatting issues

Found 88745 issues. Showing the first 2:

<details>
<summary>
INFO: The variable name 'get_last_result' isn't a lowerCamelCase identifier.
</summary>

`lib/src/bindings/4.0/generated_bindings.dart:32:7`

╷ 32 │ int get_last_result() { │ ^^^^^^^^^^^^^^^ ╵


To reproduce make sure you are using the [lints_core](https://pub.dev/packages/lints) and run `dart analyze lib/src/bindings/4.0/generated_bindings.dart`
</details>
<details>
<summary>
INFO: The variable name '_get_last_resultPtr' isn't a lowerCamelCase identifier.
</summary>

pub.dev analyzes the package with the core lints.

If you are certain that you don't want to follow the dart naming convention in the generated code, you can put: // ignore_for_file: type=lint at the top. See: https://dart.dev/guides/language/analysis-options#suppressing-rules-for-a-file

swift-kim commented 1 year ago

@sigurdm Thank you so much for the really quick response!

pub.dev analyzes the package with the core lints.

Does pana (pub.dev) always use the core lints even if there's a custom analysis_options.yaml in the package? I tried adding the following lines to my analysis_options.yaml since I wanted to apply the rules globally to all files, but it still didn't work.

include: package:lints/core.yaml

linter:
  rules:
    camel_case_types: false
    non_constant_identifier_names: false

If you are certain that you don't want to follow the dart naming convention in the generated code, you can put: // ignore_for_file: type=lint at the top.

Maybe this is the only option I can use if pana works in that way.

sigurdm commented 1 year ago

Yeah - it always uses those and ignores the custom analysis_options.yaml.

swift-kim commented 1 year ago

Okay. I read the ffigen documentation again and noticed that adding the following preamble is the recommended way to suppress the warnings.

preamble: |
  // ignore_for_file: camel_case_types, non_constant_identifier_names

Thank you again for the help!