Accessing Function code Linting

  1. To access the Function code Linting open the following URL:
  1. https://tenant/admin#/openwhisk
  1. After opening the console, you can find the list of Openwhisk actions as shown in the following figure:

https://lh4.googleusercontent.com/zCxyW9BLxMRhsuotWeO7p-Gn9fA68pVEKSH_MDnctIrZH2uV9ZZlEgYPDHJyiLa02dIPNhgH3LFpPrP8QvY7v5Y8uEeBY1XzK5aP_dSt8VTlnVkxBDo26KEA3njclyh4YFNmaWuPL816nuBbbKoRqFw

Figure 452 - Openwhisk Console

  1. To create a new action, click on Create Action button on the top right corner of the screen and to edit an existing action click on the edit icon corresponding to the action that you wish to modify.
Figure 1. Figure 453 - Edit Action
https://lh4.googleusercontent.com/9yQE5KD2c18OcqtvcAWbSJx5KcrylKRlxKfmhvi_y7c_aaT1OTNz6F-Z751InQdWGqrBIPiZcRiNACTJQfo7A4j7Pmpav0-ZkrmKYjY75miYKc5kz2RYX1lfsANjGFtBSCImgCfGoaiWE9mFDVLICTQ
  1. The following page appears:
Figure 2. Figure 454 - Code editor
https://lh4.googleusercontent.com/AVSFeccGzHwJ430NhJ4FseOxUuOJKKuHMNdOdgfHbvF94-sqd3n62QHqP6SRNKydCj2wTQhYipgUACBEK4E2Rg1LLrAsBhchIGqmSTbajVU-5MCq9kTNmSqMxHwf_rQehQgtY0qHHh5aEbqrGvPQnhs
  1. The gutter on the left side of the editor shows the user, the list of warnings and errors that are present in the code.
Figure 3. Figure 455 - Gutter in Code editor
https://lh4.googleusercontent.com/J5mKnTgOxeDhBEOsTemTRnUzeWLUAaIwo6756aHtAqxZQKz5bHNC-tD1vOEBwOIrVbG8rHvGs4nOloqauREYxOnsnGVsHG1kTzj1gdgDR1tQi2LwP9FFlI6RB3PGDW20AsC0kCsg7NPuRK6NfSDhTRc
  1. These errors and warnings that are present on the gutter can be viewed by clicking on the warnings and error icons respectively.
Figure 4. Figure 456 - Warnings and Error icons
https://lh3.googleusercontent.com/-o0nFNh-vyk28ogzWgnZGzabLL4qLFZmzhY2c3vjEBR2JgxfCvOLfOFpP2j_hBqUqR12iEhODy4CJVLXs5PRT56daoqyo5pUzZSAQFCFdjELkpqHkUA8z0T7t0qG9dncoUy6SPn2z_2vliml0yomHM8

The rules that are set in BigFix AEX for errors and warnings are listed below.

These are errors and warnings that the user can see in the editor gutter. These are the validations for any stylistic errors or other vulnerabilities. Users can still save Openwhisk actions even if there are any errors or warnings.

Linting is done to ensure that the user can review the code and refactor it so as to make it neat, scalable, efficient, and optimal.

There are errors, but if they are not syntactical, the user can still save the code.

Table 1. Table 5 - Set rules in BigFix AEX for errors and warnings
S.no Rule Type
1. Indentation of 4 spaces Warning
2. Line-break style unix, such as LF and not CRLF Warning
3. Single quotes in strings Warning
4. id length should be min of 4 (except I,j,k) Error
5. If variable is not reinitialized, then use const Error
6. var data-type not accepted Error
7. CamelCase in variable and method names Error
8. Max lines in the code is 650 (except the comments and empty lines) Warning
9. Max length of a line is 125 Warning
10. Max lines per function is 30 Warning
11. No trailing space Warning
12. Spacing between operators and operands Warning
13. Spacing in unary operator Error
14. Spacing in key-value pairs (before colon false else true) Warning
15. Missing space between async function, while as for named and anonymous no space is required Error

Apart from these, there are rules that are pre-defined from the editor and their errors and warnings can also be seen.

Rule 1: Indentation of 4 spaces

  • Indentation should be four spaces; otherwise, the below warning message is shown as "expected Indentation of 4 spaces but found 0" as shown in the following figure:
Figure 5. Figure 457 - Indentation Warning Message
https://lh5.googleusercontent.com/VIPkBaMjvpLK53I0XeuuWU8uGsv4uVu2UEHVYUMQ_qMRrLz1SznP9Y7QAl1ulodmg-C3QpTINQSes1T1V-kuoqcAFoKfOo9XgBH3d6ZtOoHMoiwyb7w5CtE9QqNRyzUBsgjhiV9UEnGT7YvXTE7DLV0

Rule 2: Line-break style Unix i.e., LF and not CRLF

  • There are two kinds of line break systems that is LF and CRLF, the code editor that is being used in openwhisk console uses the LF line break style so if the format is not of LF, the below warning message appears as “Expected linebreaks to be ‘LF' but found 'CRLF'”:
Figure 6. Figure 458 - Line Break Error

Rule 3: Single quotes in strings

  • String must be in single quote, otherwise the below warning message appears as “Strings must use single quote”:
Figure 7. Figure 459 - Single Quote Warning Message
https://lh4.googleusercontent.com/urfb_LReVAQzSm5_b5LDcgpyJjY_NjAlq933TfwNGhSktIgKnUDfUBFVppeA54sqgQq02BGu22xXRK5xuHOuU52MbOR9EL4nGrCHbmzTQqjqXaD6q0ubrT3DzQszvDB0bskJ6Le2tynmbXvdoTKy-oU

Rule 4: id length should be min of 4 (except i,j,k)

  • While we declare a variable or method, the id length should be min of 4 letters (except i,j,k) otherwise the below error message is shown as “Identifier name 'ABC' is too short (<4)”:
Figure 8. Figure 460 - ID Length Error Message
https://lh3.googleusercontent.com/Y8AYdWdWoVswX-d489UhALRHKvdlsP0FyJkO9TuSCSmCld3MUacEMZVwvS1MWNiO7VL1EBZvwdGuKnD9Mbox-LSy6-BSPahebLMahMTSLbudV5BPo4zVRDmT9Vo-HD_BpzZkukycJ4XBPEAkorx9xOs

Rule 5: If variable is not reinitialized, then use const.

  • If the variable is not reinitialized, then the user is prompted to declare a const variable, instead let or var variable otherwise the below error message appears:
Figure 9. Figure 461 - Variable Error Message
https://lh6.googleusercontent.com/V1e_nxxGD8-J1CKKGRgkSwt4vsUTreoVxJOBr1mTi07VwYzSJDG4Jx1aVHgJU6dWFCwilI7Zy_VbbcPjCIlK2Vgg2Ehkjb6ZTQAoiFEoKHj5mbgr03jvt_U-GZhCzCMcHEQ1aqDVmejbFE7yT_JFVdM

Rule 6: var datatype not accepted

  • When user declares the data type, he should use let or const data type. var data type is not accepted. if var datatype is declared, the below error message appears as “Unexpected var, use let or const instead”:
Figure 10. Figure 462 - Data Type Error Message
https://lh6.googleusercontent.com/qAzMmsBfRAmVUyHeLVOCm6d-35HwV5sE_l4hKmH77wjbDoV2GwRGj725Tol_TKaTA9Ec56The3Phqm6lH9ks_LhY6Q0ulOA4XCOrDVDdmXMKbWGdSfbnD_yqXIYtkmeGxoCFq-IQSHrySDiN3EJEq2g

Rule 7: Camel-case in variable and method names

  • When declaring a variable or method, camel-case should be followed, or else the below error message appears:
Figure 11. Figure 463 - Camel-case error message
https://lh4.googleusercontent.com/TIMKdSL005mxsoXT26viuNcA2VCqcAVMAVvRIM4wMtlUk9LB7pCbj6cuf8ENXBs0OPQvTeXVWmybiEa3GIznRY7oaATr9oogkaCcDXsEthbQuj0Hdzp7l2H59uro_bjkBK-AP8g1KIYrinVwzxmMxxE

Rule 8: Max lines in the code is 650 (except the comments and empty lines)

  • The code length should be of maximum 650 (except the comments and empty lines) if it exceeds more than 650 lines the below warning message is seen in the gutter “File has too many lines (651). Maximum allowed is 650”:
Figure 12. Figure 464 - Warning message
https://lh4.googleusercontent.com/EOn4BhE8Ls1m3o2iLPGLVt57APVVslNeoEEdJ2GZNa7o_g0llBP_fCpstSKtEjU3xOyJ-vp-Owcqy1AYdYbJ4hgSceUYvZ5eEBIy9vLN5aW8dz4PytUKi32O6Afhf1O8we_AsAW9NjpcRbtx27tSMsI

Rule 9: Max length of a line is 125.

  • The maximum length of a line should be 125, if this line is exceeded, the below warning message is shown “This line has a length of 126. Maximum allowed is 125”:
Figure 13. Figure 465 - Warning message
https://lh3.googleusercontent.com/-D8zpF2KUQTymoiJKt1O1RpHlTcuSOklmbydsBwASqRl5250fnzXoYWgiCbt94bj8ct6WYeuEDrVlKDwyhLwpz-E1qd0IWsOQRQ4Wvj_rSJVk8aTalrsYTnT01ZRKnOdH82N2dQE0Vx3SGoIhM-kpJs

Rule 10: Max lines per function is 30.

  • The maximum lines per function should be 30, if it is exceeded more than 30 lines in a function, the below warning message appears as “Function ‘main’ has too many lines (31). Maximum allowed is 30”:
Figure 14. Figure 466 - Warning message
https://lh5.googleusercontent.com/Q4T-VdWeeK1oAwxQZcf7mBR1lZUGK78YYY3AYuz-9DWnBfWDFdWjMpr4-lvHugK7X7_crIF3GYkyBVmQdOC-DOK_efHMDPLpi_6_mb4C6l8FgdbBTU1airU-YM3D_h4pXuwWssxJjLIw1Qbi9IFq7bg

Rule 11: No trailing space

  • While writing code, if user uses the unnecessary spaces, the below warning message is shown as “Trailing spaces not allowed”:
Figure 15. Figure 467 - No trailing space warning message
https://lh6.googleusercontent.com/OVXo4wfGEGlFy9tzcmXFMHTRaiScV1s7jW5qhuGy5zQta31IpblzGzT2_vN8RWRjoM-OrqHj997H6nFXqNZjv2VrN9Qk8g6EP4NL8pDmqYIcLik9cwUjSQDqK6ljRho6MzQKZ2achMKM37MOLNhh-uM

Rule 12: Spacing between operators and operands

  • There should be a space between operators and operands otherwise the below warning message is shown as “Operator ‘=’ must be spaced.”:
Figure 16. Figure 468 - Operator Must Be Spaced Warning Message
https://lh4.googleusercontent.com/_17cVvckC3VqkuKZBfDN61t8QMYK8M27o0-BX9bTQBh2I-6oVb4POs_VIeFomuU8h-daiz8KS2capRHcJNDB8hf35pc_aqSJQueiYV_Dmj_9FhZ4XeAQBMNWgHJH5ZNuFGa5EoYNa2vsnB7uXC4HmCw

Rule 13: Spacing in unary operator.

  • There should be no space between unary operator, otherwise the error message is shown as “Unexpected space after unary operator”:
Figure 17. Figure 469 - Unexpected Space After Unary Operator Error Message
https://lh4.googleusercontent.com/2g6z-DFCSzuaTtQX8Tt4XGeSRXyJ4Tj_9OJGsZ8z555P1_dgJYZhUxa3uq6-3ZLEsBasNc8v2N0H7foGFQMrlXJK-6yo7yspeu0KI5ks3VaPUi8ZtBdrhyX2kvBu35L83_J55ZpjSLrZ1xMqNC3ekt8

Rule 14: Spacing in key-value pairs (before colon false else true)

  • In Key value pair, after key name before colon, if user gives space and space before key name, the below warning message is shown as “Extra space after key makes”:
Figure 18. Figure 470 - Extra Space After Key Makes Warning Message

Rule 15: Missing space between async function, while as for named and anonymous function, no space is required.

  • Space should not be used between async function, otherwise the below Error message can be seen as in below figure:
Figure 19. Figure 471 - Missing Space Before Function Parentheses Error Message
https://lh3.googleusercontent.com/9rwkddoo_9Aw_VbzumXuMcQnDeWJtvK_tXPZJlbkXGyXUavI050SavVTrjxvOmN4knS_TDB5rfxvZ-F_DjvDLv1JwuZLGt_aRcKCddIYHE_I0dkiUDTC1hdKS7DqKgdpAo3IR3OnXZlvddnzg1eJKo8