# 14_generate_static_descriptions.py import json from pathlib import Path # === Top 30 reguł używanych w v4 top_rules = [ "DL4006", "DL3008", "SC2086", "DL3003", "DL3015", "DL3047", "DL3009", "DL3004", "DL4001", "DL4000", "DL3059", "DL3018", "SC2016", "SC2046", "DL3006", "SC2028", "DL3027", "DL3020", "DL3025", "DL3042", "DL3013", "DL3007", "DL3033", "SC2043", "DL3019", "DL3005", "DL3002", "DL3048", "DL3045", "DL3032" ] # === Opisy reguł — pobrane z dokumentacji hadolinta descriptions = { "DL4006": "Set the SHELL option -o pipefail before using RUN with a pipe.", "DL3008": "Pin versions in apt-get install. Avoid floating dependencies.", "SC2086": "Double quote to prevent globbing and word splitting.", "DL3003": "Use WORKDIR to switch to a directory instead of RUN cd.", "DL3015": "Avoid installing unnecessary packages to keep the image lean.", "DL3047": "Do not use latest tag for the base image.", "DL3009": "Delete the apt-get lists after installing packages.", "DL3004": "Do not use sudo as it leads to unpredictable behavior in containers.", "DL4001": "Either use ADD for local tar archives or COPY for everything else.", "DL4000": "MAINTAINER is deprecated. Use LABEL instead.", "DL3059": "Multiple consecutive RUN instructions should be combined.", "DL3018": "Pin versions in apk add commands.", "SC2016": "Expressions don't expand in single quotes. Use double quotes.", "SC2046": "Quote this to prevent word splitting.", "DL3006": "Always tag the version of the base image explicitly.", "SC2028": "Quotes in echo may not behave as expected. Use printf instead.", "DL3027": "Use only an allowed registry in the FROM image.", "DL3020": "Use COPY instead of ADD for files and folders.", "DL3025": "Use COPY instead of ADD unless you need ADD's features.", "DL3042": "Avoid cache busting by rearranging ADD/RUN order properly.", "DL3013": "Avoid installing unnecessary packages in your container.", "DL3007": "Using yum install is discouraged. Prefer apk or apt.", "DL3033": "Specify version with pip install to ensure reproducibility.", "SC2043": "Use 'case' instead of many 'if' statements for simplicity.", "DL3019": "Do not use ADD with URLs; use curl or wget instead.", "DL3005": "Do not use apt-get upgrade or dist-upgrade.", "DL3002": "Last USER should not be root.", "DL3048": "Avoid using the ADD instruction; prefer COPY.", "DL3045": "Do not specify the same label multiple times.", "DL3032": "Do not use deprecated ADD syntax; use COPY." } # === Tworzenie struktury JSON output_data = {} for rule in top_rules: output_data[rule] = { "code": rule, "title": descriptions.get(rule, "No title available."), "description": descriptions.get(rule, "No description available."), "documentation": "" } # === Zapis output_path = Path("data/metadata/rules_descriptions_en.json") output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_path, "w", encoding="utf-8") as f: json.dump(output_data, f, indent=2) print(f"✅ Zapisano {len(output_data)} reguł do {output_path}")