Skip to content

Commit

Permalink
Fix parsing json with comments
Browse files Browse the repository at this point in the history
Handles basic case when comments are at end of a line
  • Loading branch information
mbtools committed Dec 19, 2024
1 parent 102f535 commit 29f6475
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/zcl_abaplint_abapgit_ext_issue.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ CLASS zcl_abaplint_abapgit_ext_issue IMPLEMENTATION.
METHOD _read_class_line.

DATA:
lx_error TYPE REF TO cx_root,
lo_instance TYPE REF TO object, "cl_oo_factory,
lo_source TYPE REF TO object, "cl_oo_clif_source,
lo_scan TYPE REF TO object, "cl_oo_source_scanner
Expand Down
28 changes: 15 additions & 13 deletions src/zcl_abaplint_abapgit_ext_rules.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ CLASS zcl_abaplint_abapgit_ext_rules DEFINITION

CONSTANTS:
c_abaplint_host TYPE string VALUE 'https://schema.abaplint.org/',
c_abaplint_schema TYPE string VALUE 'schema.json',
c_abaplint_defaults TYPE string VALUE 'default.json'.

DATA:
Expand Down Expand Up @@ -140,7 +139,6 @@ CLASS zcl_abaplint_abapgit_ext_rules DEFINITION
VALUE(result) TYPE REF TO zif_abapgit_html

Check failure on line 139 in src/zcl_abaplint_abapgit_ext_rules.clas.abap

View check run for this annotation

abaplint / abaplint

Method parameter name does not match pattern ^R._.+$: result

https://rules.abaplint.org/method_parameter_names
RAISING
zcx_abapgit_exception.

ENDCLASS.


Expand Down Expand Up @@ -220,10 +218,10 @@ CLASS zcl_abaplint_abapgit_ext_rules IMPLEMENTATION.
METHOD get_repo_rules.

DATA:
lx_error TYPE REF TO zcx_abapgit_ajson_error,
lv_filename TYPE string,
lt_files TYPE zif_abapgit_git_definitions=>ty_files_tt,
ls_file LIKE LINE OF lt_files,
lv_warning TYPE abap_bool,
lv_json TYPE string,
lt_json TYPE string_table.

Expand Down Expand Up @@ -255,16 +253,20 @@ CLASS zcl_abaplint_abapgit_ext_rules IMPLEMENTATION.
mv_repo_filename = lv_filename.
lv_json = zcl_abapgit_convert=>xstring_to_string_utf8( ls_file-data ).

" TODO: Workaround until ajson parses JSON with comments
IF lv_filename CS '.jsonc'.
SPLIT lv_json AT cl_abap_char_utilities=>newline INTO TABLE lt_json.
LOOP AT lt_json INTO lv_json.
FIND REGEX '(.*)(\/\/[\w\d\s]*)$' IN lv_json IGNORING CASE SUBMATCHES lv_json.
IF sy-subrc = 0.
MODIFY lt_json FROM lv_json.
ENDIF.
ENDLOOP.
CONCATENATE LINES OF lt_json INTO lv_json SEPARATED BY cl_abap_char_utilities=>newline.
" TODO: Workaround until ajson parses JSON5 with comments
" Removes end of line // comments
SPLIT lv_json AT cl_abap_char_utilities=>newline INTO TABLE lt_json.
LOOP AT lt_json INTO lv_json.
FIND REGEX '(.*)\/\/[^"]*$' IN lv_json IGNORING CASE SUBMATCHES lv_json.
IF sy-subrc = 0.
lv_warning = abap_true.
MODIFY lt_json FROM lv_json.

Check failure on line 263 in src/zcl_abaplint_abapgit_ext_rules.clas.abap

View check run for this annotation

abaplint / abaplint

Check sy-subrc

https://rules.abaplint.org/check_subrc

Check failure on line 263 in src/zcl_abaplint_abapgit_ext_rules.clas.abap

View check run for this annotation

abaplint / abaplint

Database operation in loop

https://rules.abaplint.org/db_operation_in_loop
ENDIF.
ENDLOOP.
CONCATENATE LINES OF lt_json INTO lv_json SEPARATED BY cl_abap_char_utilities=>newline.

IF lv_warning = abap_true.
MESSAGE 'Rules contain comments which are not shown here!' TYPE 'S' DISPLAY LIKE 'W'.
ENDIF.

mi_repo_rules = zcl_abapgit_ajson=>parse( lv_json ).
Expand Down

0 comments on commit 29f6475

Please sign in to comment.