1
1
import argparse
2
2
import sys
3
3
from dataclasses import asdict , dataclass
4
- from typing import Any , Generator , Iterator , Mapping , Optional , TextIO , TypedDict , Union , cast
4
+ from typing import Any , Generator , Iterator , List , Mapping , Optional , TextIO , TypedDict , Union , cast
5
5
from pathlib import Path
6
6
import jsonschema
7
7
import json
@@ -74,14 +74,15 @@ def generate_json_patches_for_recategorization(recategorization: GuidelineRecate
74
74
"""
75
75
Compute as set of JSON patches to apply the recategorization to the subject Sarif file.
76
76
"""
77
- def to_jsonpatch (pointer :jsonpointer .JsonPointer ):
78
- standard = cast (str , pointer .get (subject )).split ('/' )[1 ]
79
- return JsonPatch (
77
+ def to_jsonpatch (pointer :jsonpointer .JsonPointer ) -> Iterator [JsonPatch ]:
78
+ obligation_tag = cast (str , pointer .get (subject ))
79
+ _ , standard , _ , category = obligation_tag .split ('/' )
80
+ yield JsonPatch (
80
81
op = 'replace' ,
81
82
path = pointer .path ,
82
- value = f'external/{ standard } /obligation/{ recategorization .category } '
83
- )
84
- return map ( to_jsonpatch , json_path_to_pointer (recategorization_to_json_path_for_category (recategorization ), subject ))
83
+ value = f'external/{ standard } /obligation/{ recategorization .category } ' )
84
+ yield JsonPatch ( op = 'add' , path = pointer . path , value = f'external/ { standard } /original-obligation/ { category } ' )
85
+ return ( patch for pointer in json_path_to_pointer (recategorization_to_json_path_for_category (recategorization ), subject ) for patch in to_jsonpatch ( pointer ))
85
86
86
87
87
88
def get_guideline_recategorizations (coding_standards_config : Mapping [str , Any ]) -> Generator [GuidelineRecategorization , None , None ]:
0 commit comments