-
Notifications
You must be signed in to change notification settings - Fork 25
STYLE: Code linting #216
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
jahnvi480
wants to merge
22
commits into
main
Choose a base branch
from
jahnvi/code_linting
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.
Open
STYLE: Code linting #216
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c635707
FIX: Python Code linting
jahnvi480 00401a0
FIX: Python Code linting
jahnvi480 939252d
Cpp linting
jahnvi480 ef97e24
Resolving merge conflicts
jahnvi480 6857285
Resolving conflicts
jahnvi480 7943443
silence unwanted devskim alerts
bewithgaurav 6892100
Resolving error
jahnvi480 ac7003a
Merge branch 'jahnvi/code_linting' of https://github.com/microsoft/ms…
jahnvi480 d90e48f
Resolving errors
jahnvi480 f112356
Resolving errors
jahnvi480 70f7170
Resolving errors
jahnvi480 901c30d
Resolving errors
jahnvi480 c5697c9
Resolving conflicts
jahnvi480 315b35d
Adding fully types methods for all the methods in mssql_python
jahnvi480 99747af
Adding precommit hook as well as workflow
jahnvi480 34a386f
Adding precommit hook as well as workflow
jahnvi480 c81197d
Adding precommit hook as well as workflow
jahnvi480 4130cca
Adding precommit hook as well as workflow
jahnvi480 4d21df0
Adding precommit hook as well as workflow
jahnvi480 8966cae
Adding precommit hook as well as workflow
jahnvi480 9fca5aa
Adding pre-commit in requirements.txt
jahnvi480 850ce79
Adding pre-commit in requirements.txt
jahnvi480 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,141 @@ | ||
name: Code Quality | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
|
||
on: | ||
pull_request: | ||
types: [opened, edited, reopened, synchronize] | ||
paths: | ||
- '**.py' | ||
- '**.cpp' | ||
- '**.h' | ||
|
||
jobs: | ||
lint: | ||
name: Code Linting | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Cache pip dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -e . | ||
pip install pylint cpplint | ||
|
||
- name: Run Python Linter | ||
id: pylint | ||
continue-on-error: true | ||
run: | | ||
echo "Running pylint with threshold 8.5..." | ||
python -m pylint --fail-under=8.5 --disable=fixme,no-member,too-many-arguments,too-many-positional-arguments,invalid-name,useless-parent-delegation --output-format=colorized mssql_python | ||
echo "pylint_status=$?" >> $GITHUB_ENV | ||
|
||
- name: Run C++ Linter | ||
id: cpplint | ||
continue-on-error: true | ||
run: | | ||
echo "Running cpplint with maximum 10 errors per file..." | ||
|
||
# Find C++ files excluding build directories | ||
FILES=$(find mssql_python -name "*.cpp" -o -name "*.h" | grep -v "/build/") | ||
if [ -z "$FILES" ]; then | ||
echo "No C++ files found to check!" | ||
echo "cpplint_status=0" >> $GITHUB_ENV | ||
exit 0 | ||
fi | ||
|
||
echo "Found files to check:" | ||
echo "$FILES" | ||
|
||
# Process each file individually with better error handling | ||
MAX_ERRORS=10 | ||
FAILED_FILES="" | ||
|
||
for FILE in $FILES; do | ||
echo "Checking $FILE..." | ||
|
||
# Run cpplint on a single file and capture output | ||
OUTPUT=$(python -m cpplint --filter=-readability/todo --linelength=100 "$FILE" 2>&1 || true) | ||
|
||
# Display the output for this file | ||
echo "$OUTPUT" | ||
|
||
# Extract error count more reliably | ||
ERROR_COUNT=$(echo "$OUTPUT" | grep -o 'Total errors found: [0-9]*' | grep -o '[0-9]*' || echo "0") | ||
|
||
# If we couldn't extract a count, default to 0 | ||
if [ -z "$ERROR_COUNT" ]; then | ||
ERROR_COUNT=0 | ||
fi | ||
|
||
echo "File $FILE has $ERROR_COUNT errors" | ||
|
||
# Check if over threshold | ||
if [ "$ERROR_COUNT" -gt "$MAX_ERRORS" ]; then | ||
FAILED_FILES="$FAILED_FILES\n- $FILE ($ERROR_COUNT errors)" | ||
fi | ||
done | ||
|
||
# Output results | ||
if [ ! -z "$FAILED_FILES" ]; then | ||
echo -e "\n⛔ The following files have more than $MAX_ERRORS errors:$FAILED_FILES" | ||
echo "cpplint_status=1" >> $GITHUB_ENV | ||
else | ||
echo -e "\n✅ All files have $MAX_ERRORS or fewer errors." | ||
echo "cpplint_status=0" >> $GITHUB_ENV | ||
fi | ||
|
||
- name: Determine overall status | ||
run: | | ||
if [[ "${{ env.pylint_status }}" != "0" || "${{ env.cpplint_status }}" != "0" ]]; then | ||
echo "Linting checks failed!" | ||
exit 1 | ||
else | ||
echo "All linting checks passed!" | ||
fi | ||
|
||
- name: Comment on PR | ||
if: github.event_name == 'pull_request' && (env.pylint_status != '0' || env.cpplint_status != '0') | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
let comment = '## Code Quality Check Results\n\n'; | ||
|
||
if ('${{ env.pylint_status }}' !== '0') { | ||
comment += '⚠️ **Python linting failed** - Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.\n\n'; | ||
} else { | ||
comment += '✅ **Python linting passed**\n\n'; | ||
} | ||
|
||
if ('${{ env.cpplint_status }}' !== '0') { | ||
comment += '⚠️ **C++ linting failed** - Some files exceed the maximum error threshold of 10.\n\n'; | ||
} else { | ||
comment += '✅ **C++ linting passed**\n\n'; | ||
} | ||
|
||
comment += 'See [code quality guidelines](https://github.com/microsoft/mssql-python/blob/main/CONTRIBUTING.md) for more information.'; | ||
|
||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: comment | ||
}); |
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,16 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/mirrors-pylint | ||
rev: v3.0.0a5 | ||
hooks: | ||
- id: pylint | ||
args: [--fail-under=8.5, --disable=fixme,no-member,too-many-arguments,too-many-positional-arguments,invalid-name,useless-parent-delegation] | ||
|
||
- repo: local | ||
hooks: | ||
- id: cpplint | ||
name: cpplint | ||
entry: python -m cpplint | ||
language: python | ||
types: [c++] | ||
args: [--filter=-readability/todo, --linelength=100] | ||
exclude: ^.*build/.*$ |
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,4 @@ | ||
set noparent | ||
filter=-readability/todo | ||
linelength=100 | ||
exclude_files=build |
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
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
Oops, something went wrong.
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.
can we put this comment regardless of error? lets try adding this first, if looks spammy we can restore this condition