passsy / dart-lint Goto Github PK
View Code? Open in Web Editor NEWAn opinionated, community-driven set of lint rules for Dart and Flutter projects. Like pedantic but stricter
License: Apache License 2.0
An opinionated, community-driven set of lint rules for Dart and Flutter projects. Like pedantic but stricter
License: Apache License 2.0
I wanted to ask if there is any rule that enforces documentation in Flutter code ? Like any rule that check if methods and attributes of a class are properly documented with proper style guide ?
dart-lint/lib/analysis_options.yaml
Lines 348 to 350 in c83db92
As already definied in the comment, it makes sense to define interfaces (abstract classes in dart) architecture wise when defining boundaries. A Function reference is not a good replacement because it is very likely that new functions will be added which then would result in a breaking change.
Seems like it is accidentally enabled
I am using VSCode and I added lint:^1.2.0
as a dev_dependencies
.
Now trying to import analysis_options_package.yaml
as shown below breaks the flutter analyze
.
include: package:lint/analysis_options_package.yaml
Following warning is raise by flutter analyze
.
warning - The include file package:lint/analysis_options_package.yaml in
C:\my\local\path\to\analysis_options.yaml cannot be found -
analysis_options.yaml:1:11 - include_file_not_found
Should it be added to normal dependencies
instead dev_dependecies
? In my case that didn't help either. Not sure if I am missing any step.
if I want to restrict some static text like 'google.com' so how I write custom rule
Until now I haven't found a single project using this rule. Better remove it.
Please have a look at dart-lang/linter#3286 to see why it is wrong. So, shall we disable it?
https://dart-lang.github.io/linter/lints/avoid_dynamic_calls.html
TODO research implications on actual code
I am not able to find a lint rule which can analyse and tell me if the variable or method can be private.
Hello,
I didn't find the reason, but the linter got confused around my import for no special reason (no double enum / class with the same name) and i got the following behavior which is funny :
Enum is type DownloadType (good)
Enum instance variable is dynamic...
When playing with import order this issue disappear but as I used this rule : directives_ordering I can't. If i remove the comma just after DownloadType downloadType, error disappear... So seems like parsing error from the linter.
I got massive errors from the analyzer includes:
argument_type_not_assignable
field_initializer_not_assignable
Most of them are from the Map<String, dynamic> json
parsing to a model class.
I tried to turn them off in the analysis_options.yaml
, but it didn't help.
I think these 2 errors contradict each other
lint: ^1.6.0
abstract class IContent {
final String? name;
IContent({
this.name,
});
}
class Content extends IContent {
// 2 conflicting errors
// Annotate overridden members.dart(annotate_overrides)
// Don't override fields.dart(overridden_fields)
final String? name;
}
Hello. I have tried several different ways to get the linter to ignore this error but am unsure what the correct answer is.
"A value of type ‘{0}’ can’t be assigned to a variable of type ‘{1}’"
I have tried:
invalid_assignment: true
invalid_assignment: false
invalid_assignment: ignore
invalid_assignment: warn
Nothing seems to prevent this from being a compile error in my project except removing [lint: ^1.0.0] completely
What am I doing wrong? What do I need to do to use?
I have 1 problem with lint and mobx
in the raisedbutton onprees I put the mobx computer and the following error comes out
The argument type 'Function' can't be assigned to the parameter type 'void Function ()'
code example
// Page
final LoginController controller = LoginModule.to.get <LoginController> ();
Observer (
builder: (_) {
return Container (
height: 50,
child: RaisedButton (
onPressed: controller.loginPressed,
shape: RoundedRectangleBorder (
borderRadius: BorderRadius.circular (20),
),
child: controller.loading
? const CircularProgressIndicator (
valueColor:
AlwaysStoppedAnimation (Colors.white),
)
: const Text (
'Log in',
style: TextStyle (
color: Colors.white,
fontSize: 20,
),
),
),
);
},
)
// Controller
@computed
Function get loginPressed =>
emailValid && passwordValid &&! loading? _login: null;
Is it possible to ignore files? I've got some generated files that give prefer_const_declarations warnings.
It would be nice to be possible to ignore *.g.dart and *.chopper.dart files.
Hey,
I'm a bit new to dart, but I would like to know if it is possible that this package be used with dart-sdk
2.17, the latest stable release of dart-sdk
.
For coding dojos, examples and quick prototypes a more relaxed set of rules would be great.
For that kind of apps it's irrelevant if const
or prints
are added or not.
I am creating this issue after my comment here: #3 (comment)
After further testing, I have discovered that the comment ins the analysis_options.yaml
file break the possibility of customization. This may occur due to some YAML library parsing problems, maybe some undocumented handling of comment nodes, no idea.
I have done the following to determine this:
pedenatic
package and extend the rules adding and disabling - this works - pedantic has no comments in their filesanalysis_options.yaml
file of this library to a local project file - customization does not workHi,
I freshly installed your linter package. I'm using bloc and bloc_test and get tons of issues because of "return_of_invalid_type_from_closure".
blocTest(
'emits [ScannerLoadingState, ScannerNotValidState, ScannerInitState] if token is valid',
build: () async {
...
},
// bloc.add is causing the "return_of_invalid_type_from_closure"
act: (bloc) => bloc.add(CheckScannedCode(
code: 'code',
eventUuid: '123-jdakls-daksl',
checkState: 'CHECKED_IN',
)),
expect: [
isA<ScannerLoadingState>(),
isA<ScannerNotValidState>(),
isA<ScannerInitState>()
],
);
I don't really know how to fix this so I tried decativating it in analysis_options.yaml but it doesn't work.
include: package:lint/analysis_options.yaml
linter:
rules:
return_of_invalid_type_from_closure: false
What am I doing wrong? How can I fix it?
Best regards and thanks for your help
Verena
In my bloc I have following code:
@override
Stream<VerificationState> mapEventToState(VerificationEvent event) async* {
yield* event.when(
loginRetry: (phoneNumber) => _loginRetry( phoneNumber ),
verify: (phoneNumber, code) => _verify(phoneNumber, code),
);
}
If I forget to add yield*
, lint does not warn me. How can I be warned for such a mistake?
While developing a Flutter plugin, after adding
dev_dependencies:
lint: 1.6.0
I'm getting a warning indicating that the analysis_options
file cannot be found.
warning: The include file package:lint/analysis_options_package.yaml in /my/local/path/to/analysis_options.yaml cannot be found. (include_file_not_found at [my_project] analysis_options.yaml:1)
flutter 3.0 has released. seems that there are some new: https://github.com/dart-lang/lints/blob/main/CHANGELOG.md#200
# Might cause frame drops because of synchronous file access on mobile, especially on older phones with slow storage.
# There are no known measurements sync access does *not* drop frames.
#
# https://dart-lang.github.io/linter/lints/avoid_slow_async_io.html
# - avoid_slow_async_io
From the comments, I guess we should enable this rule?
I want to disable the lint: "The argument type 'dynamic' can't be assigned to the parameter type x" but I can't find it.
Update
I used this and the problem is solved!
analyzer:
strong-mode:
implicit-casts: true
I applied it in my project, but I haven' t find some way to quick fix the code.
Thanks for making this package.
I think it would make sense to inform people that these rules can easily be customized. It was not clear to me until I checked Dart docs.
Ignoring rules is very nice when migrating from ugly codebase - I just added this to my project and I have hundreds of warnings and errors. I fixed what I could, ignored the rest, and will continue cleanup when I have more time.
# Too many false positives.
# Using the pedantic package for the unawaited function doesn't make code better readable
#
# pedantic: enabled
# https://dart-lang.github.io/linter/lints/unawaited_futures.html
# - unawaited_futures
As above the doco suggest this does produce false positive.
The converse issues is that diagnosing a missing await can be a very complex issue.
I personally am happy to wear the burden of having to unawait methods to avoid bugs especially bugs that are hard to solve.
I really think this should be part of the default package.
I just added this to a small project (6000 lines) and it fixed three bugs and returned no false positives.
analyzer:
exclude:
- linux/**
doesn't work.
I also tried
analyzer:
exclude: [linux/**]
flutter pub get
Running "flutter pub get" in appname...
The current Dart SDK version is 2.10.4.
Because appname depends on lint >=1.5.0 which requires SDK version >=2.12.0-0 <3.0.0, version solving failed.
pub get failed (1; Because appname depends on lint >=1.5.0 which requires SDK version >=2.12.0-0 <3.0.0, version solving failed.)
exit code 1
Hey!
I just set up lint on my project (Relatively late because I just found out about it now) and I get the error "Inspect 'Annotator' options" in a lot of places. What does this error mean and how can I fix it?
The error occurs both in widgets, as in variables, etc.
I would be very happy about an answer,
LG
Clarification please:
I am not sure if this package supports the exclude
step, when testing I found that it is skipped over, i.e.
include: package:lint/analysis_options.yaml
linter:
rules:
sort_constructors_first: true
prefer_final_in_for_each: false
analyzer:
exclude:
- '**/*.chopper.dart'
- '**/*.g.dart'
- '**/*.*.dart' // ← I've tried using this blob pattern and all versions seem to be ignored
- lib/**/*.g.dart // this blob pattern also appears not to work as the warning is displayed still
errors:
missing_required_param: error
return_of_invalid_type_from_closure: ignore
I still get the following for the generated files:
Avoid const keyword.dartunnecessary_const
Thanks
How disable this rule ?
Hi thanks for the lint rules! I wonder whether this is a super set of the Flutter-suggested package:flutter_lints/flutter.yaml?
Hellou, 👋🏽
I'm getting the following warning when including package:lint/strict.yaml
(or the equivalent casual.yaml
or package.yaml
file) while I'm on Dart version 3.0.0
(build 3.0.0-218.1.beta
):
Warning in the included options file <path>/lib/strict.yaml(227..240): The option 'implicit-casts' is
no longer supported.dart(included_file_warning)
It seems that the implicit-casts
option needs to be removed for Dart versions >= 3
. As I couldn't figure out conditional includes (I don't think they exist for yaml
files), maybe we need additional files without the option so the user can use them for newer Dart versions.
Anyways, a current workaround would be to override strong-mode
by making sure your analysis_options.yaml
file contains:
package:lint/package.yaml # or any other
analyzer:
strong-mode:
This will make the warning disappear. 💨
cancel_subscriptions
is disabled in pedantic because it has false positives when you use a utility method or class to call cancel
.
A similar lint rule close_sinks
is also disabled following the same logic.
I personally ran into those false positives. If you do, upvote this issue.
Nice linter! Really appreciate the explanation for every rule choice.
According to some resources, const is in some cases optional. Meaning it gets added by the runtime and you do not gain any performance benefits by adding const. But I am not 100% sure, as in some cases it ensures that const is definitely used and thus has better performance.
IMO I would leave const out, trust the DartVM to optimize most of it and for that **VERY expensive ** constructor I would leave it to the developer to add it in.
This should clean up code in flutter a lot, since a lot of widgets can be const.
Some resources:
const is optional inside of a constant context.
Dart2 Migration guide: https://dart.dev/dart-2
In short, even without the keyword, we can still unambiguously recognize the expressions that create objects. In that sense, the keywords are superfluous.
Similarly, it may be important for developers to ensure that certain expressions are constant, because of the improved performance and the guaranteed canonicalization.
https://github.com/dart-lang/sdk/blob/master/docs/language/informal/implicit-creation.md
Here are some very good examples on where it is optional:
https://stackoverflow.com/questions/52581148/when-is-const-optional-in-dart-2
In the pub.dev install section of this package it is written to insert the dependency under dependencies
.
As this dependency is not running while the software is running (as far as I know) it should be placed under dev_dependencies
.
Is it ok to place it under dev_dependencies
and if it does can we change it in the pub.dev install page for the incoming users?
When using lint 1.5.1
In the following switch statement there are two cases that both check if char = ' '.
The lint incorrectly marks the second test as invariant_booleans as it sees the if char = ' ' in the first case and assume that the test protects the second case from having a space.
If you change the first char = ' ' in the first case to anything else the warning goes away.
The lint should not fire in this scenario.
enum _ParseState { starting, inQuote, inWord }
/// parses the given command breaking them done into words
void _parse2(String commandLine) {
var state = _ParseState.starting;
for (var i = 0; i < commandLine.length; i++) {
final char = commandLine[i];
switch (state) {
case _ParseState.starting:
if (char == ' ') {
break;
}
break;
case _ParseState.inWord:
if (char == ' ')
{
break;
}
}
}
}
Nice linter! Really appreciate the explanation for every rule choice.
So I'm getting avoid_redundant_argument_values but this is how Flutter widgets work in the UI for example flutter crossAxisAlignment shouldn't this be removed from the lint to set to false by default
Now that there's a new official lint package, I think another comparison in the README is appropriate.
False positive in Pubspec.yaml shows line under Cupertino_icons which is now under the flutter and sdk entries.
No quick fix on popup ?
RegExp(
r'(\s)'
'?(foo|bar)(\s)?',
caseSensitive: false,
),
the third matching group (\s)
is incorrectly identified as unecessary_string_escapes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.