forked from PLC-lang/rusty
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add Pre-commit + editorconfig + gitattributes (PLC-lang#1034)
* Fix indentation levels cause by tabs In many places indentation level is little of because tabs where used. Probably someone might have example tabs size 2. Let's fix these by hand as automatic tools cannot fix these for us. They can prevent them from happening but fixing is not easy. * Fix unicode replacement chars These seems like accidents so remove those so we can start verify whole repo against those. In combined.st I changed language to english as it seems it should be. * Change all line-endings to LF in whole project There where not many files which where with CRLF. So it looks like we should always use LF. Let's fix couple files and then make sure this does not happen again. I also have some other problems with some of these files as I get strange douple newlines. * Add .gitattributes to force line-ending LF Force line-endings to LF. It could probably also be auto, but unless someone complain let's keep it LF. This will help that we have unified way for line-endings so we do not get those accidental commits where whole file is just big diff because line-ending change. * Add .pre-commit-config.yaml and .editorconfig With these we can automate lot of formatting issues with all files. We also get cleaner commits as every commit will be check with various small checkers. * Add editorconfig extension to devcontainer Now that we have editorconfig file it make sense to add it also to VScode as it does not support it out of the box. * ci: Remove submodules checks as we do not have any We do not have submodules so we do not need to check those. * format: Strip trailing whitespaces We want to get rid of trailing whitespaces completly as they make just git noice. Much better to start using automated tools to get rid of them once and not getting them back again. This way git history will be cleaner and review easyer. Commit was generated with: pre-commit run --all-files trailing-whitespace * format: File should have exacly one new line end of them It is good practice that every file has one new line. It is not now days so mandatory but it also is not nice if file has lot of newlines end of it. We will use pre-commit which takes automatically care about this so let's fix all. Commit was generated with: pre-commit run --all-files end-of-file-fixer * format: Run Black for whole repo Currently we only have one python file but is is nice if we have same formatting for all files. We will use Black for this. Commit was generated with: pre-commit run --all-files black * format: Convert tabs to spaces Project mostly use spaces over tabs. When mixing tabs and spaces this usually makes formatting issues and also when changing those in commits it will make lot of git noise. We will force spaces so just convert everything to tabs already. We did also have some users who tab wide was 2 and some 4. This is very common in projects to happen. Using pre-commit for these we can basically prevent this. Commit was generated with: pre-commit run --all-files remove-tabs * Regenerate test snapshots As we have changed style and example removed whitespaces we need to regenerate all test snapshots. Commit was generated with: ./pre-py/snap-pre.sh; cargo test --all; ./pre-py/snap-rework.sh; cargo test --all; ./pre-py/snap-rework.sh --------- Co-authored-by: Kari Argillander <[email protected]>
- Loading branch information
Showing
368 changed files
with
12,573 additions
and
12,489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ rustflags = [ | |
"-C", | ||
"link-arg=--target=aarch64-linux-gnu", | ||
] | ||
linker = "clang" | ||
linker = "clang" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,44 @@ | ||
{ | ||
"name": "Rust", | ||
"build": { | ||
"dockerfile": "./Dockerfile" | ||
}, | ||
// "image": "ghcr.io/plc-lang/rust-llvm:latest", | ||
"features": { | ||
"ghcr.io/devcontainers/features/common-utils:2": { | ||
"name": "Rust", | ||
"build": { | ||
"dockerfile": "./Dockerfile" | ||
}, | ||
// "image": "ghcr.io/plc-lang/rust-llvm:latest", | ||
"features": { | ||
"ghcr.io/devcontainers/features/common-utils:2": { | ||
"installZsh": "true", | ||
"username": "vscode", | ||
"userUid": "1000", | ||
"userGid": "1000", | ||
"upgradePackages": "true" | ||
} | ||
}, | ||
// Set *default* container specific settings.json values on container create. | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"lldb.executable": "/usr/bin/lldb", | ||
// VS Code don't watch files under ./target | ||
"files.watcherExclude": { | ||
"**/target/**": true | ||
}, | ||
"rust-analyzer.checkOnSave.command": "clippy" | ||
}, | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"bungcip.better-toml", | ||
"vadimcn.vscode-lldb", | ||
"mutantdino.resourcemonitor", | ||
"rust-lang.rust-analyzer" | ||
] | ||
} | ||
}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "rustc --version", | ||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode", | ||
"containerUser": "vscode" | ||
}, | ||
// Set *default* container specific settings.json values on container create. | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"lldb.executable": "/usr/bin/lldb", | ||
// VS Code don't watch files under ./target | ||
"files.watcherExclude": { | ||
"**/target/**": true | ||
}, | ||
"rust-analyzer.checkOnSave.command": "clippy" | ||
}, | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"bungcip.better-toml", | ||
"editorconfig.editorconfig", | ||
"vadimcn.vscode-lldb", | ||
"mutantdino.resourcemonitor", | ||
"rust-lang.rust-analyzer" | ||
] | ||
} | ||
}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "rustc --version", | ||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode", | ||
"containerUser": "vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.{yaml,yml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Set default behaviour to force line endings to LF. | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Pre-commit is currently in testing phase for this repo. It is not yet forced | ||
# in CI or mandatory to use. Pre-commit will run various checks and mostly fix | ||
# those when you do commiting. You can use it locally by installing it with | ||
# | ||
# pip install pre-commit | ||
# | ||
# and running | ||
# | ||
# pre-commit install | ||
# | ||
# in the root of the repository. This will install git hook which will run | ||
# checks before every commit. If you want to run checks manually for whole repo, | ||
# you can run | ||
# | ||
# pre-commit run --all-files | ||
# | ||
# You can always commit without running checks by adding --no-verify flag to git | ||
# commit command. | ||
|
||
exclude: target/|\.git/|.*\.snap | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: c4a0b883114b00d8d76b479c820ce7950211c99b # v4.5.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
args: [--assume-in-merge] | ||
# Editorconfig-checker does not care if file contains multiple newlines. | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-case-conflict | ||
- id: trailing-whitespace | ||
- id: fix-byte-order-marker | ||
|
||
- repo: https://github.com/Lucas-C/pre-commit-hooks | ||
rev: 762c66ea96843b54b936fc680162ea67f85ec2d7 # v1.5.4 | ||
hooks: | ||
- id: remove-tabs | ||
name: Remove tabs (4 spaces) | ||
args: ['--whitespaces-count', '4'] | ||
exclude: \.(yaml|yml)$ | ||
- id: remove-tabs | ||
name: Remove tabs (2 spaces) | ||
args: ['--whitespaces-count', '2'] | ||
files: \.(yaml|yml)$ | ||
|
||
- repo: https://github.com/pre-commit/pygrep-hooks | ||
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316 # v1.10.0 | ||
hooks: | ||
- id: text-unicode-replacement-char | ||
exclude: ".*test_fdx_utf8.cpp$" | ||
|
||
# Formatting Python code. We have not so many files so no example flake8 yet. | ||
- repo: https://github.com/psf/black | ||
rev: 2a1c67e0b2f81df602ec1f6e7aeb030b9709dc7c #23.11.0 | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
|
||
- repo: https://github.com/doublify/pre-commit-rust | ||
rev: eeee35a89e69d5772bdee97db1a6a898467b686e #v1.0 | ||
hooks: | ||
- id: fmt | ||
- id: cargo-check | ||
- id: clippy | ||
args: ["--", "-D", "warnings"] | ||
|
||
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python | ||
rev: 2b74735540f79457a50369e5c17a2c35d52c3298 # 2.7.3 | ||
hooks: | ||
- id: editorconfig-checker | ||
args: [ | ||
# Saddly we have to disable this, but it just won't work. Maybe some day. | ||
-disable-indent-size, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,4 @@ | |
"cwd": "${workspaceFolder}" | ||
}, | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
name = "rusty" | ||
version = "0.2.0" | ||
authors = [ | ||
"Ghaith Hachem <[email protected]>", | ||
"Mathias Rieder <[email protected]>", | ||
"Ghaith Hachem <[email protected]>", | ||
"Mathias Rieder <[email protected]>", | ||
] | ||
edition = "2021" | ||
readme = "README.md" | ||
|
@@ -59,16 +59,16 @@ path = "src/lib.rs" | |
|
||
[workspace] | ||
members = [ | ||
"xtask", | ||
"libs/stdlib", | ||
"compiler/plc_driver", | ||
"compiler/plc_ast", | ||
"compiler/plc_diagnostics", | ||
"compiler/plc_project", | ||
"compiler/plc_source", | ||
"compiler/plc_util", | ||
"compiler/plc_xml", | ||
"compiler/plc_derive", | ||
"xtask", | ||
"libs/stdlib", | ||
"compiler/plc_driver", | ||
"compiler/plc_ast", | ||
"compiler/plc_diagnostics", | ||
"compiler/plc_project", | ||
"compiler/plc_source", | ||
"compiler/plc_util", | ||
"compiler/plc_xml", | ||
"compiler/plc_derive", | ||
] | ||
default-members = [".", "compiler/plc_driver", "compiler/plc_xml"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.