Skip to content

changing default severity #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 27 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
# code pal for ABAP

[![abap package version](https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/SAP/code-pal-for-abap/src/y_code_pal_version.intf.abap/abap&label=version)](https://github.com/SAP/code-pal-for-abap/blob/master/changelog.txt)
[![abap package version](https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/SAP/code-pal-for-abap/src/y_code_pal_version.intf.abap/abap&label=version)](changelog.txt)
[![license](https://img.shields.io/github/license/SAP/code-pal-for-abap)](LICENSE)

This tool supports you in writing a clean ABAP code. Clean Code allows you to read your code like well-written prose, it is easily understandable, maintainable, and extensible. In addition, you can write high quality and reliable Unit Tests without hurdles and thereby reduce the total cost of ownership of the software.
Based on the [Clean ABAP](https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md) style guide, this tool contains a set of checks to guarantee the [Clean ABAP](https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md) adherence.
Together, we both support you in writing a clean ABAP code.

Furthermore... It's **free** and **open-source**!
❣️ It's **free** and **open-source**.

It is licensed under the Apache License, Version 2.0 - see [LICENSE](LICENSE).

## News

**:warning: Migration Required :warning:**

From version `v1.01.0` to `v1.02.0` the folder logic was changed, and the abapGit is not able to perform this migration automatically. Therefore, please, follow the step-by-step described in [How To Migrate](pages/how-to-migrate.md)!
## Features

Check the [change log](changelog.txt) for further information.
- Supported by Code Inspector (`SCI` / `SCII`) and ABAP Test Cockpit (ATC) (`SE80` / Eclipse);
- Ignores automatically generated code;
- Supports exemptions;
- Provides a new user-friendly way to create variants ([Profile Management](pages/how-to-configure.md));
- Allows configuration based on:
- Threshold;
- Severity / Priority;
- Validity for productive code, test code, or both;
- Validity for objects created since a specific date;
- Validity period;
- Allow / Deny exemption.

⚠️ Tool is not RFC-Enabled ([#268](https://github.com/SAP/code-pal-for-abap/issues/268)).

## Features
⚠️ Severities set to `Notification` / `Priority 3` by default ([#368](https://github.com/SAP/code-pal-for-abap/issues/368)).

- Checks are ready-to-use;
- Checks can be executed via SUT, SCI, SCII (Code-Inspector) and via ATC (e.g. directly in SE80, Eclipse...);
- Automatic exclusion of code which shall not be checked (e.g. generated code);
- The scope is customizable (filter option on object creation date);
- Thresholds are customizable;
- Message severity is customizable (error, warning, or notification);
- Checking may be activated in productive-code and/or test-code (customizable);
- Findings can be suppressed via Code-Inspector Pragmas;
- Usage of a "Profile Management Tool" (Optional).

The Profile Management Tool, which is an alternative of working with SCI based variant(s), offers among others:
- An user friendly UI;
- A user-based or group-based execution of Checks;
- Creation, assignment and unassignment of Profiles (unassigning a profile will only delete it if no checks are registered to this profile);
- Import/Export a profile among systems (download/upload function – UI button or API Post Service);
- Single-Click registration of all code pal checks at once to a profile (UI button);
- Multiple execution of several profiles at the same time (the sharpest/strongest and time valid configuration/threshold will be taken);
- Delegation principle to facilitate team work (all delegates, for instance: team members, can work with the same profile);

:warning: The checks are not RFC-Enabled due to local dependencies.

## List of Checks
## Set of Checks

- [Check Documentation](docs/check_documentation.md)

Expand All @@ -56,11 +42,14 @@ The Profile Management Tool, which is an alternative of working with SCI based v
- **[Execute](pages/how-to-execute.md)**
- **[Contribute](pages/how-to-contribute.md)**

## Further Reading
## Recommended Readings

- [ABAP Styleguides on Clean Code](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md)
- [Writing Testable Code for ABAP](https://open.sap.com/courses/wtc1/items/2gzG0sRlN1yjkTUREB02L9)
- [ABAP Development for S/4HANA](https://open.sap.com/courses/a4h1)
- [Clean ABAP](https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md)
- [ABAP 7.40 Quick Reference](https://blogs.sap.com/2015/10/25/abap-740-quick-reference/)
- [ABAP Built-in Functions](https://blogs.sap.com/2015/11/30/reminder-abap-built-in-functions/)
- [ABAP - Release-Specific Changes](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abennews.htm)

## Recommended Courses

- [Writing Testable Code for ABAP](https://open.sap.com/courses/wtc1/items/2gzG0sRlN1yjkTUREB02L9)
- [ABAP Development for S/4HANA](https://open.sap.com/courses/a4h1)
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Whenever you upgrade code pal for ABAP, it is highly recommended to execute the

2021-04-** v.1.14.0
------------------
! Notification as Default Severity (#368)
+ Prefer LINE_EXISTS or LINE_INDEX to READ TABLE or LOOP AT (#355)
+ Additional option to disable exceptions/pragmas (#329)
* Diffs for TABL (#359)
Expand Down
106 changes: 62 additions & 44 deletions pages/how-to-configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,104 @@

## How to Configure

**The default customizing (initial values) is not an SAP delivered standard value.**
⚠️This documentation describes how to configure using the `Profile Management Tool` feature only.

The tool is 100% compatible with the SAP CI Framework (Code Inspector). That is, SAP Transactions: SCI and SCII. By means of these transactions, it is possible to create/run/save an inspection using our delivered CHECKS (the checks can be found under the "CODE PAL FOR ABAP" category).
It is also possible to create a CI-Variant and run the selected CHECKS using this variant at any time. This CI-Variant can be also used in SUT (ABAP CHECK REPORT), ATC or even using SAP-Workbench ABAP Editors (e.g.: SE80) or ADT (e.g.: Eclipse) with ATC/CI Integration directly (the CI-Variant will be asked).
💡Alternatively, you can use the SAP Code Inspector variants in the `SCI` transaction.

In summary, it is possible to use our tool directly in SCI/SCII, via ATC Integration, via API Call, via SUT, via CI-Variant or via Profile(s).
But keep in mind, one has to choose betweeen using CI-Variants (Code Inspector Variants) or Using Profile/s (via Transaction: Y_CODE_PAL_PROFILE, delivered along with the toolkit). Both features cannot be used in paralell in the same system for the same user. For more details on using CI-Variant/s and Profile/s, please check the section: [How to Execute](https://github.com/SAP/code-pal-for-abap/blob/master/pages/how-to-execute.md).
Table of Contents:

Furtheremore, every single CHECK can be configurable independenlty.
- [How to Configure](#how-to-configure)
- [Profiles](#1-profiles)
- [Delegates](#2-delegates)
- [Checks](#3-checks)
- [Further Features](#further-features)
- [Import / Export Profile](#import--export-profile)
- [Import via API](#import-via-api)
- [Add / Remove All Checks](#add--remove-all-checks)
- [Add Missing Checks](#add-missing-checks)

By the Check configuration: You can,
💡 The transaction `Y_CODE_PAL_PROFILE` provides access to the `Profile Management Tool`.

* Define check's validity period;
* Restrict to objects created since a specific date;
* Define check's severity;
* Define check's threshold (if applicable);
* Define if it is applicable in productive code (if applicable);
* Define if it is applicable in test code (if applicable);
* Define if it allows exemption via pseudo comments (if applicable).
### Profiles

Check behavior:
> Profiles are similar to Code Inspector Variants.

* If using a CI-Variant, just one variant can be executed per time.
* If using a profile, first, at least one profile should be assigned to your user. Then, all checks assigned to this profle will be executed. But if so, the usage of a CI-variant is no longer possible. The profile overrules a CI-variant! In order to use again a CI-variant, one has to unassign the profile(s) of his/her user;
* If multiple profiles are assigned to your user, all checks assigned to all profiles will be executed and the "strongest" or "sharpest" thresholds will be taken;
* If have no profile assigned to your user, the execution of the checks have to be made live in SCI/SCII or by means of a CI-Variant.
Behavior:

Profile behavior:
- (❗) If you assign a Profile to your user, **it overwrites the Code Inspector variant** (❗);
- If you assign multiple Profiles to your user, the tool will combine them in runtime;
- You can assign someone else Profile to your user;
- The Profile is deleted once it has no check and assigned to nobody.

* If you unassign a profile from your user, it will not delete it from the database. It means, you can reassign it to your user, and all the checks with respective customization will return;
* If you assign the `Y_CHECK_PROFILE_MESSAGE` check to the profile, you will receive an info message every time you execute the global check variant. It means, not all the checks from the variant were executed, but so the ones related to the active profile.
To create or assign it, click on the `+` button, and inform the Profile name:

Threshold behavior:

* If you have multiple profiles, and the same check assigned to two or more profiles, it will use the check with the strongest threshold.

### 1. Create or Assign a Profile
![create a profile](imgs/create-profile.png)

Start transaction `Y_CODE_PAL_PROFILE`, click on the `+` button, and inform the profile name.
### Delegates

![create a profile](imgs/create-profile.png)
> Delegates are the Profile owners who are allowed to configure it;
> Multiple delegates are allowed.

You can assign an already existing profile to your user. It is useful for working on a team based on the same checks.
Behavior:

### 2. Assign Delegates
- If you aren't a Delegate, you won't be able to add / change / remove a Delegate or Check.

Delegates are users which can maintain the checks. As you are creating a new check, you will be added automatically. In case you want to add someone else as an owner, click on the `+` button and inform his/her user name.
To add someone else, click on the `+` button and inform his / her user name:

![assign delegate](imgs/assign-delegate.png)

### 3. Assign Checks
### Checks

Click on the `+` button and assign the checks.
> Checks are the rules based on the [Clean ABAP](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md) style guide.

![assign check](imgs/assign-check.png)
Behavior:

- You can define a Check threshold (if applicable);
- You can define a Check severity / priority (error / priority 1, warning / priority 2, or notification / priority 3)
- You can define a Check filter on productive code, test code, or both (if applicable);
- You can define a Check filter on object creation date;
- You can define a Check validity period;
- You can define if a Check can/cannot be exempt via pseudo-comments (if applicable).
- If you have multiple Profiles assigned to your user, the check with the"strongest" or "sharpest" thresholds will be taken;

To assign them to your Profile, click on the `+` button:

If you want, you can change the default configuration:
![assign check](imgs/assign-check.png)

![customize check](imgs/customize-check.png)

If you do not understand the check meaning, you can check its documentation:
💡 You can use the documentation button to navigate to the Check documentation:

![check documentation](imgs/check-documentation.png)

## How to export and import customization
## Further Features

You can export and import profiles, with respective delegates and checks, using a `JSON` file.
### Import / Export Profile

It is useful when you work with multiple systems, and you want to sync the profiles between them.
You can import and export a Profile with its Delegates and Checks using a `JSON` file, here:

![import and export feature](imgs/import-export-feature.png)

### Import via API

Once you export a profile to a `JSON` file, you can import it using the service created in the [How To Install](how-to-install.md) guide.

To consume the API, you have to `POST` the `JSON` file to the service with the respective authentication you configured to the service (usually basic, user/pass) and with the header `Content-Type` as `application/json` and `action` as `import_profile`.
To consume the API, you have to `POST` the `JSON` file to the service with the respective authentication you configured to the service (usually basic, user/pass) and with the headers `Content-Type` as `application/json` and `action` as `import_profile`.

Possible returns:

- `HTTP 400 - Bad Request` if the file format is not valid, or if the request has a wrong `Content-Type`;
- `HTTP 403 - Forbidden` if the profile already exists in the system and the authentication user is not listed as a delegate;
- `HTTP 500 - Internal Server Error` if the functionality is not working as expected.

### Add / Remove All Checks

You can add all and remove all the Checks from a Profile, here:

![add all and remove all](imgs/)

The API returns an `HTTP 400 - Bad Request` if the file format is not valid, or if the request has a wrong `Content-Type`.
### Add Missing Checks

The API returns an `HTTP 403 - Forbidden` if the profile already exists in the system and the authentication user is not listed as a delegate.
You can add all the missing checks, comparing your Profile and the available Checks, here:

The API returns an `HTTP 500 - Internal Server Error` if the functionality is not working as expected.
![missing checks](imgs/)
3 changes: 1 addition & 2 deletions src/checks/y_check_branch_coverage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
METHOD constructor.
super->constructor( ).

version = '0001'.
version = version + 1.

settings-prio = c_note.
settings-threshold = 70.
settings-is_threshold_reversed = abap_true.
settings-disable_on_prodcode_selection = abap_true.
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_chain_decl_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ CLASS Y_CHECK_CHAIN_DECL_USAGE IMPLEMENTATION.
settings-pseudo_comment = '"#EC CHAIN_DECL_USAG' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }chain-declaration-usage.md|.

set_check_message( 'Do not chain up-front declarations!' ).
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_comment_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ CLASS y_check_comment_usage IMPLEMENTATION.
METHOD constructor.
super->constructor( ).

settings-prio = c_note.
settings-threshold = 10.
settings-documentation = |{ c_docs_path-checks }comment-usage.md|.
settings-ignore_pseudo_comments = abap_true.
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_empty_catches.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ CLASS Y_CHECK_EMPTY_CATCHES IMPLEMENTATION.
settings-pseudo_comment = '"#EC EMPTY_CATCH' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }empty-catch.md|.

set_check_message( 'Empty catch should be removed!' ).
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_empty_procedures.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ CLASS y_check_empty_procedures IMPLEMENTATION.
settings-pseudo_comment = '"#EC EMPTY_PROCEDURE' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }empty-procedure.md|.

set_check_message( 'Empty Procedure should be removed!' ).
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_is_interface_in_class.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ CLASS Y_CHECK_IS_INTERFACE_IN_CLASS IMPLEMENTATION.
settings-pseudo_comment = '"#EC INTF_IN_CLASS' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 1.
settings-prio = c_warning.
settings-apply_on_test_code = abap_false.
settings-documentation = |{ c_docs_path-checks }interface-in-class.md|.

Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_method_return_bool.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ CLASS Y_CHECK_METHOD_RETURN_BOOL IMPLEMENTATION.
settings-pseudo_comment = '"#EC METH_RET_BOOL' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }method-return-bool.md|.

relevant_statement_types = VALUE #( ( scan_struc_stmnt_type-class_definition )
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_prefer_line_exists.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ CLASS y_check_prefer_line_exists IMPLEMENTATION.
settings-pseudo_comment = '"#EC PREF_LINE_EX' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }prefer-line-exists.md|.

set_check_message( 'Prefer LINE_EXISTS or LINE_INDEX to READ TABLE or LOOP AT!' ).
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_prefer_new_to_crt_obj.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CLASS y_check_prefer_new_to_crt_obj IMPLEMENTATION.
settings-pseudo_comment = '"#EC PREF_NEW' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }prefer-new-to-create-object.md|.

set_check_message( 'Prefer NEW to CREATE OBJECT!' ).
Expand Down
3 changes: 1 addition & 2 deletions src/checks/y_check_procedure_coverage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ CLASS y_check_procedure_coverage IMPLEMENTATION.
METHOD constructor.
super->constructor( ).

version = '0001'.
version = version + 1.

settings-prio = c_note.
settings-threshold = 30.
settings-is_threshold_reversed = abap_true.
settings-disable_on_prodcode_selection = abap_true.
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_profile_message.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ CLASS y_check_profile_message IMPLEMENTATION.
settings-apply_on_test_code = abap_true.
settings-apply_on_productive_code = abap_true.
settings-ignore_pseudo_comments = abap_true.
settings-prio = c_note.

set_check_message( '&1 Profile(s) in use: &2.' ).
ENDMETHOD.
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_pseudo_comment_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ CLASS y_check_pseudo_comment_usage IMPLEMENTATION.
settings-apply_on_test_code = abap_true.
settings-apply_on_productive_code = abap_true.
settings-ignore_pseudo_comments = abap_true.
settings-prio = c_note.

relevant_statement_types = VALUE #( BASE relevant_statement_types
( scan_struc_stmnt_type-class_definition )
Expand Down
3 changes: 1 addition & 2 deletions src/checks/y_check_returning_name.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ CLASS y_check_returning_name IMPLEMENTATION.
settings-pseudo_comment = '"#EC RET_NAME' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }returning-name.md|.

version = '001'.
version = version + 1.

relevant_statement_types = VALUE #( ( scan_struc_stmnt_type-class_definition ) ).
relevant_structure_types = VALUE #( ).
Expand Down
1 change: 0 additions & 1 deletion src/checks/y_check_scope_of_variable.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ CLASS y_check_scope_of_variable IMPLEMENTATION.
settings-pseudo_comment = '"#EC SCOPE_OF_VAR' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }scope-of-variable.md|.

set_check_message( 'Variable in use out of its scope!' ).
Expand Down
3 changes: 1 addition & 2 deletions src/checks/y_check_statement_coverage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ CLASS y_check_statement_coverage IMPLEMENTATION.
METHOD constructor.
super->constructor( ).

version = '0001'.
version = version + 1.

settings-prio = c_note.
settings-threshold = 60.
settings-is_threshold_reversed = abap_true.
settings-disable_on_prodcode_selection = abap_true.
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/y_check_base.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ CLASS Y_CHECK_BASE IMPLEMENTATION.
has_documentation = abap_true.

settings-object_created_on = '20190101'.
settings-prio = c_error.
settings-prio = c_note.
settings-threshold = 5.
settings-apply_on_productive_code = abap_true.
settings-apply_on_test_code = abap_true.
Expand Down