diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e6afa4072 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,23 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: 'ad270fb9db427f956ce8eb50c74617ed117b9bfc' + hooks: + - id: clang-format + - repo: https://github.com/pocc/pre-commit-hooks + rev: '336fdd7c3cab698ead0b1c95157b9e74d3906b62' + hooks: + - id: cppcheck + args: [ "--platform=unix64", "-j", "4", "-I include src" ] + - repo: https://github.com/compilerla/conventional-pre-commit + rev: 'v3.2.0' + hooks: + - id: conventional-pre-commit + stages: [ commit-msg ] + args: [ ] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f5806b5c2..a3260f1c5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,9 +5,10 @@ You will find here a summary of the different things you should do / look up to ## Starting * First, [fork](https://github.com/ArkScript-lang/Ark/fork) the repository -* Then, clone your fork: +* Then, clone your fork: * HTTPS: `git clone https://github.com//Ark.git` * or SSH: `git clone git@github.com:/Ark.git` +* Install the pre-commit hooks: `pre-commit install` (you may need to [install pre-commit](https://pre-commit.com/#install) first) * Create a branch for your feature: `git checkout -b feat/my-awesome-idea` * When you're done, push it to your fork and submit a pull request @@ -29,35 +30,21 @@ See the guide [to create a module](https://arkscript-lang.dev/impl/d1/d8c/module ## Submitting a pull request -### Checking the enforcement of the coding style - -If it is a C++ project, it is strongly advised to run clang-format on your code *before* submitting a pull request. - -You can do as follows if you are a Windows user: -```powershell -Function run-on { - param ( - $folder - ) - Get-ChildItem -Path $folder -File -Recurse | Foreach {clang-format -style=file -i $_.fullname} -} - -run-on .\include\Ark -run-on .\src -``` +Code formatting as well as static analysis is handled through `pre-commit` and its hooks. If you don't have it installed, refer back to [Contributing#Starting](#starting). ### Running the test suite -The ArkScript test suite requires the console module for text colors. You can build all the modules by including the `-DARK_BUILD_MODULES` CMake switch when building ArkScript. Once you have the modules built, you can run the ArkScript test suite from the root folder using `./build/arkscript tests/arkscript/unittests.ark --lib ./lib`. - -The standard library test suite should be ran from the root folder of the standard library project (the console module will need to be copied to the folder). You can run standard library test suite using `./arkscript tests/all.ark --lib ./`. +Build and run the `arkscript` and `unittests` targets: +- `arkscript tests/arkscript/unittests.ark` (ArkScript unit tests for the VM and builtins) +- `arkscript lib/std/tests/all.ark` (ArkScript unit tests for the standard library) +- `unittests` (various C++ unit tests, testing error messages, AST, parsing...) ## C++ coding guidelines * Avoid `auto` whenever possible. Using it is tolerated for complex types such as iterators * Indent with **4 spaces** * Every brace (`{`, `}`) must be on its own line -* Conditions with a single statement (`if (condition) do_this();`) do not need to be enclosed in braces +* Conditions with a single statement (eg `if (condition) do_this();`) do not need to be enclosed in braces * Put a space between `for`, `while`, `if` and `(...)`, around each `=` sign (wherever it is, even in for-loops), between `#include` and the file to include * Prefer `enum class` over `enum` * Left-const over right-const @@ -108,11 +95,11 @@ for (std::size_t i = 0, end = container.size(); i < end; i++) * @brief Tokenize ArkScript code * @version 0.1 * @date 2020-10-27 - * + * * @copyright Copyright (c) 2020 - * + * */ - + #include code... @@ -127,9 +114,9 @@ Snippet to recapitulate guidelines for headers: * @brief Tokenize ArkScript code * @version 0.1 * @date 2020-10-27 - * + * * @copyright Copyright (c) 2020 - * + * */ #ifndef HEADER_GUARD @@ -149,13 +136,13 @@ namespace Ark public: /** * @brief doxygen documentation here - * + * */ Lexer(); /** * @brief doxygen documentation here - * + * * @param a_parameter defines the power of the flux capacitor */ void aMethod(const std::string& a_parameter); diff --git a/README.md b/README.md index b487b13fe..4b035555a 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ cmake --install build * First, [fork](https://github.com/ArkScript-lang/Ark/fork) the repository * Then, clone your fork: `git clone git@github.com:username/Ark.git` +* Install the pre-commit hooks: `pre-commit install` (you may need to [install pre-commit](https://pre-commit.com/#install) first) * Create a branch for your feature: `git checkout -b feat-my-awesome-idea` * When you're done, push it to your fork and submit a pull request @@ -181,19 +182,19 @@ DESCRIPTION ArkScript programming language SYNOPSIS - arkscript -h - arkscript -v - arkscript --dev-info - arkscript -e - arkscript -c [-d] - arkscript [-d] [-L ] - arkscript -f [--dry-run] - arkscript --ast [-d] [-L ] - arkscript -bcr -on - arkscript -bcr -a [-s ] - arkscript -bcr -st [-s ] - arkscript -bcr -vt [-s ] - arkscript -bcr [-cs] [-p ] [-s ] + arkscript -h + arkscript -v + arkscript --dev-info + arkscript -e + arkscript -c [-d] + arkscript [-d] [-L ] + arkscript -f [--dry-run] + arkscript --ast [-d] [-L ] + arkscript -bcr -on + arkscript -bcr -a [-s ] + arkscript -bcr -st [-s ] + arkscript -bcr -vt [-s ] + arkscript -bcr [-cs] [-p ] [-s ] OPTIONS -h, --help Display this message diff --git a/docs/guidelines_coding.md b/docs/guidelines_coding.md index 98988012a..66f20c10a 100644 --- a/docs/guidelines_coding.md +++ b/docs/guidelines_coding.md @@ -9,7 +9,7 @@ _module_: C++ plugin for the ArkScript virtual machine, allowing use of C++ code ## Precisions -Indentation matters to us, programmers (but not to the compiler): 4 spaces or a single tab, but it should stay consistent accross a project/file. +Indentation matters to us, programmers (but not to the compiler): 4 spaces or a single tab, but it should stay consistent across a project/file. The general rule of thumb is that a closing parenthesis should never be to the left of its matching opening parenthesis. All new lines should be a couple of spaces to the right of the opening parenthesis of the list they're in. @@ -21,7 +21,7 @@ Functions and constants (the ones in the lib and in the builtins) are named foll * Indent the content of every `begin` block * When using begin blocks in if (then, else), they should appear clearly as a block, each opening brace on its own line -* When using begin blocks in functions (body), they can appear as an indenpendant block (initial `(begin` or `{` on its own line) or not (initial `(begin` or `{` on the same line as the `fun` keyword) +* When using begin blocks in functions (body), they can appear as an independent block (initial `(begin` or `{` on its own line) or not (initial `(begin` or `{` on the same line as the `fun` keyword) * closing braces are stacked together, and never preceded by a newline * if the last instruction wasn't a function call but a variable, a space should be put between those two