Okay, so today I messed around with Dart, specifically something I’m calling “Rule 34”. Sounds kinda weird, I know, but it’s just a catchy name I gave it. Basically, it’s about trying to enforce a specific coding style in my Dart projects.
I started by, you know, just coding like I normally do. Writing some functions, making some classes, the usual stuff. But then I thought, “Hey, wouldn’t it be cool if I could automatically check my code for certain style things?” Like, making sure I always use curly braces, even for single-line if statements, or maybe enforcing a specific way to format my lists.
Getting My Hands Dirty
First, I dug into the Dart documentation. I figured there had to be some built-in way to do this. And yeah, there is! Dart has this thing called the “analyzer”. It’s what powers a lot of the code completion and error highlighting you see in your IDE.
Turns out, you can configure the analyzer using a file called analysis_*
. So, I created that file in the root of my project. Inside, you can specify all sorts of rules, like linting rules. Linting is just a fancy word for checking your code for potential problems and style issues.
I added a bunch of rules, some that I found online, and some that I just made up based on what I like. For example, I added this one:
always_use_package_imports: true
That one forces me to always import packages using the package:
prefix, which is a good practice, I think. Keeps things organized.
Then I tried another one:
prefer_single_quotes: true
This forces to use single quote, it’s a simple config.

I played around with a few other rules too, like prefer_const_constructors
(which encourages you to use const
when you can), and avoid_empty_else
(which, well, you can probably guess what that one does).
The “Aha!” Moment
The cool part was, after setting up these rules, my IDE started showing me warnings and suggestions whenever I broke them! It was like having a little coding buddy constantly looking over my shoulder, making sure I was following my own rules. I found myself fixing a lot of little things that I probably wouldn’t have noticed otherwise.
Wrapping Up
So, yeah, that’s “Rule 34” for me. It’s not some super complicated thing, just a way to use Dart’s built-in tools to enforce a consistent coding style. I think it’s going to help me write cleaner, more maintainable code in the long run. It’s like setting up the guardrails on a highway – keeps you from veering off course. Plus, it was kinda fun to tinker with the analysis_*
file and see what different rules did. I definitely recommend giving it a try if you’re working with Dart.
I kept on adjusting little things, after runing my program, things got better!