flutter_hooks_lint_plugin

Last updated:

0 purchases

flutter_hooks_lint_plugin Image
flutter_hooks_lint_plugin Images
Add to Cart

Description:

flutter hooks lint plugin

flutter_hooks_lint_plugin #
flutter_hooks_lint_plugin is a dart analyzer plugin for the flutter hooks, inspired by eslint-plugin-react-hooks.
Rules #
Missing/Unnecessary keys #
Lint to detect missing, unnecessary keys in the useEffect calling.
It finds build variables (class fields, local variables, any other build-related variables) in the HookWidget, then compares references of the build variables and specified keys in the useEffect calling, and reports a lint error if there are any differences.
final variable1 = callSomething();
final variable2 = callSomething();

useEffect(() {
print(variable1);
}, [variable2]); // <= missing key 'variable1', unnecessary key 'variable2'
copied to clipboard
Avoid nested using of hooks #
Lint to detect nested using of hooks which is one of the bad practices.
It reports a lint error if there are any using of hooks under control flow syntax (if, for, while, ... ).
if (flag) {
final variable = useState('hello'); // <= avoid nested hooks
}
copied to clipboard
Installation #
Add flutter_hooks_lint_plugin dependency to your pubspec.yaml:
dev_dependencies:
flutter_hooks_lint_plugin: ^0.6.1
copied to clipboard
Add flutter_hooks_lint_plugin plugin directive to your analyzer_options.yaml:
analyzer:
plugins:
- flutter_hooks_lint_plugin
copied to clipboard
Then, run flutter pub get and restart your IDE/Editor.
Options #
You can customize plugin's behavior by the analysis_options.yaml:
flutter_hooks_lint_plugin:
exhaustive_keys:
# hooks do not change over the state's lifecycle
constant_hooks:
# default values
- useRef
- useIsMounted
- useFocusNode
- useContext

# your custom hooks here
- useConstantValue
copied to clipboard
Suppress lints #
There are several ways to suppress lints:

add // ignore_for_file: exhaustive_keys, nested_hooks to suppress lints in the entire file
add // ignore: exhaustive_keys, nested_hooks to suppress lints at the next or current line
add // ignore_keys: foo, bar to suppress lints for the specific keys at the next or current line

CLI #
You can also use this plugin by CLI command:
$ dart pub run flutter_hooks_lint_plugin:flutter_hooks_lint analyze ./

$ flutter pub run flutter_hooks_lint_plugin:flutter_hooks_lint analyze ./
copied to clipboard
TODO #

✅ support Fix (suggestion)

Contribution #
Welcome PRs!
You can develop locally by modifying plugin's dependency to absolute path in tools/analyzer_plugin/pubspec.yaml:
dependencies:
flutter_hooks_lint_plugin:
path: /home/mjhd/flutter_hooks_lint_plugin # <= absolute path to the cloned directory
copied to clipboard
LICENSE #
The MIT License © mjhd

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.