Category: News
Website Setting up Homepage Layout Part-2 | Learning freelancing skill for course |
Specbee: How to Adhere to Drupal Coding Standards with Git Hooks
Prabhu
23 May, 2023
Good code is like well-built Lego creations – it’s strong, looks good, and is easy to change if you need to. The importance of good coding standards is especially high when you’re coding in a team, working on a scalable project, or participating in an open-source community like Drupal.
As with any other open-source project, Drupal has thousands of developers working on the project. And each of them comes with their own level of expertise. How do you ensure everyone on your team or in the community follows good coding practices? Git Hooks!
Git Hooks are an easy and automated way of ensuring your code always meets Drupal’s coding standards. Implementing Drupal Coding Standards with Git hook will help developers to commit and push the code with proper coding standards as declared by the Drupal community. It can also help improve your project management skills and allows developers to commit code with proper commit message standards. Learn more about Git hooks and how to put them into action.
What is a Git Hook
Git Hooks are scripts that will run automatically every time a Git command is invoked. Just as you would use hook_form_alter to alter the forms in Drupal, you can have separate pre-defined hooks for every Git action.
The Pictorial Representation of Git hook
Finding Git hooks
You can find Git hooks within your project folder (provided Git is initialized) under .git/hooks. There, you will find all the hooks with .sample extension to prevent them from executing by default.
To make use of the required hooks, you need to remove the .sample extension and edit your code for the execution.
There are many Git hooks available but we are going to use pre-commit Git hooks for initiating Drupal coding standards.
Pre-commit Git hooks are hooks that will run before the code gets committed. It checks for the line of code that’s getting committed.
Implementing Git Hooks
Before you start, make sure you have these basic requirements ready:
- Composer
- Git
- Php-code-sniffer
- drupal/coder:8.3.13
The below procedure is for installing it in Mac devices. You can find the reference link here for installing instructions on other devices.
- brew install php-code-sniffer
- composer global require drupal/coder:8.3.13
- phpcs –config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
- phpcs -i → Will give you installed coding standards.
Let’s begin!
I am creating a new Drupal project called demo. You can use it in your existing project as well.
→ Using cd command we got into the project folder.
cd demo
→ initializing git into the project
Git init
→ Adding and making my first commit.
git commit -m “Initial commit”
→ Installing php code sniffer using below command for Mac.
brew install php-code-sniffer
→ Installing Drupal coder using composer
composer global require drupal/coder:8.3.13
→ Once the coder and its path are defined you will get the following output as shown below image.
phpcs –config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
→ phpcs -i
The above command will give you Drupal and DrupalPractice
→ Now you can commit your code. If you have any syntax or coding standard error, you will be notified in the display and your commit process will be aborted.
→ Below is the code to fix the error automatically
phpcbf –standard=Drupal –extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/custom/demo
Any other issues will need to be fixed manually. Commit your code once done.
Once your code is clean it will allow you to commit the code
Just copy and paste the code in pre-commit.sample within .git/hooks. Don’t forget to remove sample extensions.
Pre-commit code sample:
#!/bin/bash
# Redirect output to stderr.
exec 1>&2
# Color codes for the error message.
redclr=`tput setaf 1`
greenclr=`tput setaf 2`
blueclr=`tput setaf 4`
reset=`tput sgr0`
# Printing the notification in the display screen.
echo “${blueclr}”
echo “…………………………… Validating your codes ……..……………..”
echo “———————————————————–${reset}”
# Mentioning the directories which should be excluded.
dir_exclude=’/kint/|/contrib/|/devel/|/libraries/|/vendor/|.info$|.png$|.gif$|.jpg$|.ico$|.patch$|
.htaccess$|.sh$|.ttf$|.woff$|.eot$|.svg$’
# Checking for the debugging keyword in the commiting code base.
keywords=(ddebug_backtrace debug_backtrace dpm print_r var_dump dump console.log)
keywords_for_grep=$(printf “|%s” “${keywords[@]}”)
keywords_for_grep=${keywords_for_grep:1}
# Flags for the counter.
synatx_error_found=0
debugging_function_found=0
merge_conflict=0
coding_standard_error=0
# Checking for PHP syntax errors.
changed_files=`git diff-index –diff-filter=ACMRT –cached –name-only HEAD — | egrep ‘.theme$|.module$|.inc|.php$’`
if [ -n “$changed_files” ]
then
for FILE in $changed_files; do
php -l $FILE > /dev/null 2>&1
compiler_result=$?
if [ $compiler_result -eq 255 ]
then
if [ $synatx_error_found -eq 0 ]
then
echo “${redclr}”
echo “# Compilation error(s):”
echo “=========================${reset}”
fi
synatx_error_found=1
`php -l $FILE > /dev/null`
fi
done
fi
# Checking for debugging functions.
files_changed=`git diff-index –diff-filter=ACMRT –cached –name-only HEAD — | egrep -v $dir_exclude`
if [ -n “$files_changed” ]
then
for FILE in $files_changed ; do
for keyword in “${keywords[@]}” ; do
pattern=”^+(.*)?$keyword(.*)?”
resulted_files=`git diff –cached $FILE | egrep -x “$pattern”`
if [ ! -z “$resulted_files” ]
then
if [ $debugging_function_found -eq 0 ]
then
echo “${redclr}”
echo “Validating keywords”
echo “================================================${reset}”
fi
debugging_function_found=1
echo “Debugging function” $keyword
git grep -n $keyword $FILE | awk ‘{split($0,a,”:”);
printf “found in ” a[1] ” in line ” a[2] “n”;
}’
fi
done
done
fi
# Checking for Drupal coding standards
changed_files=`git diff-index –diff-filter=ACMRT –cached –name-only HEAD — | egrep -v $dir_exclude | egrep ‘.php$|.module$|.inc$|.install$|.test$|.profile$|.theme$|.js$|.css$|.info$|.txt$|.yml$’`
if [ -n “$changed_files” ]
then
phpcs_result=`phpcs –standard=Drupal –extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml –report=csv $changed_files`
if [ “$phpcs_result” != “File,Line,Column,Type,Message,Source,Severity,Fixable” ]
then
echo “${redclr}”
echo “# Hey Buddy, The hook found some issue(s).”
echo “———————————————————————————————${reset}”
phpcs –standard=Drupal –extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml $changed_files
echo ” Run below command to fix the issue(s)”
echo “# phpcbf –standard=Drupal –extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml your_custom_module_or_file_path”
echo “”
echo “# To skip the Drupal Coding standard issue(s), Please use this commands >”
echo “—————————————————————————————————————————————–${reset}”
coding_standard_error=1
fi
fi
# Checking for merge conflict markers.
files_changed=`git diff-index –diff-filter=ACMRT –cached –name-only HEAD –`
if [ -n “$files_changed” ]
then
for FILE in $files_changed; do
pattern=”(>>>)+.*(n)?”
resulted_files=`egrep -in “$pattern” $FILE`
if [ ! -z “$resulted_files” ]
then
if [ $merge_conflict -eq 0 ]
then
echo “${redclr}”
echo “———————–Unable to commit the file(s):————————“
echo “———————————–${reset}”
fi
merge_conflict=1
echo $FILE
fi
done
fi
# Printing final result
errors_found=$((synatx_error_found+debugging_function_found+merge_conflict+coding_standard_error))
if [ $errors_found -eq 0 ]
then
echo “${greenclr}”
echo “Wow! It is clean code”
echo “${reset}”
else
echo “${redclr}”
echo “Please Correct the errors mentioned above. We are aborting your commit.”
echo “${reset}”
exit 1
fi
Final Thoughts
I hope you found this article interesting and that it helps you write better code because better code means a better web! Liked what you just read? Consider subscribing to our weekly newsletter and get tech insights like this one delivered to your inbox!
Leveling Up For Juniors With CodeWithJulie | Rubber Duck Dev Show 85
Python 3.12.0 beta 1 released
I’m pleased to announce the release of Python 3.12 beta 1 (and feature freeze for Python 3.12).
https://www.python.org/downloads/release/python-3120b1/
This is a beta preview of Python 3.12
Major new features of the 3.12 series, compared to 3.11
Some of the new major new features and changes in Python 3.12 are:
- New type annotation syntax for generic classes (PEP 695).
- More flexible f-string parsing, allowing many things previously disallowed (PEP 701).
- Even more improved error messages. More exceptions potentially caused by typos now make suggestions to the user.
- Many large and small performance improvements (like PEP 709).
- Support for the Linux perf profiler to report Python function names in traces.
- The deprecated wstr and wstr_length members of the C implementation of unicode objects were removed, per PEP 623.
- In the unittest module, a number of long deprecated methods and classes were removed. (They had been deprecated since Python 3.1 or 3.2).
- The deprecated smtpd and distutils modules have been removed (see PEP 594 and PEP 632. The setuptools package (installed by default in virtualenvs and many other places) continues to provide the distutils module.
- A number of other old, broken and deprecated functions, classes and methods have been removed.
- Invalid backslash escape sequences in strings now warn with SyntaxWarning instead of DeprecationWarning, making them more visible. (They will become syntax errors in the future.)
- The internal representation of integers has changed in preparation for performance enhancements. (This should not affect most users as it is an internal detail, but it may cause problems for Cython-generated code.)
- (Hey, fellow core developer, if a feature you find important is missing from this list, let Thomas know.)
For more details on the changes to Python 3.12, see What’s new in Python 3.12. The next pre-release of Python 3.12 will be 3.12.0b2, currently scheduled for 2023-05-29.
More resources
And now for something completely different
As the first beta release marks the point at which we fork off the release branch from the main development branch, here’s a poem about forks in the road.
Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;Then took the other, as just as fair,
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that the passing there
Had worn them really about the same,And both that morning equally lay
In leaves, no step had trodden black.
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I —
I took the one less traveled by,
And that has made all the difference.
Enjoy the new release
News & Views Live: मविआचा जागांचा वाद, भाजपची रणनीती तयार? | Maha Vikas Aghadi | BJP
#mahavikasaghadi #shivsenaubt #ncp #congress #maharashtrapolitics #lokmat
Subscribe to Our Channel
https://www.youtube.com/user/LokmatNews?sub_confirmation=1
आमचा video आवडल्यास धन्यवाद. Like, Share and Subscribe करायला विसरू नका!
मित्रांसोबत गप्पा मारताना विश्वसनीय, संशोधनावर आधारीत माहिती सादर करायची असेल तर लोकमतचे चॅनल सबस्क्राईब करा. कारण या चॅनलवर तुम्हाला पाहायला मिळतील अतिशय अभ्यासू, वेगळ्या अँगलच्या बातम्या ! राजकारण, क्राईम, मनोरंजन आणि क्रीडा क्षेत्रातील अनुभवी पत्रकार तुमच्यासाठी आणत आहेत दर्जेदार आणि जाणते करणाऱ्या बातम्या….
Click Here For Latest News & Updates►http://www.lokmat.com
To Stay Updated Download the Lokmat App►
Android Google Play: http://bit.ly/LokmatApp
Like Us On Facebook ► https://www.facebook.com/lokmat
Follow Us on Twitter ►https://twitter.com/MiLOKMAT
Instagram ►https://www.instagram.com/milokmat
Anne Givaudan. Robins des Bois 33. Le Gouvernement de l’Âme, de la Conscience c/mental, ego
Entrevue
France => Humanité
~
Titre originel –
« Anne Givaudan : Robin des Bois – 15 mars 2023 »
~
Les liens conseillés par Anne :
– https://cutt.ly/CmKPamp
(aller dans la partie intitulée «ANNE GIVAUDAN : ROBIN DES BOIS – 22 MAI 2023»)
– ou cliquer ci-après puis aller dans le descriptif
à venir
~
Canal Telegram “Anne Givaudan et son équipe” – https://t.me/AnneGivaudanFrance
Newsletter – https://cutt.ly/nJAjRjf
~
“c/” est l’abréviation de “contre”
~
Aussi :
● Anne Givaudan
► https://www.dailymotion.com/playlist/x73h26
● Elémentaux – les Petits Peuples de la Nature
► https://www.dailymotion.com/playlist/x7hq9o
● Retrouver sa Souveraineté
► https://www.dailymotion.com/playlist/x7hilg
● Amérique du Nord
► https://www.dailymotion.com/playlist/x7easg
● Europe ֎ 1
► https://www.dailymotion.com/playlist/x73dum
● Europe ֎ 2
► https://www.dailymotion.com/playlist/x7j5gb
~
♥ . . .
~
} Si lecture impossible de vidéo, désactiver le bloqueur de publicité ABP icône panneau routier « Stop » en haut à droite de la barre d’adresse dans Google Chrome.
} Si le lecteur indique « vidéo réservée aux adultes » alors désactiver le Filtre Parental en bas de la page de présentation de la vidéothèque.
} Afin de préserver de la calcification la glande pinéale qui est l’un des éléments corporels permettant la reliance au spirituel, il est nécessaire, certes d’utiliser des dentifrices sans fluor comme ceux à l’argile mais également de porter des lunettes spécial écran d’ordinateur afin de réduire la réception de la lumière bleue.
Website Setting up Homepage Layout Part-1 | Learning Freelancing Skill For Course |
Thank you for your subscription and for visiting here.
Love from Nouman Sabir ❤️️
Hi, I’m Nouman Sabir , a freelance developer having 2.5 years of experience. I’m a top-rated developer at Upwork and earned more than $100K through freelancing. My goal is to enable you to earn at least 1000 Dollars per month Every people in Pakistan Inshallah . Subscribe to learn and earn.
[ English subtitles are added in all videos for guys who don’t understand Urdu or Hindi ]
Kindly subscribe this channal and don’t forget to click bell icon ,
Contact for paid promotions, sponsorships, and integrations by email
Best Regards,
Nouman Sabir
Facebook : https://www.facebook.com/nouman.sabir.777/
Instagram : Noumansabir13121995
1) Agar Kisi ko course me kisi bhi software ya tools ke liye koi information chaiye ho tu wo rabta kar sakhta hai our us ko
support kiya jai ga inshallah
2) Freelancing ya kisi bhi webside ko use karne me koi bhi issue ho us ke liye bhi ap mare se rabta kar sakhte hai
Jazakallah Khair
Disclaimer :
Video is for educational purpose only Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research Fair use is a use permitted by copyright statute that might otherwise be infringing Non-profit, educational or personal use tips the balance in favor of fair use.
Some photos in the video are downloaded from Google Image. Picture used in this video is protected by the Fair Use Law, section 107 used for commentary, criticism, news reporting or education for transformative use
Video Title : Website Setting up Homepage Layout Part-1 | Learning Freelancing Skill For Course |
Keywords :
#AmazonJungle
#Amazonaffiliatemarkrting
#Amazonfba
#Amazondropshipping
#Amazonproducts
#Amazoncourse
#Ecommercebusiness
#Amazonprimevideo
#Amazonsellarforbeginners
#Amazonfbaforbeginners
#Ecommeracestore
#Ecommercebusinessforbeginners
#Ecommarecewebsitewordpress
#Ecommercemarketing
#Ecommercewebsitehtmlcssjavacript
#Digitalmarketingcourse
#Graphicdesigncourse
#wordpresscourse
#autocadcourse
#digiskills.pk
#digiskillfreecourses
#LearningfreelancingSkillsforcourse
#SEOcourse
#topfreelancingskills
#makemoneyonline
#onlineworkhomebasic
#foryou
#Affiliatemarketing
#keeparesults
#Producthunting
#AmazonStore
#ChatGPT
#AIGPT