One-Language / One

One (onelang) is an open-source system programming language that makes it easy to build reliable, efficient and performant software. (release as soon) 1️⃣ 🕐 🩱
https://onelang.org
GNU General Public License v3.0
288 stars 58 forks source link

🕴🏾 Our pre-commit/clang-format config is not great 🕴🏾 #212

Open BaseMax opened 3 years ago

BaseMax commented 3 years ago

As you see in some file for example lexer.test.c file I want to implement items of tokens in several lines.. https://github.com/One-Language/One/blob/master/test/lexer.test.c#L82

for example:

lexer_tests[lexer_tests_count++] = (LexerTest){"1\r\n    2\n3\n4", {token_make(TOKEN_VALUE_NUMBER), token_make(TOKEN_SKIP_WHITESPACE_LINE), token_make(TOKEN_VALUE_NUMBER), token_make(TOKEN_SKIP_WHITESPACE_LINE), token_make(TOKEN_VALUE_NUMBER), token_make(TOKEN_SKIP_WHITESPACE_LINE), token_make(TOKEN_VALUE_NUMBER), token_make(TOKEN_EOF)}, 7};

This is VERY BAD and not readable, we want some better syntax format.

This is much better:

lexer_tests[lexer_tests_count++] = (LexerTest){"1\r\n    2\n3\n4", {
    token_make(TOKEN_VALUE_NUMBER),
    token_make(TOKEN_SKIP_WHITESPACE_LINE),
    token_make(TOKEN_VALUE_NUMBER),
    token_make(TOKEN_SKIP_WHITESPACE_LINE),
    token_make(TOKEN_VALUE_NUMBER),
    token_make(TOKEN_SKIP_WHITESPACE_LINE),
    token_make(TOKEN_VALUE_NUMBER),
    token_make(TOKEN_EOF)
}, 7};
BaseMax commented 3 years ago

This is our clang-format config: https://github.com/One-Language/One/blob/master/.clang-format

We can take a look at other c/c++ projects to see what clang-config these use...

jbampton commented 3 years ago

https://stackoverflow.com/questions/33258159/how-to-make-clang-format-skip-sections-of-c-code

@BaseMax

BaseMax commented 3 years ago

Good trick

// clang-format off
.....
.....
.....
// clang-format on
jbampton commented 2 years ago

Do we need any other custom Clang Format settings ?