From 98cfee5bf06b45baf60b8311b05edad522eae621 Mon Sep 17 00:00:00 2001 From: Zsolt Ero Date: Wed, 27 Dec 2023 20:41:24 +0100 Subject: [PATCH] lint styles --- scripts/styles/lint_styles/lint_styles.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/styles/lint_styles/lint_styles.py b/scripts/styles/lint_styles/lint_styles.py index 00ea305..ff06ef3 100755 --- a/scripts/styles/lint_styles/lint_styles.py +++ b/scripts/styles/lint_styles/lint_styles.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import json import subprocess from pathlib import Path @@ -11,15 +12,32 @@ import click type=click.Path(exists=True, file_okay=False, resolve_path=True, path_type=Path), ) def cli(styles_folder): + """ + Lints all style JSON files in a folder + First runs prettier with recursive JSON sorting + Then runs gl-style-format + """ + p = subprocess.run(['pnpm', 'bin'], capture_output=True, text=True) node_bin_path = Path(p.stdout.strip()) prettier_config_path = node_bin_path.parent.parent / '.prettierrc.js' - for style_file in styles_folder.rglob('style.json'): + for style_file in styles_folder.rglob('*.json'): + if 'node_modules' in style_file.parts: + continue + + with open(style_file) as fp: + data = json.load(fp) + if 'sources' not in data: + continue + print(f'formatting {style_file}') + subprocess.run( - [node_bin_path / 'prettier', '--config', prettier_config_path, '--write', style_file] + [node_bin_path / 'prettier', '--config', prettier_config_path, '--write', style_file], + capture_output=True, ) + p = subprocess.run( [ node_bin_path / 'gl-style-format',