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

Fiqare secmotic rules #411

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

Conversation

fiqare-secmotic
Copy link

This pull request contains improvements made by the Secmotic team for iotagent-ul. These improvements are part of the fiQare project, which is based on ISO 25010 to improve software quality. More info: https://fiqare.eu/

There are two rules:

Rule 1: Unused function parameters should be removed, based on:

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed

Rule 2: if.. else if constructs should end with else clauses, based on:

  • MISRA C:2004, 14.10 - All if...else if constructs shall be terminated with an else clause.
  • MISRA C++:2008, 6-4-2 - All if...else if constructs shall be terminated with an else clause.
  • MISRA C:2012, 15.7 - All if...else if constructs shall be terminated with an else statement
  • CERT, MSC01-C. - Strive for logical completeness
  • CERT, MSC57-J. - Strive for logical completeness

All test in Travis has been passed successfully and the coverage in Coveralls remains the same.

@@ -44,7 +44,7 @@ var http = require('http'),
},
transport = 'HTTP';

function handleError(error, req, res, next) {
function handleError(error, req, res) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if the fix for this is removing next from the signature of the function of this change is actually raising another kind of bug in the function: it should call next() upon completion but it is not doing it.

A similar case would be the one with returnCommands() modification, some lines below.

@AlvaroVega what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I guess express is expecting always a function with req, res, next) args

Copy link
Member

Choose a reason for hiding this comment

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

I have been discussing this case with @AlvaroVega and the solution here shouldn't be to remove "next" for the parametrs, but adding the next(); call to the end of the function, i.e. just after L59.

Copy link
Author

Choose a reason for hiding this comment

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

fixed in a2e11f6

lib/iotaUtils.js Outdated Show resolved Hide resolved
@fgalan fgalan mentioned this pull request Dec 17, 2019
@fgalan fgalan mentioned this pull request Jan 8, 2020
Co-Authored-By: Fermín Galán Márquez <fgalan@users.noreply.github.com>
lib/iotaUtils.js Outdated
@@ -155,7 +155,7 @@ function mergeDeviceWithConfiguration(deviceData, configuration, callback) {
} else if (!deviceData[fields[i]] && (!configuration || !configuration[confField])) {
deviceData[fields[i]] = defaults[i];
} else {
config.getLogger().error(context, 'There is no possible merge');
config.getLogger().debug(context, 'at field %d configuration merging logic did not merge anything', i);
Copy link
Member

Choose a reason for hiding this comment

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

Is "%d" the right formatter for integer in JavaScript?

Copy link
Member

Choose a reason for hiding this comment

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

Changing log from error to debug level, sure?

Copy link
Member

Choose a reason for hiding this comment

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

Probably you are seeing a partical commit... if you clear filters in diff tab the actual change shown is the addition of the a debug line. I mean, there wasn't any error() logging here before.

Copy link
Member

@AlvaroVega AlvaroVega Jan 13, 2020

Choose a reason for hiding this comment

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

you're right

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed "%d" is correct. Thus NTC (I guess)

Copy link
Author

Choose a reason for hiding this comment

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

fixed in a2e11f6

@@ -159,7 +159,7 @@ function returnCommands(req, res, next) {
updates = commandList.map(createCommandUpdate);
cleanCommands = commandList.map(cleanCommand);

async.parallel(updates.concat(cleanCommands), function(error, results) {
Copy link
Member

Choose a reason for hiding this comment

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

results seems a reminder of a log that was necessary.

Copy link
Member

Choose a reason for hiding this comment

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

In that case the fix should be to use results to provide a proper log messages based on it.

Copy link
Author

Choose a reason for hiding this comment

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

In this case we continue to rely on ISO 25010 to improve software quality. Mainly:

Rule 1: Unused function parameters should be removed, based on:

MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
MISRA C:2012, 2.7 - There should be no unused parameters in functions
CERT, MSC12-C. - Detect and remove code that has no effect or is never executed

So, this is fixed in a2e11f6

Copy link
Member

Choose a reason for hiding this comment

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

We agree that unused parameters should be avoided. However, we are proposing a different solution for this case: instead of removing the unused results parameter, let's add a log trace that uses results to print some useful information in the logs for the user.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

Based on the maintainability axis of ISO 25010, I think it is counterproductive to add code to the function to use a variable that is currently deprecated, which makes it less readable. Therefore, before adding code that will not be functional, I prefer to leave the function as it was, with the variable "results".

Copy link
Author

Choose a reason for hiding this comment

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

fixed in 9dfbdcb

@@ -135,7 +135,7 @@ function checkMandatoryParams(queryPayload) {
* This middleware checks whether there is any polling command pending to be sent to the device. If there is some,
* add the command information to the return payload. Otherwise it returns an empty payload.
*/
function returnCommands(req, res, next) {
function returnCommands(req, res) {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly to handleError() the solution should be to call next(); in the proper place (I guess that just after L205, but not fully sure).

Copy link
Author

Choose a reason for hiding this comment

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

fixed in a2e11f6

@@ -115,7 +115,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
* @param {Number} index Index of the group in the array.
* @return {Array} Updated array of functions.
*/
function processMeasureGroup(device, apikey, previous, current, index) {
function processMeasureGroup(device, apikey, previous, current) {
Copy link
Member

Choose a reason for hiding this comment

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

JavaDoc entry for index (L115) should be removed also.

Copy link
Author

Choose a reason for hiding this comment

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

fixed in 662a458

lib/iotaUtils.js Outdated
} else {
config
.getLogger()
.debug(context, 'at field "' + fields[i] + '" configuration merging logic did not merge anything', i);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.debug(context, 'at field "' + fields[i] + '" configuration merging logic did not merge anything', i);
.debug(context, 'at field "' + fields[i] + '" configuration merging logic did not merge anything');

not fully sure but I'd say that if you don't use formating (such as "%d") then the i variable should not be included at the end of the statement.

Copy link
Author

Choose a reason for hiding this comment

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

fixed in 9dfbdcb

@@ -57,6 +57,7 @@ function handleError(error, req, res, next) {
name: error.name,
Copy link
Member

@fgalan fgalan Jan 21, 2020

Choose a reason for hiding this comment

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

I think the PR is almost ready (good work! :). However, you should include an entry in the CHANGES_NEXT_RELEASE file in describing the changes. Maybe something like the following:

- Hardening: software quality improvement based on ISO25010 recommendations

Copy link
Author

Choose a reason for hiding this comment

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

fixed in 484e833

Copy link
Member

@AlvaroVega AlvaroVega left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

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

LGTM (at commit 484e833). Thanks for your contribution!

In order to keep the homogeneity along with all the IOTA suite, we will wait to merge this PR until a similar PR with software improvements based on ISO25010 recommendations could be done in the following repositories:

@fgalan
Copy link
Member

fgalan commented Jul 3, 2020

After merging PR #415 I'm afraid some merging conflict have arisen in this PR. Fortunatelly, the solution seems easy, detailed by @jason-fox at telefonicaid/iotagent-manager#171 (comment)

all you need to do is merge and accept yours

Thereafter

npm i
npm run lint

And fix any es6 errors raised. (Alternatively you could disable the failed rule for your files if necessary)

Sorry for the incoveniences

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