Skip to content

Add code formatting and checking targets #62

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

Closed
wants to merge 8 commits into from

Conversation

ikstream
Copy link
Member

@ikstream ikstream commented Apr 7, 2020

Signed-off-by: Stefan Venz [email protected]

Related Issues & PRs

fix #38

Description

  • Add separate Docker for code processing
  • Make targets added
  • Formatting file added

Context

Add Code formatting and static code analysis to improve overall code quality

Testing

  • tested by me
  • Feedback about code structure after formatting

To test this PR:
change to the flavor you want to check e.g. cd lifensensor
make check-code to see static code analysis (nothing wrong with the code so far)
make format-code to apply new formatting style

Documentation

  • Documented both new features

Copy link
Contributor

@nopeslide nopeslide left a comment

Choose a reason for hiding this comment

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

is there a way to check if the source code conforms with the format?
if there is, we should integrate such check as target in the makefile

--rm \
-ti \
$(DOCKER_DEV) \
-v format-home:/home/developer:rw \
Copy link
Contributor

Choose a reason for hiding this comment

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

is a persistent home needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

As we want to change our src files, i think so

Copy link
Contributor

@nopeslide nopeslide Apr 17, 2020

Choose a reason for hiding this comment

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

I don't see anything that is created in the home directory,
therefore I don't see the necessity.
Did I overlook sth?
If not: also remove the clean-format

Copy link
Member Author

Choose a reason for hiding this comment

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

the c and header files are adapted to the style, nothing is created

Copy link
Contributor

Choose a reason for hiding this comment

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

the files this container modifies are mounted and have nothing to do with the container home dir. the other docker containers feature a persistent home for custom configs and caches of the toolchain (i.e. ccache, .gdbinit, ...). this is not needed in this case (why customize the format style?), hence my initial question.

@jhonnyam jhonnyam added this to the Move to Cadus Repo milestone Apr 14, 2020
@jhonnyam
Copy link
Contributor

Would be nice to get some feedback which files would be/where changed.

@nopeslide
Copy link
Contributor

-typedef struct {
-       const char *name;
-       StaticTask_t tcb;
-       TaskHandle_t handle;
-       StackType_t *stack;
-       UBaseType_t priority;
+typedef struct
+{
+    const char * name;
+    StaticTask_t tcb;
+    TaskHandle_t handle;
+    StackType_t *stack;
+    UBaseType_t  priority;
 } _spo2_task;
-typedef struct {
-       UBaseType_t length;
-       UBaseType_t item_size;
-       uint8_t *buffer;
-       StaticQueue_t queue;
-       QueueHandle_t handle;
+typedef struct
+{
+    UBaseType_t   length;
+    UBaseType_t   item_size;
+    uint8_t *     buffer;
+    StaticQueue_t queue;
+    QueueHandle_t handle;
 } _spo2_queue;

the pointer 'star' placement seems to be kind of random.

@nopeslide
Copy link
Contributor

-       spo2_queue->handle = xQueueCreateStatic(
-               spo2_queue->length,
-               spo2_queue->item_size,
-               spo2_queue->buffer,
-               &spo2_queue->queue
-       );
+    spo2_queue->handle =
+        xQueueCreateStatic(spo2_queue->length, spo2_queue->item_size,
+                           spo2_queue->buffer, &spo2_queue->queue);

the current settings seem to stuff as much parameters as possible in one line.
if we break up parameters over multiple lines shouldn't we give each parameter its own line?

@nopeslide
Copy link
Contributor

nopeslide commented Apr 24, 2020

-static gpio_config_t gpio_agc_inc_config = {
-       .pin_bit_mask = SPO2_DCP_INC_PIN,
-       .mode = GPIO_MODE_OUTPUT,
-       .pull_down_en = GPIO_PULLDOWN_ENABLE,
-       .pull_up_en = GPIO_PULLUP_DISABLE,
-       .intr_type = GPIO_PIN_INTR_DISABLE
-};
+static gpio_config_t gpio_agc_inc_config = {.pin_bit_mask = SPO2_DCP_INC_PIN,
+                                            .mode         = GPIO_MODE_OUTPUT,
+                                            .pull_down_en =
+                                                GPIO_PULLDOWN_ENABLE,
+                                            .pull_up_en = GPIO_PULLUP_DISABLE,
+                                            .intr_type = GPIO_PIN_INTR_DISABLE};

multi-line initializations are hard to read when attributes don't get their own line. probably the same issues as with function parameters

@nopeslide
Copy link
Contributor

-       sample->ird_dc = spo2_dc_lowpass(sample->ird_dc,
-                                        (uint16_t)raw_data->ird_dc);
-       sample->red_dc = spo2_dc_lowpass(sample->red_dc,
-                                        (uint16_t)raw_data->red_dc);
+    sample->ird_ac =
+        spo2_ac_lowpass_no_offset(sample->ird_ac, (uint16_t)raw_data->ird_ac);
+    sample->red_ac =
+        spo2_ac_lowpass_no_offset(sample->red_ac, (uint16_t)raw_data->red_ac);

breaking up assignments should be a last resort, would prefer parameter breaking here.

@nopeslide
Copy link
Contributor

-Counter
-counter_reset
-(void);
+Counter counter_reset(void);

Giving function declarations/definitions at least an extra line for the return value seemed like a good idea

@nopeslide
Copy link
Contributor

Would be nice to get some feedback which files would be/where changed.

this would be possible by moving the find instruction inside the container. will look into it

@nopeslide
Copy link
Contributor

nopeslide commented Apr 24, 2020

Would be nice to get some feedback which files would be/where changed.

not absolutely happy with the implementation, but here you go
make check-format lists all files that need formatting and errors if any file needs formatting
make format-code now lists all files it touches (regardless if format was needed)

@nopeslide
Copy link
Contributor

not absolutely happy with the implementation, but here you go
make check-format lists all files that need formatting and errors if any file needs formatting
make format-code now lists all files it touches (regardless if format was needed)

on second thought, I think these targets are unneeded. If you format your code git shows what happened. if you want to check if any code needs formatting, format it and ask git if changes occurred.

@ikstream
Copy link
Member Author

We could run clang-format twice, once with -i and once without. This would show the changes prior applying it and only one command would be needed.

@nopeslide
Copy link
Contributor

nopeslide commented Apr 25, 2020

We could run clang-format twice, once with -i and once without. This would show the changes prior applying it and only one command would be needed.

clang-format dumps the whole file, making it kind of useless output. would prefer something like this
to check format (line diff)

git ls-files -ico -x '**/*.c' -x '**/*.h' | xargs -I % sh -c "clang-format % | git diff --exit-code --no-index --color % -"

to check format (word diff, fancy for these minimal whitespace changes)

git ls-files -ico -x '**/*.c' -x '**/*.h' | xargs -I % sh -c "clang-format % | git -c color.diff.new='normal 22' -c color.diff.old='normal 166' diff --exit-code --no-index --color --word-diff=color --word-diff-regex=. % -"

image

to apply format

git ls-files -ico -x '**/*.c' -x '**/*.h' | xargs -I % clang-format % 

@nopeslide nopeslide mentioned this pull request Apr 26, 2020
9 tasks
@ikstream
Copy link
Member Author

As there seems to be something broken with the config, besides the unfix-able problem, I will close this in favor of #70

@ikstream ikstream closed this Apr 26, 2020
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.

Linter & Auto code formatting
3 participants