Skip to content

Commit 3b50f5b

Browse files
chore: allow configuring custom haptic wrappers
1 parent 78ad66a commit 3b50f5b

5 files changed

Lines changed: 92 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.8.2-dev.2](https://github.com/Solvro/lib-mobile-solvro-config/compare/v1.8.2-dev.1...v1.8.2-dev.2) (2026-06-07)
4+
5+
6+
### Features
7+
8+
* allow configuring custom haptic wrappers
9+
310
## [1.8.0](https://github.com/Solvro/lib-mobile-solvro-config/compare/v1.7.0...v1.8.0) (2026-06-06)
411

512

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@ $ solvro_config --version
2424
# Show usage help
2525
$ solvro_config --help
2626
```
27+
28+
## Custom haptic wrappers
29+
30+
The `add_haptic_feedback_on_user_interaction` rule accepts custom haptic wrappers in `analysis_options.yaml`:
31+
32+
```yaml
33+
plugins:
34+
solvro_config:
35+
version: ^1.8.0
36+
haptic_wrappers:
37+
- HapticFeedback.
38+
- AppHaptics.
39+
```

lib/solvro_forks/solvro_custom_linter.dart

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "package:analyzer/dart/ast/visitor.dart";
99
import "package:analyzer/dart/element/element.dart";
1010
import "package:analyzer/dart/element/type.dart";
1111
import "package:analyzer/error/error.dart";
12+
import "package:yaml/yaml.dart";
1213

1314
class SolvroCustomLinterPlugin extends Plugin {
1415
@override
@@ -306,11 +307,15 @@ class AddHapticFeedbackOnUserInteractionRule extends _SolvroRule {
306307
"Encourages HapticFeedback in interaction callbacks.",
307308
);
308309

310+
static const _defaultHapticWrappers = ["HapticFeedback."];
311+
309312
@override
310313
void registerNodeProcessors(
311314
RuleVisitorRegistry registry,
312315
RuleContext context,
313316
) {
317+
final hapticWrappers = _configuredHapticWrappers(context);
318+
314319
registry.addNamedExpression(
315320
this,
316321
_NamedExpressionVisitor(this, (node) {
@@ -322,12 +327,74 @@ class AddHapticFeedbackOnUserInteractionRule extends _SolvroRule {
322327
return;
323328
}
324329
final source = node.expression.toString();
325-
if (!source.contains("HapticFeedback.")) {
330+
if (!hapticWrappers.any(source.contains)) {
326331
reportAtNode(node);
327332
}
328333
}),
329334
);
330335
}
336+
337+
static List<String> _configuredHapticWrappers(RuleContext context) {
338+
final package = context.package;
339+
if (package == null) {
340+
return _defaultHapticWrappers;
341+
}
342+
343+
final optionsFile = package.root.getChildAssumingFile(
344+
"analysis_options.yaml",
345+
);
346+
if (!optionsFile.exists) {
347+
return _defaultHapticWrappers;
348+
}
349+
350+
try {
351+
final options = loadYamlNode(optionsFile.readAsStringSync());
352+
if (options is! YamlMap) {
353+
return _defaultHapticWrappers;
354+
}
355+
356+
final plugins = options["plugins"];
357+
if (plugins is! YamlMap) {
358+
return _defaultHapticWrappers;
359+
}
360+
361+
for (final pluginName in ["solvro_config", "solvro_custom_linter"]) {
362+
final pluginConfig = plugins[pluginName];
363+
if (pluginConfig is! YamlMap) {
364+
continue;
365+
}
366+
367+
final wrappers = <String>[];
368+
_addConfiguredWrappers(wrappers, pluginConfig["haptic_wrapper"]);
369+
_addConfiguredWrappers(wrappers, pluginConfig["haptic_wrappers"]);
370+
371+
if (wrappers.isNotEmpty) {
372+
return wrappers;
373+
}
374+
}
375+
} on YamlException {
376+
return _defaultHapticWrappers;
377+
} on Exception {
378+
return _defaultHapticWrappers;
379+
}
380+
381+
return _defaultHapticWrappers;
382+
}
383+
384+
static void _addConfiguredWrappers(List<String> wrappers, Object? value) {
385+
if (value is String && value.isNotEmpty) {
386+
wrappers.add(value);
387+
return;
388+
}
389+
390+
if (value is YamlList) {
391+
for (final item in value) {
392+
if (item is String && item.isNotEmpty) {
393+
wrappers.add(item);
394+
}
395+
}
396+
}
397+
}
331398
}
332399

333400
class AssetImageRule extends _SolvroRule {
@@ -670,9 +737,7 @@ class PreferToIncludeSliverInNameRule extends _SolvroRule {
670737
_ClassVisitor(this, (node) {
671738
final buildMethod = node.body.members
672739
.whereType<MethodDeclaration>()
673-
.where(
674-
(method) => method.name.lexeme == "build",
675-
);
740+
.where((method) => method.name.lexeme == "build");
676741
if (buildMethod.isEmpty) {
677742
return;
678743
}

lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: solvro_config
22
description: A Dart linter/config package for Solvro projects.
3-
version: 1.8.2-dev.1
3+
version: 1.8.2-dev.2
44

55
repository: https://github.com/Solvro/lib-mobile-solvro-config
66

@@ -20,6 +20,7 @@ dependencies:
2020
husky: ^0.1.7
2121
lint_staged: ^0.5.1
2222
process_run: ^1.3.3+1
23+
yaml: ^3.1.3
2324

2425
lint_staged:
2526
"lib/**.dart": dart format && dart fix --apply

0 commit comments

Comments
 (0)