Update code standards to prohibit inline imports and ensure all imports are at the top of the file

This commit is contained in:
Jokob @NetAlertX
2026-05-24 02:21:56 +00:00
parent b7cffe8c07
commit b5d280644e
2 changed files with 2 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ description: NetAlertX coding standards and conventions. Use this when writing c
- use environment variables for runtime paths, never hardcode paths or use relative paths
- follow existing code style and structure, and ensure backward compatibility with existing installations when submitting PRs
- all code needs to be scalable to handle large networks with thousands of devices (10k+) without performance degradation
- no inline imports, all imports must be at the top of the file
## File Length

View File

@@ -493,9 +493,8 @@ def _parse_sync_payload(file_path: str) -> list:
Returns the list of device dicts on success, or raises nothing on invalid
input — callers should catch JSONDecodeError / KeyError and skip the file.
"""
import json as _json
with open(file_path, "r") as f:
data = _json.load(f)
data = json.load(f)
return data["data"]
@@ -509,7 +508,6 @@ class TestMode3JsonSkip:
"""
def test_valid_sync_payload_is_parsed(self, tmp_path):
import json
payload = {"data": [{"devMac": "aa:bb:cc:dd:ee:01", "devName": "TestDevice"}]}
f = tmp_path / "last_result.ARPSCAN.decoded.Node1.1.log"
f.write_text(json.dumps(payload))
@@ -526,7 +524,6 @@ class TestMode3JsonSkip:
def test_json_without_data_key_raises_key_error(self, tmp_path):
"""JSON that lacks the 'data' key must raise KeyError so callers can skip it."""
import json
f = tmp_path / "last_result.UNKNOWN.log"
f.write_text(json.dumps({"result": []}))
with pytest.raises(KeyError):