Code Monkey home page Code Monkey logo

dart-lint's People

Contributors

fzyzcjy avatar hacker1024 avatar nilsreichardt avatar nohli avatar passsy avatar robiness avatar thoughtworks-tcaceres avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dart-lint's Issues

`exclude`

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

avoid_redundant_argument_values ?

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

Create a casual lint

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.

Add information that rules can be customized

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.

cancel_subscriptions has false positives

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.

Remove `implicit-casts` for new Dart versions or use this workaround

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. 💨

implicit-dynamic: false

Why implicit-dynamic is not included?
I have seen recommendation in the internet articles where they recommend to add implicit-dynamic: false.

Tweet from Remi Rousselet.

Documentation Rules

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 ?

Inspect 'Annotator' options

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

Lint rule for missing yield statement

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?

Suggestion: const can be left out in more ways than the lints allow

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

SizedBox for whitespace warning

Hello, guys. I just update lint 1.3.0. in one of my projects.

Then, I got a warning with this code:

@override
Widget build(BuildContext context) {
   return Container(width: 270, child: _video);
}

The warnings says SizedBox for whitespace.

image

I think it's a false positive. What do you think?

Ignore entire files

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.

invalid_assignment rule

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?

The lint invariant_booleans is confused inside a switch statement.

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;
          }
      }
    }
  }

analysis_options_package.yaml cannot be found

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.

one_member_abstracts should be allowed

# Defining interfaces (abstract classes), with only one method, makes sense architecture wise
# https://dart-lang.github.io/linter/lints/one_member_abstracts.html
- one_member_abstracts

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

field initializer and argument type not assignable

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.

`avoid_slow_async_io` is disabled, but the comments suggest it should exist

# 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?

conflict with sdk version in flutter

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

Comments in the analysis_options.yaml file break customization

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:

  1. Try to use pedenatic package and extend the rules adding and disabling - this works - pedantic has no comments in their files
  2. Copy the analysis_options.yaml file of this library to a local project file - customization does not work
  3. Remove all comments form the local file - customization works

The argument type 'Function' can't be assigned to the parameter type 'void Function()

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;

Broken linter around enum and import order

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)
Capture d’écran 2022-04-19 à 10 52 00

Enum instance variable is dynamic...
Capture d’écran 2022-04-19 à 10 52 05

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.

abstract class override fields

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;
}

Exclude {Key? key} from 'Put required named parameters first' rule

Since Flutter source code full of {Key? key, required ...} constructors, it would be better excluding this specific case.

Screen Shot 2021-08-31 at 10 22 36

Flutter example:

const Padding({
    Key? key,
    required this.padding,
    Widget? child,
  }) : assert(padding != null),
       super(key: key, child: child);

add in unawaited_futures

# 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.

How to solve or deactivate return_of_invalid_type_from_closure

Hi,
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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.