google / json_serializable.dart

Generates utilities to aid in serializing to/from JSON.
https://pub.dev/packages/json_serializable
BSD 3-Clause "New" or "Revised" License
1.55k stars 395 forks source link

[problem] Dart program generated by json_annotation fails analyze check #1317

Closed kanryu closed 1 year ago

kanryu commented 1 year ago

Hi, I made a new Dart project using json_serializable.

https://github.com/kanryu/paypay_uo

It's working fine, but running dart analyze shows the problem.

Please let me know if there is a way around this issue.

$ dart analyze
Analyzing paypay_uo...

   info • lib\src\core\model\amount.g.dart:9:11 • The variable name '_$$_AmountFromJson' isn't a 
          lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase style. • 
          non_constant_identifier_names
   info • lib\src\core\model\amount.g.dart:14:22 • The variable name '_$$_AmountToJson' isn't a  
          lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase style. • 
          non_constant_identifier_names
   info • lib\src\core\model\api_result.g.dart:9:15 • The variable name '_$$_ResultInfoFromJson' 
          isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase  
          style. • non_constant_identifier_names
   info • lib\src\core\model\api_result.g.dart:16:22 • The variable name '_$$_ResultInfoToJson'  
          isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase  
          style. • non_constant_identifier_names
   info • lib\src\core\model\api_result.g.dart:23:14 • The variable name '_$$_ApiResultFromJson' 
          isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase  
          style. • non_constant_identifier_names
   info • lib\src\core\model\api_result.g.dart:29:22 • The variable name '_$$_ApiResultToJson'   
          isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase  
          style. • non_constant_identifier_names
   info • lib\src\core\model\capture_payment_auth_payload.g.dart:9:30 • The variable name        
          '_$$_CapturePaymentAuthPayloadFromJson' isn't a lowerCamelCase identifier. Try changing
          the name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\capture_payment_auth_payload.g.dart:20:22 • The variable name       
          '_$$_CapturePaymentAuthPayloadToJson' isn't a lowerCamelCase identifier. Try changing  
          the name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\cash_back_payload.g.dart:9:20 • The variable name
          '_$$_CashBackPayloadFromJson' isn't a lowerCamelCase identifier. Try changing the name 
          to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\cash_back_payload.g.dart:22:22 • The variable name
          '_$$_CashBackPayloadToJson' isn't a lowerCamelCase identifier. Try changing the name to
          follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_continuous_payment_payload.g.dart:9:35 • The variable name   
          '_$$_CreateContinuousPaymentPayloadFromJson' isn't a lowerCamelCase identifier. Try    
          changing the name to follow the lowerCamelCase style. • non_constant_identifier_names  
   info • lib\src\core\model\create_continuous_payment_payload.g.dart:19:22 • The variable name  
          '_$$_CreateContinuousPaymentPayloadToJson' isn't a lowerCamelCase identifier. Try      
          changing the name to follow the lowerCamelCase style. • non_constant_identifier_names  
   info • lib\src\core\model\create_payment_auth_payload.g.dart:9:29 • The variable name
          '_$$_CreatePaymentAuthPayloadFromJson' isn't a lowerCamelCase identifier. Try changing 
          the name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_payment_auth_payload.g.dart:19:22 • The variable name        
          '_$$_CreatePaymentAuthPayloadToJson' isn't a lowerCamelCase identifier. Try changing   
          the name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_payment_payload.g.dart:9:25 • The variable name
          '_$$_CreatePaymentPayloadFromJson' isn't a lowerCamelCase identifier. Try changing the 
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_payment_payload.g.dart:19:22 • The variable name
          '_$$_CreatePaymentPayloadToJson' isn't a lowerCamelCase identifier. Try changing the   
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_pending_payment_payload.g.dart:9:32 • The variable name      
          '_$$_CreatePendingPaymentPayloadFromJson' isn't a lowerCamelCase identifier. Try       
          changing the name to follow the lowerCamelCase style. • non_constant_identifier_names  
   info • lib\src\core\model\create_pending_payment_payload.g.dart:19:22 • The variable name     
          '_$$_CreatePendingPaymentPayloadToJson' isn't a lowerCamelCase identifier. Try changing
          the name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_qr_code_payload.g.dart:9:24 • The variable name
          '_$$_CreateQrCodePayloadFromJson' isn't a lowerCamelCase identifier. Try changing the  
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\create_qr_code_payload.g.dart:26:22 • The variable name
          '_$$_CreateQrCodePayloadToJson' isn't a lowerCamelCase identifier. Try changing the    
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\order_item.g.dart:9:14 • The variable name '_$$_OrderItemFromJson'  
          isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase  
          style. • non_constant_identifier_names
   info • lib\src\core\model\order_item.g.dart:17:22 • The variable name '_$$_OrderItemToJson'   
          isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase  
          style. • non_constant_identifier_names
   info • lib\src\core\model\refund_payment_payload.g.dart:9:25 • The variable name
          '_$$_RefundPaymentPayloadFromJson' isn't a lowerCamelCase identifier. Try changing the 
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\refund_payment_payload.g.dart:20:22 • The variable name
          '_$$_RefundPaymentPayloadToJson' isn't a lowerCamelCase identifier. Try changing the   
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\reverse_cash_back_payload.g.dart:9:27 • The variable name
          '_$$_ReverseCashBackPayloadFromJson' isn't a lowerCamelCase identifier. Try changing   
          the name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\reverse_cash_back_payload.g.dart:21:22 • The variable name
          '_$$_ReverseCashBackPayloadToJson' isn't a lowerCamelCase identifier. Try changing the 
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\revert_auth_payload.g.dart:9:22 • The variable name
          '_$$_RevertAuthPayloadFromJson' isn't a lowerCamelCase identifier. Try changing the    
          name to follow the lowerCamelCase style. • non_constant_identifier_names
   info • lib\src\core\model\revert_auth_payload.g.dart:18:22 • The variable name
          '_$$_RevertAuthPayloadToJson' isn't a lowerCamelCase identifier. Try changing the name 
          to follow the lowerCamelCase style. • non_constant_identifier_names

28 issues found.

dart version

dart --version
Dart SDK version: 3.1.0-35.0.dev (dev) (Sat Apr 22 17:37:13 2023 -0700) on "windows_x64"
kevmoo commented 1 year ago

Annoying, I know.

See https://github.com/dart-lang/source_gen#configuring-combining_builder

kanryu commented 1 year ago

@kevmoo Thanks for an important member like you to answer me. :)

Your answer wasn't a direct solution to my question, but it provided an important hint.

I noticed that I can customize the execution of 'dart analyze', so I add into analysis_options.yaml.

reference: https://dart.dev/guides/language/analysis-options

For many projects, including mine, adding this setting will solve this problem.

analysis_options.yaml

analyzer:
exclude: 
- 'build/**'
- '**/*.g.dart'
- '**/*.freezed.dart'

enjoy! :)