From 46e80cdd3a58228534c0d0e639c51202bc6665eb Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 29 Jul 2020 11:19:40 +0000 Subject: [PATCH] check-node-fixtures: Enforce sorting of events. We want lib/events.js to be somewhat of an executable piece of documentation, and it's really not that hard to keep it sorted going forward. --- tools/check-node-fixtures | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/check-node-fixtures b/tools/check-node-fixtures index cc9d7aaac5..9b999c835b 100755 --- a/tools/check-node-fixtures +++ b/tools/check-node-fixtures @@ -3,7 +3,7 @@ import argparse import os import subprocess import sys -from typing import Any, Callable, Dict, Optional +from typing import Any, Callable, Dict, List, Optional import ujson @@ -87,8 +87,23 @@ def read_fixtures() -> Dict[str, Any]: return ujson.loads(schema) +def verify_fixtures_are_sorted(names: List[str]) -> None: + for i in range(1, len(names)): + if names[i] < names[i - 1]: + raise Exception( + f""" + Please keep your fixtures in order within + your events.js file. The following + key is out of order + + {names[i]} + """ + ) + + def run() -> None: fixtures = read_fixtures() + verify_fixtures_are_sorted(list(fixtures.keys())) for name, event in fixtures.items(): if name in SKIP_LIST: print(f"skip {name}")