Skip to content
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

Bugfixes and new rules from collaboration EUMETSAT-AQCLab #230

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

jverdugo-aqclab
Copy link

@jverdugo-aqclab jverdugo-aqclab commented Dec 21, 2022

Proposed changes

Fixing of parsing errors detected in three rules: COM.Inst.Brace, COM.PROJECT.Header, COM.NAME.Homonymy

Implementation of 8 new rules (from EUMETSAT coding standard, but useful in other contexts) to check:

  • size of files (lines of code) againts a threshold: The rule checks if a program or module exceeds a maximum number of lines of code (excluding comments and blank lines) set at 1000 by default.
  • size of procedures (lines of code) againts a threshold: The rule checks if a procedure (function or subroutine) exceeds a maximum number of lines of code (excluding comments and blank lines) set at 150 by default.
  • percentage of comments againts a threshold: The rule checks if a program or module has at least a certain percentage of comments set at 30% by default.
  • cyclomatic complexity of procedures againts a threshold: The rule checks if a procedure (function or subroutine) exceeds a maximum number of cyclomatic complexity (simplified, not taking goto statements into account) set at 15 by default.
  • declaration of only one program/module per file: Each file should only contain one program or module. The rule checks if there are several of them in one file.
  • number of arguments for procedures againts a threshold: The rule checks if a procedure (function or subroutine) has more than a maximum number of arguments or parameters, set at 7 by default.
  • documentation of variables: The rule checks that the declaration of variables and types is preceded by a comment line that describes its use.
  • content in headers: The rule checks that headers for modules or programs have, at least, the following components: Unique identification of the program or module, name of the file, author’s name, statement of the Copyright ownership of the code, description of the nature of functions/subroutines in the file

Types of changes

What types of changes does your code introduce to i-Code?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Issues closed by changes

Checklist

  • I have read the CONTRIBUTING doc
  • I agree with the CODE OF CONDUCT
  • Lint and unit tests pass locally with my changes
  • SonarCloud and GitHub Actions tests pass with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

The changes implemented were sponsored and agreed with EUMETSAT, based on their needs, but both EUMETSAT and AQCLab consider that these may be useful to other parties, and for that may be considered to be included in the offical development of i-Code.

jverdugo-aqclab and others added 11 commits December 21, 2022 13:00
…ndexOutOfBoundsException) were produced when analyzed files contained declaration of functions or subroutines with modifiers Recursive, Elemental or Pure
…a file only contains comments, no source code. Also a JFlexException was thrown in the case of a file without code nor comments. The throw for this Exception has been removed to avoid parsing errors in the results.
…n analyzing files that included sentences like "PROCEDURE(proc_interface), POINTER :: proc"
…ld of LOC (set at 1000). Only lines of code are taken into account, comments and blank lines are ignored.
…eshold of LOC (set at 150). Only lines of code are taken into account, comments and blank lines are ignored.
Rule to check the maximum number of arguments in each procedure, which must be at most 7.
Rule to check the maximum value of the cyclomatic complexity in each function, which at most must be 15.
Rule to check that only one module or program is declared in each file.
Rule to check that in each file there are at least 30% of lines of comments with respect to the total number of lines.
@jverdugo-aqclab jverdugo-aqclab changed the title Eumetsat aqc lab 2 Bugfixes and new rules from collaboration EUMETSAT-AQCLab Dec 22, 2022
Copy link
Contributor

@diegorodriguez31 diegorodriguez31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you provide me some Fortran files that break the new rules and the fixed rules, so that I can test it?
The merge request will be approved after the new rules tested and when my suggestions will be taken into account or discussed with me to clarify.

<languageId>fr.cnes.icode.fortran90</languageId>
</check>
<check>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it if you decide to enhance the existing header rule

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending of confirmation on comment #230 (comment)

<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.F77FILEHeader</class>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it if you decide to enhance the existing header rule

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending of confirmation on comment #230 (comment)

@@ -109,47 +109,43 @@ STRING = \'[^\']*\' | \"[^\"]*\"

private void raiseErrors() throws JFlexException {
LOGGER.finest("begin method raiseErrors");
if(linesType.isEmpty()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You decided to remove the fact that we raise an error if file is blank.
Can it be possible to really have blank files in FORTRAN?
If yes, then I will join your choice.
If no, we should implement a rule checking if there is empty files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising an error in this specific rule and not in others seemed arbitrary, since checking empty files is not the purpose of this rule.
Having a blank file is possible (we found it in one of the projects we evaluated at EUMETSAT). Even though it doesn't present a great problem, such a file would be useless and should be avoided, the same way unused variables should be avoided. So, for this purpose we agree on having a specific rule that checks this situation.
As an alternative, we would favor simply ignoring blank files, but not raise an error in an unrelated rule such as COMPROJECTHeader.

@@ -104,90 +104,86 @@ STRING = \'[^\']*\' | \"[^\"]*\"
}

private void raiseErrors() throws JFlexException {
if(this.linesType.isEmpty()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than for fortran77 COMPROJECTHeader

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising an error in this specific rule and not in others seemed arbitrary, since checking empty files is not the purpose of this rule.
Having a blank file is possible (we found it in one of the projects we evaluated at EUMETSAT). Even though it doesn't present a great problem, such a file would be useless and should be avoided, the same way unused variables should be avoided. So, for this purpose we agree on having a specific rule that checks this situation.
As an alternative, we would favor simply ignoring blank files, but not raise an error in an unrelated rule such as COMPROJECTHeader.

Copy link
Contributor

@diegorodriguez31 diegorodriguez31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change these values too to respect RNC

jverdugo-aqclab and others added 14 commits June 2, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants