Comments (3)
@passsy The flutter repo is using this rule
from dart-lint.
Yes @Juneezee they are indeed using it, it is however not always so nice, matter of opinion of course. Here is my reasoning around this rule.
I do like the default unnamed constructor first, and that is ON via another rule, but after it I want to see it followed by its properties, and then after this other named constructors and factories. This rule gets in the way of that order and forces you to put (often final) constructor properties after all the named constructors and factories, making them tedious to find and disconnected from where I want to see, read and maintain them. This is especially the case if there are many constructors and factories and they have a lot of parameters.
I also disabled this rules in my personal custom rules and order things as described above, which apart from the default constructor properties coming right after the constructor, is where it I deviate from the rule, but otherwise I do put constructors first.
Like you said, the entire Flutter repo does use this rule, but take a look at eg ThemeData and many other classes with a long list of properties and different constructors and factories, you have to really scroll and search for the properties with their doc comments. and adding new properties gets tedious with the long distance between its declaration and usage in the default constructor.
I think @passsy made the right call here, of course that is opinionated too, but many lint rules are 😄
from dart-lint.
Just my two cents -- I really like this rule. 😄
Reason being is that, as a user of some Dart API, package or components, I find that how to interact with a given class is more useful and interesting to me than what the class contains, especially since a constructor does not always fully align with the fields that are inside it (like, for example, Size.square(double dimension)
).
If I want to dive into the specific fields a class contains or what its inner workings look like, I can scroll over to the fields and methods.
Additionally, for code that isn't null-safe yet, I find it useful to immediately see what arguments can and cannot be null
, and see other assertions unrelated to null
.
... but take a look at eg ThemeData and many other classes with a long list of properties and different constructors and factories, you have to really scroll and search for the properties with their doc comments. and adding new properties gets tedious with the long distance between its declaration and usage in the default constructor.
Though I understand the irritation here, this is a minor nuisance to me and doesn't weigh against the advantages this rule provides for readability when it comes to API consumption. Using an IDE, it's easy to find any field or constructor (in VS Code, the default binding is ⌘+Shift+O
/Ctrl+Shift+O
), so I don't see this as an issue. 👍🏻
from dart-lint.
Related Issues (20)
- avoid_redundant_argument_values ? HOT 5
- Enable avoid_dynamic_calls HOT 2
- Is it a superset of `package:flutter_lints/flutter.yaml`? HOT 1
- Shall we disable `use_decorated_box` since it seems to be wrong: Its fix is not equivalent and changes UI
- must_be_immutable
- `avoid_slow_async_io` is disabled, but the comments suggest it should exist HOT 2
- Broken linter around enum and import order HOT 2
- Version tag for `1.8.2` is missing on GitHub HOT 1
- flutter 3.0's lints HOT 3
- Updating this package to use dart-sdk 2.17 is possible ? HOT 1
- Create a casual lint HOT 1
- Documentation Rules HOT 1
- Remove `implicit-casts` for new Dart versions or use this workaround HOT 1
- False positive: unecessary_string_escapes HOT 2
- Remove `implicit-casts` HOT 2
- "implicit-casts" is not longer suppported Dart 3.10 HOT 1
- Add new rules of Dart 3.1 HOT 1
- Add new rules for Dart 3.2 HOT 12
- Uses of `dynamic` as generic type are not flagged because `always_specify_types` is disabled HOT 2
- Dart 3.1 - no recognized rules HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart-lint.