Skip to content

Commit d837ddd

Browse files
authored
Merge pull request #7 from lizy-coding/develop
新增特性
2 parents 89a4960 + cb46053 commit d837ddd

37 files changed

Lines changed: 2323 additions & 220 deletions

.github/workflows/flutterguard.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: FlutterGuard
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
scan:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
runs-on: ${{ matrix.os }}
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: dart-lang/setup-dart@v1
20+
with:
21+
sdk: "3.3.0"
22+
23+
- name: Install FlutterGuard
24+
run: dart pub global activate flutterguard_cli
25+
26+
- name: Scan
27+
run: flutterguard scan . --format json --fail-on high --min-score 80
28+
continue-on-error: true
29+
30+
- name: Upload report
31+
if: always()
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: flutterguard-report-${{ matrix.os }}
35+
path: .flutterguard/report.json

AGENTS.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,62 @@ IoT/smart home Flutter project static analysis CLI plugin. NOT an observability
1919
|---------|---------|
2020
| `dart run melos bootstrap` | Install workspace dependencies |
2121
| `dart run melos run analyze` | dart analyze on all packages |
22-
| `dart run melos run test:cli` | CLI tests only |
23-
| `dart run flutterguard scan -p <path>` | Run scan on a project |
22+
| `dart run melos run test:cli` | CLI tests only (26 tests) |
23+
| `flutterguard scan [<path>]` | Run scan on a project (path defaults to current dir) |
24+
| `flutterguard scan <path> --format json --fail-on high` | JSON output with CI gate |
25+
| `dart compile exe ... -o flutterguard` | Compile native binary |
26+
27+
## CI & Automation
28+
- `.github/workflows/flutterguard.yml` — CI with ubuntu/macos/windows matrix
29+
- `scripts/compile.sh` / `scripts/compile.ps1` — cross-platform native binary compilation
30+
- `scripts/scan_ci.sh` / `scripts/scan_ci.ps1` — local CI gate scripts
2431

2532
## CLI Entry Point
2633
`packages/flutterguard_cli/bin/flutterguard.dart`
2734

28-
Wired rules (5): LargeUnitsRule, LifecycleResourceRule, LayerViolationRule, ModuleViolationRule, CircularDependencyRule
35+
Supports positional path: `flutterguard scan ./my_project` (no `-p` required). Project auto-discovery walks up from CWD to find `flutterguard.yaml`, `pubspec.yaml`, or `lib/`.
36+
37+
Wired rules (11 rule classes, 13 rule IDs):
38+
- Standards: LargeUnitsRule (3 IDs), MissingConstConstructorRule, PubspecSecurityRule
39+
- Performance: LifecycleResourceRule
40+
- Architecture: LayerViolationRule, ModuleViolationRule, CircularDependencyRule
41+
- IoT: DeviceLifecycleRule, MqttConnectionRule, BleScanningRule, IotSecurityRule
2942

3043
## Source Layout
3144
```
3245
packages/flutterguard_cli/lib/src/
33-
config_loader.dart # YAML → ScanConfig (incl architecture.layers/modules)
46+
config_loader.dart # YAML → ScanConfig typedefs (11 rule configs + architecture)
3447
file_collector.dart # Glob file discovery
48+
project_resolver.dart # Project auto-discovery (walk-up flutterguard.yaml / pubspec.yaml / lib/)
3549
static_issue.dart # StaticIssue + RiskLevel + IssueDomain + Priority
36-
report_generator.dart # Table + JSON output + score
50+
report_generator.dart # Table + JSON output + score, --no-color support
3751
domain.dart # IssueDomain enum (architecture/performance/standards)
3852
priority.dart # Priority enum (p0/p1/p2)
53+
path_utils.dart # Cross-platform path/glob helpers (p.Context abstraction)
54+
import_utils.dart # Dart import resolution against collected files
55+
source_utils.dart # Analyzer offset → line number conversion
3956
rules/
40-
large_units.dart # large_file, large_class, large_build_method
41-
lifecycle_resource.dart # lifecycle_resource_not_disposed
42-
layer_violation.dart # layer_violation (architecture layer breaches)
43-
module_violation.dart # module_violation (cross-module breaches)
44-
circular_dependency.dart # circular_dependency (file-level cycles)
57+
large_units.dart # large_file, large_class, large_build_method
58+
lifecycle_resource.dart # lifecycle_resource_not_disposed
59+
layer_violation.dart # layer_violation (architecture layer breaches)
60+
module_violation.dart # module_violation (cross-module breaches)
61+
circular_dependency.dart # circular_dependency (file-level cycles)
62+
missing_const_constructor.dart # missing_const_constructor
63+
iot_security.dart # iot_security (hardcoded secrets, cleartext MQTT/HTTP, insecure BLE)
64+
device_lifecycle.dart # device_lifecycle (init/teardown pair checks)
65+
mqtt_connection.dart # mqtt_connection (MQTT connect/disconnect, broker URLs)
66+
ble_scanning.dart # ble_scanning (BLE startScan/stopScan, timeout)
67+
pubspec_security.dart # pubspec_security (unbounded deps, deprecated packages)
4568
```
4669

4770
## Spec
4871
Single source of truth: `docs/FLUTTERGUARD_SPEC.md` — read before implementing any feature.
4972

5073
## Maintenance Rules
51-
1. New rule: spec entry → config typedef → rule class → fixture → test → wire into bin/flutterguard.dart
74+
1. New rule: spec entry → config typedef → rule class → fixture → test → wire into scanner.dart
5275
2. Always run `melos run analyze` + `melos run test:cli` before committing
5376
3. Do NOT modify archived packages (core/dio/flutter) — they are frozen references
5477
4. Do NOT add Flutter widgets, web/cloud infra, or SaaS SDKs
5578
5. Output format defaults to `table`. JSON available via `--format=json`
5679
6. Architecture rules require explicit `architecture.layers` / `architecture.modules` in flutterguard.yaml
80+
7. CLI supports positional path (`flutterguard scan ./project`) and `--no-color` flag

CHANGELOG.md

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

3+
## 0.2.0 (2026-06-15)
4+
5+
### IoT Domain Rules (5 new rules)
6+
7+
- **cli:** `iot_security` rule — detects hardcoded credentials, cleartext MQTT (port 1883), cleartext HTTP, and insecure BLE configurations (p0, architecture)
8+
- **cli:** `device_lifecycle` rule — checks balanced init/teardown pairs (initState↔dispose, connect↔disconnect, startScan↔stopScan, listen↔cancel, subscribe↔unsubscribe) (p0, architecture)
9+
- **cli:** `mqtt_connection` rule — validates MQTT connect/disconnect and subscribe/unsubscribe pairing, detects hardcoded broker URLs (p0, architecture)
10+
- **cli:** `ble_scanning` rule — checks BLE startScan/stopScan pairing, connect/disconnect, and scan timeout configuration (p1, architecture)
11+
- **cli:** `pubspec_security` rule — analyzes pubspec.yaml for unbounded dependencies, deprecated packages (flutter_blue→flutter_blue_plus), and outdated IoT dependencies (p2, standards)
12+
13+
### UX Improvements
14+
15+
- **cli:** Positional path argument — `flutterguard scan ./my_project` now works without `-p` flag
16+
- **cli:** Project auto-discovery — walks up from CWD to find `flutterguard.yaml`, `pubspec.yaml`, or `lib/`
17+
- **cli:** Config path resolution with 3-tier priority (absolute → CWD-relative → project-relative)
18+
- **cli:** `--no-color` flag to disable ANSI terminal output
19+
- **cli:** Cross-platform compile scripts (`scripts/compile.sh`, `scripts/compile.ps1`)
20+
21+
### CI & Automation
22+
23+
- **ci:** GitHub Actions workflow with ubuntu/macos/windows matrix
24+
- **ci:** Local CI scripts (`scripts/scan_ci.sh`, `scripts/scan_ci.ps1`) with configurable gates
25+
- **docs:** README restructured — user install (pub.dev) / native binary / developer install tiers
26+
- **docs:** README CI integration examples (GitHub Actions, GitLab CI, pre-commit hook, local scripts)
27+
- **docs:** Windows commands use correct backslash paths in install and compile steps
28+
29+
### Total Rules: 11 rule classes, 13 rule IDs
30+
331
## 0.1.0 (2026-05-17)
432

533
### Initial Release — CLI Static Analysis

0 commit comments

Comments
 (0)