-
Notifications
You must be signed in to change notification settings - Fork 521
CHAD-17043: Created pre-commit script to check for newline and copyright on all staged lua files #2601
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
Open
aleclorimer
wants to merge
7
commits into
main
Choose a base branch
from
CHAD-17043-pre-commit-newline-copyright-checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−0
Open
CHAD-17043: Created pre-commit script to check for newline and copyright on all staged lua files #2601
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e98e95e
CHAD-17043: Created pre-commit script to check for newline and copyri…
aleclorimer b66a65d
CHAD-17043: Removed testing line
aleclorimer 15cf054
CHAD-17043: Copyright check no longer strict on year
aleclorimer 1b821ff
CHAD-17043: Allow for range of years in copyright checking
aleclorimer 283b1af
CHAD-17043: Newline and SmartThings driver checking
aleclorimer 407032d
CHAD-17043: Ensure executable commited and updated to soft linking logic
aleclorimer 9840f91
Merge branch 'main' into CHAD-17043-pre-commit-newline-copyright-checks
aleclorimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,41 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2025 SmartThings, Inc. | ||
| # Licensed under the Apache License, Version 2.0 | ||
| # | ||
| # pre-commit | ||
| # | ||
| # - Soft link into .git/hooks/pre-commit | ||
| # - $ ln -s tools/pre-commit .git/hooks/pre-commit | ||
| # - Ensure executable | ||
|
|
||
| set -e | ||
|
|
||
| # Get changed files that are Added or Modified | ||
| files=$(git diff --staged --name-only --diff-filter=AM) | ||
|
|
||
| fail=0 | ||
| for file in $files; do | ||
| # Only process .lua files | ||
| case "$file" in | ||
| *.lua) | ||
| # Skip if not a regular file | ||
| [ -f "$file" ] || continue | ||
|
|
||
| # Check if file is not empty, is a SmartThings driver and has the copyright header | ||
| if [ -s "$file" ] && [[ "$file" =~ "drivers/SmartThings" ]] | ||
| && [[ ! $(grep $file -P -e "-{2,} Copyright \d{4}(?:-\d{4})? SmartThings") ]]; then | ||
| echo "$file: SmartThings Copyright missing from file" | ||
| fail=1 | ||
| fi | ||
|
|
||
| # Check if file is non-empty and does NOT end with a newline | ||
| if [ -s "$file" ] && [ -n "$(tail -c 1 "$file")" ]; then | ||
| echo "$file: Missing newline at end of file" | ||
| fail=1 | ||
| fi | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| exit $fail | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's different with your version of
ln, but usually the first argument is assigned to the symlink verbatim, rather than computed from where you invoked the command. So, it should be../../tools/pre-commit.