File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2422,6 +2422,17 @@ def file_content(self):
24222422 for optimal compatibility.
24232423 """
24242424 from textcode .analysis import numbered_text_lines
2425+ from typecode import get_type
2426+
2427+ # When reading a map file, Textcode only provides the content inside
2428+ # `sourcesContent`, which can be misleading during any kind of review.
2429+ # This workaround ensures that the entire content of map files is displayed.
2430+ file_type = get_type (self .location )
2431+ if file_type .is_js_map :
2432+ with open (self .location , "r" ) as file :
2433+ content = json .load (file )
2434+
2435+ return json .dumps (content , indent = 2 )
24252436
24262437 numbered_lines = numbered_text_lines (self .location )
24272438 numbered_lines = self ._regroup_numbered_lines (numbered_lines )
Original file line number Diff line number Diff line change 2121# Visit https://github.com/nexB/scancode.io for support and download.
2222
2323import io
24+ import json
2425import shutil
2526import sys
2627import tempfile
@@ -1229,6 +1230,18 @@ def test_scanpipe_codebase_resource_model_file_content(self):
12291230 line_count = len (resource .file_content .split ("\n " ))
12301231 self .assertEqual (101 , line_count )
12311232
1233+ def test_scanpipe_codebase_resource_model_file_content_for_map (self ):
1234+ map_file_path = self .data_location / "d2d-javascript/to/main.js.map"
1235+ copy_input (map_file_path , self .project1 .codebase_path )
1236+ resource = self .project1 .codebaseresources .create (path = "main.js.map" )
1237+
1238+ with open (map_file_path , "r" ) as file :
1239+ expected = json .load (file )
1240+
1241+ result = json .loads (resource .file_content )
1242+
1243+ self .assertEqual (expected , result )
1244+
12321245 def test_scanpipe_codebase_resource_model_compliance_alert (self ):
12331246 scanpipe_app .license_policies_index = license_policies_index
12341247 resource = CodebaseResource .objects .create (project = self .project1 , path = "file" )
You can’t perform that action at this time.
0 commit comments