def update_current_text()

in prebuilt-rules-scripts/generate.py [0:0]


def update_current_text(package_version):
    # Path to latest prebuilt rules JSON file
    rule_dump = str(PREBUILT_RULES.joinpath('orig-rules-json-files', f'{package_version}-prebuilt-rule.json'))
    with open(rule_dump, "r") as source:
        current_text = json.load(source)

    # Path to JSON file generated from existing documentation
    diff_file = str(PREBUILT_RULES.joinpath('diff-files', 'gen-files', f'json-from-docs-{package_version}.json'))
    with open(diff_file, "r") as source:
        updated_text = json.load(source)

    for rule in current_text:
        for new_text in updated_text:
            if rule['name'] == new_text['name']:
                new_text['description'] = rule['description']
                if 'false_positives' in new_text and 'false_positives' in rule:
                    new_text['false_positives'][0] = rule['false_positives'][0]
                if 'note' in new_text:
                    new_text['note'] = rule['note']

    # Output file with updated text from the documentation for previously existing
    # prebuilt rules. New rules are unchanged.

    with open(diff_file, "w") as fp:
        json.dump(current_text, fp, indent=2)

    click.echo(f'saved file: {diff_file}')