Use pre-commit and editorconfig (#753)

* Add editorconfig and pre-commit config

Editorconfig is widly used and supported file. It says basic things how
files should be formatted.

pre-commit is tool which can automatically check some basic checks like
code formatting everytime someone makes commit. This can also be used in
CI to run these things. Then it is very easy to do same things locally
as in CI. This also makes easy to select clang-format version so
everyone is using same one.

* clang-format: Ignore folders where are external code

We should not format external code. Add clang-format files to exclude
those. We should move external code always to example external/ folder
so we can exclude those more easily.

* clang-format: Remove custom zephyr/.clang-gormat

This clang-format file where introduces before our root clang-format. It
does not make sense anymore as we have root clang-format. Removing this
will unifie formatting in whole repo.

* clang-format: Add couple new rules

Add couple new formatting rules.

Always align const to left side. We did have only one place where it was
right side so this make sense as it is already rule for us.

I choose also insertbraces becuase when I run this I notice that we have
lot of multiline code without braces. So very error prone places. This
will take error possibility away. Repo also always use braces even with
single line statments so this does not matter much.

* ci: Add pre-commit validation

Validate pre-commit in CI.

* format: Convert spaces to tabs in Makefiles

Makefile normally use tabs. We enforce that with editorconfig. Fix
couple places where spaces where still in use.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander
2024-08-29 01:04:00 +03:00
committed by GitHub
parent 599033b7b0
commit 0177c59f4a
39 changed files with 317 additions and 174 deletions
+3 -3
View File
@@ -190,9 +190,9 @@ lint:
$(LINT) $(BFLAGS) $(CSRC)
install: $(TARGET_ELF)
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(TARGET).hex
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(TARGET).hex
## Clean target
.PHONY: clean
+5
View File
@@ -0,0 +1,5 @@
---
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
# External folder so ignore everything.
[*]
charset = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
end_of_line = unset
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+3 -3
View File
@@ -180,9 +180,9 @@ lint:
$(LINT) $(BFLAGS) $(CSRC)
install: $(TARGET_ELF)
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(TARGET).hex
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(TARGET).hex
## Clean target
.PHONY: clean
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
# External folder so ignore everything.
[*]
charset = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
end_of_line = unset
+5
View File
@@ -0,0 +1,5 @@
---
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
# External folder so ignore everything.
[*]
charset = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
end_of_line = unset
+5
View File
@@ -0,0 +1,5 @@
---
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
# External folder so ignore everything.
[*]
charset = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
end_of_line = unset
+5
View File
@@ -0,0 +1,5 @@
---
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+1 -1
View File
@@ -87,7 +87,7 @@ install: $(PRODUCT_EXE)
$(PRODUCT_EXE) : $(OBJS)
@echo Running Linker for $(PRODUCT_EXE)
$(LINK) -L$(C_LIB_DIR) -L$(BACNET_LIB_DIR) -m -c -s -v @&&|
$(BORLAND_DIR)\lib\c0x32.obj $**
$(BORLAND_DIR)\lib\c0x32.obj $**
$<
$*.map
$(LIBS)
+4 -4
View File
@@ -7,8 +7,8 @@
!ifndef BORLAND_DIR
BORLAND_DIR_Not_Defined:
@echo .
@echo You must define environment variable BORLAND_DIR to compile.
@echo .
@echo You must define environment variable BORLAND_DIR to compile.
!endif
PRODUCT = rs485
@@ -59,7 +59,7 @@ all : $(BCC_CFG) $(PRODUCT_EXE)
$(PRODUCT_EXE) : $(OBJS)
@echo Running Linker for $(PRODUCT_EXE)
$(LINK) -L$(C_LIB_DIR) -m -c -s -v @&&| # temp response file, starts with |
$(BORLAND_DIR)\lib\c0x32.obj $** # $** lists each dependency
$(BORLAND_DIR)\lib\c0x32.obj $** # $** lists each dependency
$<
$*.map
$(LIBS)
@@ -91,7 +91,7 @@ clean :
# Compiler configuration file
$(BCC_CFG) :
Copy &&|
Copy &&|
$(CFLAGS)
-c
-y #include line numbers in OBJ's
+7
View File
@@ -0,0 +1,7 @@
---
# Disable formatting for now as there is external code. We should move external
# code to a separate directory and enable formatting for our code.
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never
+7
View File
@@ -0,0 +1,7 @@
# External folder so ignore everything.
[*]
charset = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
end_of_line = unset
+5
View File
@@ -0,0 +1,5 @@
---
DisableFormat: true
# DisableFormat will not disable include sorting with some versions.
SortIncludes: Never