Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement correctly static analysis rules suppression #506

Closed
iXamDev opened this issue Oct 6, 2023 · 2 comments · Fixed by #507
Closed

implement correctly static analysis rules suppression #506

iXamDev opened this issue Oct 6, 2023 · 2 comments · Fixed by #507
Assignees
Labels
bug Something isn't working

Comments

@iXamDev
Copy link

iXamDev commented Oct 6, 2023

Steps to Reproduce

  1. Create any chopper service
  2. Adjust analysis_options.yaml and enable non-default rules, for example, 'omit_local_variable_types'
  3. Proceed code generation
  4. Execute flutter analyze --fatal-warnings on the code sample

Expected results:
No warnings or errors are shown for generated .chopper.dart files

Actual results:

Linter warnings are shown for .chopper.dart files:

info • Unnecessary type annotation on a local variable • sources/core/patient_core/lib/src/api/services/dummy_service.chopper.dart:21:5 • omit_local_variable_types

image
Code sample

dummy_service.dart

import 'package:chopper/chopper.dart';

part 'dummy_service.chopper.dart';

@ChopperApi(baseUrl: 'dummy')
abstract class DummyService extends ChopperService {
  static DummyService create([ChopperClient? client]) => _$DummyService(client);

  @Get(path: 'sample')
  Future<Response<dynamic>> get();
}

analysis_options.yaml

include: package:flutter_lints/flutter.yaml

linter:
  rules:
    omit_local_variable_types: true
Logs
   info • Unnecessary type annotation on a local variable • sources/core/platform_core/lib/src/api/services/dummy_service.chopper.dart:21:5 • omit_local_variable_types
   info • Unnecessary type annotation on a local variable • sources/core/platform_core/lib/src/api/services/dummy_service.chopper.dart:22:5 • omit_local_variable_types

Solution

It would help if you disabled the linter for the generated files entirely instead of ignoring specific rules.

So please replace the comment in generated files // ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_string_interpolations, unnecessary_brace_in_string_interps with // ignore_for_file: type=lint.

This approach is used by other projects like built_value.

@iXamDev iXamDev added the bug Something isn't working label Oct 6, 2023
@techouse techouse self-assigned this Oct 6, 2023
@techouse
Copy link
Collaborator

techouse commented Oct 6, 2023

Hey 👋

Thanx for the bug report. Should be fixed in #507

@iXamDev
Copy link
Author

iXamDev commented Oct 9, 2023

Hi, yes the issue is resolved.
Thanks a lot for your rapid assistance 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants