简体   繁体   English

如何强制在DartEditor中生成警告

[英]How to force generating a warning in DartEditor

I'm looking for a way to generate a warning anywhere in my code (top level, class, functions). 我正在寻找一种在我的代码(顶级,类,函数)中的任何位置生成警告的方法。 As I'm typically having a 0 warning policy, this enables me to see where I make a change I need to revert before commit 因为我通常有一个0警告策略,这使我能够看到我在提交之前需要还原的地方

For example in Java, i could do this: 例如在Java中,我可以这样做:

private int warning_revert_to_false;
boolean DEBUG = true;

and it will generate a warning (according to my settings). 它会产生一个警告(根据我的设置)。 Using jslint/jshint that's easy (mixed tab/space for example), in C/C++ i can use pragma... 使用简单的jslint / jshint(例如混合制表符/空格),在C / C ++中我可以使用pragma ...

Basically I want the code to still compile and run and so far in Dart, I could not find a simple solution and I'm sure there is one that I have missed. 基本上我希望代码仍然可以编译和运行,到目前为止在Dart中,我找不到一个简单的解决方案,我确信有一个我错过了。 Thanks! 谢谢!

Add the following library to your program: 将以下库添加到您的程序:

library forced;    
import 'package:meta/meta.dart';

class Forced {
  @deprecated
  static void warning() {

  }
}

Wherever you want a forced warning you can simply write: 无论您想要强制警告,您都可以简单地写:

Forced.warning();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM