Reactter


Pub Publisher Reactter Lint Pub points MIT License

Reactter_lint is an analytics tool for Reactter that helps developers to encourage good coding practices and preventing frequent problems using the conventions Reactter.

Contents

Quickstart

Run this command in your root project:

dart pub add -d reactter_lint custom_lint

And then include these lines of code into analysis_options.yaml:

analyzer:
  plugins:
    - custom_lint

Then you can see suggestions in your IDE or you can run checks manually:

dart run custom_lint

Lints

hook_late_convention

The hook late must be attached an instance.

Bad

Cause: ReactterHook cannot be late without attaching an instance.

class AppController {
  final otherState = UseState(0);
  late final stateLate = UseState(otherState.value);
  ...
}

Good

Fix: Use Reactter.lazyState for attaching a instance.

class AppController {
  final otherState = UseState(0);
  late final stateLate = Reactter.lazyState(
    () => UseState(otherState.value),
    this,
  );
  ...
}

hook_name_convention

The hook name should be prefixed with use.

Bad

Cause: The hook name is not prefixed with use.

class MyHook extends ReactterHook {
  ...
}

Good

Fix: Name hook using use preffix.

class UseMyHook extends ReactterHook {
  ...
}

invalid_hook_position

The hook must be defined after the hook register.

Bad

Cause: The hook cannot be defined before the hook register.

class UseMyHook extends ReactterHook {
  final stateHook = UseState(0);
  final $ = ReactterHook.$register;
  ...
}

Good

Fix: Define it after the hook register.

class UseMyHook extends ReactterHook {
  final $ = ReactterHook.$register;
  final stateHook = UseState(0);
  ...
}

invalid_hook_register

The hook register('$' field) must be final only.

Bad

Cause: The hook register cannot be defined using getter.

class MyHook extends ReactterHook {
  get $ => ReactterHook.$register;
  ...
}

Cause: The hook register cannot be defined using setter.

class UseMyHook extends ReactterHook {
  set $(_) => ReactterHook.$register;
  ...
}

Cause: The hook register cannot be defined using var keyword.

class UseMyHook extends ReactterHook {
  var $ = ReactterHook.$register;
  ...
}

Cause: The hook register cannot be defined using a type.

class UseMyHook extends ReactterHook {
  Object $ = ReactterHook.$register;
  ...
}

Good

Fix: Define it using final keyword.

class UseMyHook extends ReactterHook {
  final $ = ReactterHook.$register;
  ...
}

Libraries

reactter_lint