abaplint icon indicating copy to clipboard operation
abaplint copied to clipboard

suggestion: exclude non-abap language parts from linter

Open jkadw opened this issue 1 year ago • 16 comments

according to https://syntax.abaplint.org/#/abap/statement/MethodImplementation, a class method can be implemented using another language, e.g. SQLSCRIPT.

As the ABAP linter cannot interpret the code and throws a lot of unnecessary problem messages.

Obviously, it would be great to include these languages in the linter, but that does not seem feasible.

So I' suggest to exclude these code parts from the linter and treat them like some kind of comment.

BR, Jan

jkadw avatar Nov 27 '24 13:11 jkadw

Example:

METHOD session_context BY DATABASE FUNCTION
  FOR HDB LANGUAGE SQLSCRIPT
  OPTIONS READ-ONLY.
    RETURN
       SELECT
      port,
      connection_id,
      key AS key_,
      value,
      section,
      host
    FROM sys.m_session_context;
  endmethod.

jkadw avatar Nov 27 '24 13:11 jkadw

they do identify as NativeSQL, so need to exclude those "statements" from the rules

image

larshp avatar Nov 29 '24 10:11 larshp

@jkadw try again, 2.113.68 published

larshp avatar Nov 29 '24 11:11 larshp

I've tested with standalone 2.113.68. The linter does not exclude the native SQL. You can see it from this slightly enhanced code snippet - it's still throwing an error because of the colon:

CLASS cl_global_func DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES: if_amdp_marker_hdb.
    CLASS-METHODS get_dummy FOR TABLE FUNCTION /test/abc.

ENDCLASS.

CLASS cl_global_func IMPLEMENTATION.
  METHOD get_dummy BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY.
    RETURN
      SELECT dummy FROM sys.dummy WHERE dummy = :var;
  ENDMETHOD.
ENDCLASS.

jkadw avatar Nov 29 '24 13:11 jkadw

thanks, reproduces in the playground,

image

larshp avatar Nov 29 '24 13:11 larshp

You might notice that it does not recognize the end of "Native SQL" correctly: image => Both the "ENDMETHOD." and the "ENDCLASS." are marked as "Native SQL"...

jkadw avatar Nov 29 '24 13:11 jkadw

That last post came from another example where I put double quotes around the schema name, and as they are recognized as the beginning of a comment, the rest doesn't parse well:

REPORT zfoobar.

CLASS lcl_global_func DEFINITION.

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.
    CLASS-METHODS get_dummy FOR TABLE FUNCTION /test/abc.

ENDCLASS.

CLASS lcl_global_func IMPLEMENTATION.
  METHOD get_dummy BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY.
    RETURN
      SELECT dummy FROM "SYS".dummy WHERE dummy = :var;
  ENDMETHOD.
ENDCLASS.

jkadw avatar Nov 29 '24 14:11 jkadw

The reason is that the linter recognizes ";" as the end of the "Native SQL" section, but this is now hidden behind the comment. If you put the ";" on a new line, it at least parses just like the original code.

jkadw avatar Nov 29 '24 14:11 jkadw

@jkadw try again, 2.113.69 published

larshp avatar Dec 02 '24 15:12 larshp

That's better. But the main problem is that it's still parsing the NativeSQL part as though it were ABAP. It tries to evaluate the code, and it will stumble:

  1. Dots "." are used to recognize the end of a command. In SQL it's semicolons ";"
  2. Double quotes are used to recognize the beginning of a line comment. In SQL these are used to escape field names, table names and schema names.

In the end, this leads to the parser to be unable to recognise the "real" end of the NativeSQL part - which is defined by a semicolon, followed by whitespace and then ENDMETHOD. For the playground, you can use the example above with the "SYS" in quotation marks. I think these are the most tricky part for the parser...

jkadw avatar Dec 03 '24 08:12 jkadw

I think its getting there, https://github.com/abaplint/abaplint/pull/3491 will contain a few more fixes

larshp avatar Dec 03 '24 09:12 larshp

the syntax highlighting is not correct, but the linter is happy,

image

larshp avatar Dec 03 '24 14:12 larshp

Looks good, I'll run it on a larger set of code when there's the next update for the vscode extension. Thanks a lot!

jkadw avatar Dec 03 '24 14:12 jkadw

I'll update the vscode extension on Friday(remind me if I forget), I'm travelling and too lazy to setup the authentication on the laptop

alternatively try running it via the command line interface, to check for bugs

larshp avatar Dec 03 '24 14:12 larshp

new vscode extension published, it will show up in a bit

larshp avatar Dec 06 '24 09:12 larshp

@jkadw any luck?

larshp avatar Dec 14 '24 06:12 larshp