Your commit message
This commit is contained in:
parent
6db7f1b834
commit
023e1049f7
|
@ -0,0 +1 @@
|
|||
_
|
|
@ -0,0 +1,100 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
# Function to display errors
|
||||
display_errors() {
|
||||
local errors="$1"
|
||||
echo "Errors detected:"
|
||||
echo "---------------------------------------"
|
||||
echo "$errors"
|
||||
echo "---------------------------------------"
|
||||
}
|
||||
|
||||
# Get the list of staged files
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(php|js|css|jsx|ts|tsx)$')
|
||||
|
||||
# If there are no staged files, exit
|
||||
if [ -z "$STAGED_FILES" ]; then
|
||||
echo "No files staged for commit."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Initialize error flags
|
||||
ESLINT_ERRORS=""
|
||||
PHP_ERRORS=0
|
||||
|
||||
# Function to run ESLint and Prettier on JavaScript files
|
||||
run_js_tools() {
|
||||
local files="$1"
|
||||
if [ -n "$files" ]; then
|
||||
echo "Running ESLint..."
|
||||
for FILE in $files; do
|
||||
ESLINT_OUTPUT=$(npx eslint "$FILE" 2>&1)
|
||||
if [ $? -ne 0 ]; then
|
||||
display_errors "$ESLINT_OUTPUT"
|
||||
ESLINT_ERRORS=1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Running Prettier..."
|
||||
for FILE in $files; do
|
||||
npx prettier --write "$FILE"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run PHP tools
|
||||
run_php_tools() {
|
||||
local files="$1"
|
||||
if [ -n "$files" ]; then
|
||||
echo "Checking PHP syntax errors..."
|
||||
SYNTAX_ERRORS=0
|
||||
for FILE in $files; do
|
||||
php -l "$FILE"
|
||||
if [ $? -ne 0 ]; then
|
||||
SYNTAX_ERRORS=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $SYNTAX_ERRORS -ne 0 ]; then
|
||||
PHP_ERRORS=1
|
||||
echo "Syntax errors detected in PHP files."
|
||||
fi
|
||||
|
||||
echo "Running PHPCBF..."
|
||||
for FILE in $files; do
|
||||
/home/aissel/.config/composer/vendor/bin/phpcbf --standard=/var/www/html/google_forms/phpcs.xml "$FILE" || true
|
||||
done
|
||||
|
||||
echo "Running PHP CS Fixer..."
|
||||
for FILE in $files; do
|
||||
/home/aissel/.config/composer/vendor/bin/php-cs-fixer fix "$FILE"
|
||||
done
|
||||
|
||||
echo "Running PHPCS..."
|
||||
for FILE in $files; do
|
||||
PHPCS_OUTPUT=$(/home/aissel/.config/composer/vendor/bin/phpcs --standard=/var/www/html/google_forms/phpcs.xml "$FILE" 2>&1)
|
||||
if [ $? -ne 0 ]; then
|
||||
display_errors "$PHPCS_OUTPUT"
|
||||
PHP_ERRORS=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Run tools based on file types
|
||||
run_js_tools "$(echo "$STAGED_FILES" | grep -E '\.(js|jsx|ts|tsx)$')"
|
||||
run_php_tools "$(echo "$STAGED_FILES" | grep '\.php$')"
|
||||
|
||||
# Add the fixed files back to the staging area
|
||||
for FILE in $STAGED_FILES; do
|
||||
git add "$FILE"
|
||||
done
|
||||
|
||||
# Exit with error code if there were any errors
|
||||
if [ $PHP_ERRORS -ne 0 ] || [ $ESLINT_ERRORS -eq 1 ]; then
|
||||
echo "Pre-commit checks failed. Please fix the errors before committing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Pre-commit checks completed."
|
29
package.json
29
package.json
|
@ -6,21 +6,22 @@
|
|||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"prepare": "husky install",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "phpcbf && eslint . --fix"
|
||||
"lint": "eslint src --ext .js,.jsx --report-unused-disable-directives",
|
||||
"lint-php": "phpcs --standard=PSR12 && phpcbf --standard=PSR12 && php-cs-fixer fix",
|
||||
"format": "prettier --write"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.aissel.com/RameshT/google_forms.git"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.php": [
|
||||
"phpcbf",
|
||||
"git add"
|
||||
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
||||
"prettier --write"
|
||||
],
|
||||
"*.js": [
|
||||
"eslint --fix",
|
||||
"git add"
|
||||
"**/*.php": [
|
||||
"phpcs --standard=PSR12",
|
||||
"phpcbf --standard=PSR12",
|
||||
"php-cs-fixer fix"
|
||||
]
|
||||
},
|
||||
"keywords": [],
|
||||
|
@ -28,10 +29,14 @@
|
|||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.8.0",
|
||||
"eslint": "^9.8.0",
|
||||
"globals": "^15.8.0",
|
||||
"husky": "^8.0.0",
|
||||
"lint-staged": "^15.2.7"
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-html": "^8.1.1",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"globals": "^15.9.0",
|
||||
"husky": "^6.0.0",
|
||||
"lint-staged": "^15.2.7",
|
||||
"prettier": "^3.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-escapes": "^7.0.0",
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="Custom Ruleset">
|
||||
<description>Custom ruleset excluding specific rules.</description>
|
||||
|
||||
<!-- PSR-12 rules -->
|
||||
<rule ref="PSR12"/>
|
||||
|
||||
<!-- Exclude the specific rule about side effects -->
|
||||
<rule ref="PSR1.Files.SideEffects">
|
||||
<exclude name="PSR1.Files.SideEffects"/>
|
||||
</rule>
|
||||
|
||||
<!-- Add any other rules or exclusions as needed -->
|
||||
</ruleset>
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"workbench.colorTheme": "Dark Chai",
|
||||
"workbench.editor.enablePreview": false,
|
||||
"files.autoSave": "afterDelay",
|
||||
"git.enableSmartCommit": true,
|
||||
"git.confirmSync": false,
|
||||
|
||||
// PHP_CodeSniffer configuration
|
||||
"phpcs.enable": true,
|
||||
"phpcs.executablePath": "/home/aissel/.config/composer/vendor/bin/phpcs",
|
||||
"phpcs.standard": "PSR12",
|
||||
|
||||
// PHP Code Beautifier and Fixer (PHPCBF) configuration
|
||||
"phpcbf.enable": true,
|
||||
"phpcbf.executablePath": "/home/aissel/.config/composer/vendor/bin/phpcbf",
|
||||
|
||||
// PHP CS Fixer configuration
|
||||
"php-cs-fixer.executablePath": "/home/aissel/.config/composer/vendor/bin/php-cs-fixer",
|
||||
"php-cs-fixer.executablePathWindows": "",
|
||||
"php-cs-fixer.onsave": true,
|
||||
"php-cs-fixer.rules": "@PSR12",
|
||||
"php-cs-fixer.config": ".php-cs-fixer.php;.php-cs-fixer.dist.php;.php_cs;.php_cs.dist",
|
||||
"php-cs-fixer.allowRisky": false,
|
||||
"php-cs-fixer.pathMode": "override",
|
||||
"php-cs-fixer.ignorePHPVersion": false,
|
||||
"php-cs-fixer.exclude": [],
|
||||
"php-cs-fixer.autoFixByBracket": true,
|
||||
"php-cs-fixer.autoFixBySemicolon": true,
|
||||
"php-cs-fixer.formatHtml": true,
|
||||
"php-cs-fixer.documentFormattingProvider": true,
|
||||
// "php-cs-fixer.setParallel": true,
|
||||
|
||||
// Format on save for PHP files
|
||||
"editor.formatOnSave": true,
|
||||
"[php]": {
|
||||
"editor.defaultFormatter": "junstyle.php-cs-fixer"
|
||||
},
|
||||
|
||||
// Additional settings
|
||||
"settingsSync.ignoredSettings": [],
|
||||
"json.schemas": [
|
||||
|
||||
|
||||
|
||||
],
|
||||
"workbench.settings.applyToAllProfiles": [
|
||||
],
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue