Analyzer option for using const - dart

Is there an analyzer option I can use in analysis_options.yaml that will notify me when I could use the const keyword? It would be nice to be notified about all the places in my code where I can use it.

There are a few dartanalyzer lints related to const:
prefer_const_constructors
prefer_const_constructors_in_immutables
prefer_const_declarations
prefer_const_literals_to_create_immutables
Also:
unnecessary_const
You can see the full list of supported lint rules.

What you're looking for is prefer_const_constructors

Related

cast_set deprecated. What’s the replacement?

I’m currently running OPA version 0.39.0, but I’m trying to upgrade to a more recent version and am getting the following issue:
rego_type_error: deprecated built-in function calls in expression: cast_set
I tried looking through the docs and release notes but don’t see anything about cast_set being deprecated. Is there a work around to continue using a deprecated function or is there a suggested replacement?
Also, is OPA following SemVer, with Major.Minor.Patch? Would expect subsequent versions after 0.39.0 to still be compatible with it since we are currently on 0.46.1.
You did not state which command you are running when you see that error. The only one that should produce that is opa check --strict, where the very purpose of the command is to check for things like unused variables, use of deprecated functions, etc... i.e. strict mode.
I just tried some other commands, like opa build and opa run, and none of them seem to produce that warning - and they shouldn't.
The idiomatic way of creating a set from an array, is to use a set comprehension:
my_arr := [1, 2, 3]
my_set := {x | x := my_arr[_]}
my_set == {1, 2, 3}
We try hard to not make backwards compatibile changes in OPA, and if you're seeing this error outside of strict mode, please open an issue. A command like opa check --strict is however meant to warn about things like this, so that's going to be an obvious exception.

Does ant design have a similar breakpoint check analagous to material-ui?

Material UI has a handy function of checking for breakpoints for example.
const matchesSM = useMediaQuery(theme.breakpoints.down("sm"));
So if the screen size goes below sm then matchesSM becomes true.
Does Ant Design have a similar feature?
Yes. It's called useBreakpoint.
Here's the doc: https://ant.design/components/grid/#components-grid-demo-useBreakpoint

Open file with default application from Vala?

What's the best way to open a file in the default application from Vala?
A bit like how xdg-open works.
I found some existing code in another application, but later on I also found this
GLib.AppInfo.launch_default_for_uri method.
A simple example:
var file = File.new_for_path (file_path);
if (file.query_exists ()) {
try {
AppInfo.launch_default_for_uri (file.get_uri (), null);
} catch (Error e) {
warning ("Unable to launch %s", file_path);
}
}
If you're using GTK, then you've also got Gtk.gtk_show_uri_on_window(), which uses the GLib stuff under the hood.
As far as I know there is only one implementation of the relevant freedesktop.org standards.
That is the reference implementation in xdg-utils:
https://www.freedesktop.org/wiki/Software/xdg-utils/
The tools are written in shell script, for example here is the source code for xdg-open:
https://cgit.freedesktop.org/xdg/xdg-utils/tree/scripts/xdg-open.in
So by far the easiest way is to just call the xdg-open script via Process.spawn_async and friends.
If you insist on using a library function you would have to implement a standard conforming library yourself.
Update:
There are quite a few libraries in various languages that implement some of the freedesktop.org standards, for example here is a list on GitHub:
https://github.com/topics/xdg
For example here is a similar tool to xdg-open written in D:
https://github.com/FreeSlave/mimeapps/blob/master/source/mimeapps.d
What I didn't find so far is a Vala / GLib or plain C library that could easily be used from a Vala application.
Update 2:
Actually it turns out there is something for that purpose in GLib (or more precisely in Gio):
https://valadoc.org/gio-2.0/GLib.AppInfo.launch_default_for_uri_async.html
https://developer.gnome.org/gio/stable/GAppInfo.html
So you should be able to use the GLib.AppInfo.launch_default_for_uri_async method.

How to make --no-packages-dir the default for dart pub in WebStorm?

Dart 1.19.0-dev supports a new flag --no-packages-dir that replaces --no-package-symlinks. Is there any way to make this the default in WebStorm?
There is no way.
We have to wait until it becomes the default in pub
https://youtrack.jetbrains.com/issue/WEB-18006

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
For example in Java, i could do this:
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...
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. 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();

Resources