178 வாசிப்புகள்

உங்கள் முதல் பாதுகாப்பு வரி Clean Code is Pre-Commit: How to Set It Up

மூலம் Alexandre Couedelo8m2025/07/06
Read on Terminal Reader

மிக நீளமானது; வாசிப்பதற்கு

முன்பே ஏற்றப்பட்ட (preloaded) Multi-Turbo மற்றும் Ultra Game Mode ஆகியவை உள்ளன.அதனால ஏற்ற (preloaded) Multi-Turbo மற்றும் Ultra Game Mode ஆகியவை உள்ளன.
featured image - உங்கள் முதல் பாதுகாப்பு வரி Clean Code is Pre-Commit: How to Set It Up
Alexandre Couedelo HackerNoon profile picture

எப்போதும் தவறாக ஒரு பதிவிறக்கத்தில் அறிகுறிகள் அழுத்தினீர்களா? அல்லது ஒருவேளை நீங்கள் அழுத்தப்படாத குறியீடுகளை அழுத்தினீர்களா, ஒரு பின்னூட்டத்தை உருவாக்க வேண்டும்? நாங்கள் அனைவரும் அங்கு இருந்தோம்.


Git Hooks இந்த பிரச்சினைகளை நிறுத்த ஒரு சக்திவாய்ந்த கருவியாகும், நீங்கள் ஒப்புக்கொள்வதற்கு முன்பாக அல்லது அணுகுவதற்கு முன் ஸ்கிரிப்டை இயக்கவும்.


Pre-commit is an easy-to-use framework for managing and sharing multi-language git hooks, help you catch issues before they even leave your workstation.

முதலீடு: சரியான அமைப்பு

Pre-commit ஐ பயன்படுத்தும் முன், நீங்கள் அதை நிறுவ மற்றும் உங்கள் திட்டங்களுக்கு அமைக்க வேண்டும்.

நிறுவல்

நீங்கள் pre-commit பயன்படுத்த பல வழிகள் உள்ளன:

  • macOS மற்றும் Linux:
brew install pre-commit
  • Python/Pip (எழுத்துப் பொருட்கள்):
pip install pre-commit
  • Other Methods: For installations using Conda or on Windows, please refer to the Official Documentation.
Official பதிவுகள்

Project-Specific Setup (Standard Way) – திட்டமிட்ட அமைப்பு

இது ஒரு குறிப்பிட்ட திட்டத்தில் pre-commit ஐ அனுமதிப்பதற்கான மிகப்பெரிய வழிமுறை:

  1. Create a Configuration File: In the root of your repository, create a file named .pre-commit-config.yaml. This file will define the hooks pre-commit should run. (We’ll cover how to populate this file in the next section).


  2. Install Hooks: Navigate to your repository’s root directory in your terminal and run:

pre-commit install
  1. இந்த ஆவணத்தில் git hooks உங்கள் பதிவிறக்கத்தின் .git/hooks பதிவிறக்கத்தில் நிறுவப்படுகிறது. இப்போது இருந்து, pre-commit நீங்கள் இந்த குறிப்பிட்ட பதிவிறக்கத்தில் செய்ய ஒவ்வொரு ஆவணத்திற்கு முன் தங்கள் கண்காணிப்புகளை தானாக இயங்குகிறது.

Global Setup (Set It and Forget It) (இதை அமைக்கவும் அதை மறக்கவும்)

நீங்கள் பெரும்பாலும் புதிய திட்டங்களை தொடங்குகிறீர்களா அல்லது குளிர்பானங்களை கிளிக் செய்கின்றீர்களா, மேலும் pre-commit இலவசமாக செயல்பட வேண்டும் (ஒரு அமைப்பு இருந்தால்), நீங்கள் அதை உலகம் முழுவதும் அமைக்கலாம்.This method uses Git's pre-commit.init.templateDirஅடையாளம்


  1. A Configuration File: All your repository must have a .pre-commit-config.yaml. This file will define the hooks that pre-commit should run. The best would be to use a template repository with a minimal pre-commit file.


  2. Configure Git’s Template Directory: Tell Git to use a specific directory as a template for new repositories:

git config --global init.templateDir ~/.git-template

(நீங்கள் விரும்பினால் வேறு ஒரு பதிவிறக்கத்தை தேர்வு செய்யலாம், அதனை அடுத்த படி உறுதி செய்யவும்.)


Pre-commit in the Template Directory: பின்வருமாறு கூறுங்கள்:

pre-commit init-templatedir ~/.git-template

(முந்தைய கட்டத்தில் நீங்கள் வேறு ஒரு தலைப்பை தேர்வு செய்தால், மாற்றவும்~/.git-templateஎனவே )


இந்த மாதிரி think different type விளம்பரங்கள் தான் add industriesla இப்போ Hot...git initஅதாவது, ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர், ஒரு கம்ப்யூட்டர் ஆகியவை உள்ளன..pre-commit-config.yamlfile, pre-commit எதையும் செய்யாது, எனவே அது உலகம் முழுவதும் திறக்க பாதுகாப்பானது.


எனினும், I like to go one step further by adding a default hook என்பதால்~/.git-template/hooks/pre-commitஇது ஒரு கடினமான கடினமாக இருந்தால் ஒரு கடினமான கடினமாக இருக்கும்..pre-commit-config.yamlHere is the content of the ஹோட்டல்.

#!/usr/bin/env bash
if [ -f .pre-commit-config.yaml ]; then
    echo 'pre-commit configuration detected, but `pre-commit install` was never run' 1>&2
    exit 1
fi

உங்கள் நிறுவல் உருவாக்க (.pre-commit-config.yaml)

முன்மொழிந்து , வழிமொழிந்துவிட்டால் அதற்குத்தானே first priority..pre-commit-config.yamlஇந்த கோப்பு, உங்கள் பதிவிறக்கத்தின் root இல் வைக்கப்படுகிறது, முன்பதிவு செயற்பாடுகளை சரிசெய்யும் என்று கூறுகிறது.

# https://github.com/xNok/infra-bootstrap-tools/blob/main/.pre-commit-config.yaml
repos:
  # Lint all yam files
  - repo: https://github.com/adrienverge/yamllint.git
    rev: v1.29.0
    hooks:
      - id: yamllint
  # Runs Ansible lint
  - repo: https://github.com/ansible/ansible-lint
    rev: v24.7.0
    hooks:
      - id: ansible-lint
        args:
          - "ansible"
        additional_dependencies:
          - ansible

தெளிவுபடுத்தப்பட்ட Core Structure

ஒரு சாதாரண அமைப்பு ஒரு பட்டியலை சேர்க்கிறது repositories, each with specific hooks:

  • Repos: இது Repository mappings list ஆகும்.Each item in the list specifies a Git repository that contains pre-commit hooks.


  • Repo: The URL of the repository hosting the hooks (e.g., https://github.com/pre-commit/pre-commit-hooks). இந்த ஒரு மிகவும் அழகான வழி அறுவை சிகிச்சை. நீங்கள் கருவி பற்றி மேலும் தெரியும் போது, நீங்கள் அறுவை சிகிச்சை செல்ல முடியும்.


  • Rev: இது ஒரு Git டேக், SHA, அல்லது பிளாஸ்டிக் க்கான pining மூலம் பயன்படுத்தப்படும் ஹாக்கின் பதிப்பை குறிப்பிடுகிறது.ஆனால், remote repository updates போது உங்கள் linting எதிர்பாராத அளவில் அழிவதில்லை என்று உறுதிப்படுத்துவதற்காக எப்போதும் ஒரு குறிப்பிட்ட பிளாஸ்டிக் அல்லது SHA (Master போன்ற ஒரு பிளாஸ்டிக் அல்ல) பயன்படுத்த வேண்டும்.


  • ஒவ்வொரு விலையிலும், ஒவ்வொரு விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த விலையுயர்ந்த


  • id: ஒருங்கிணைந்த அடையாளக் குறியீடு (e.g., trailing-whitespace, check-yaml). you can find available hook IDs in the hook repository documentation. or simply the .pre-commit-hooks.yaml at the repo's root.

முதலாளித்துவ அமைப்பு

இதோ ஒரு basic.pre-commit-config.yamlஇந்த வகையில், நான் நீங்கள் Github இல் செல்ல வேண்டும் மற்றும் ஒரு பார்வை வேண்டும் என்று பரிந்துரைக்கிறேன்Pre-Commit-Hooks / Pre-Commit-Hooks / Pre-Commit-Hooks / Pre-Commit-HooksThis is the list of simple hooks that thepre-commitஅணியும், அணியும் எங்கே கிடைக்கும்idநீங்கள் பயன்படுத்த விரும்பும் ஒவ்வொரு பொருட்கள்.

Pre-Commit-Hooks / Pre-Commit-Hooks / Pre-Commit-Hooks / Pre-Commit-Hooks


நான் சொல்வேன்trailing-whitespaceமற்றும்end-of-file-fixerஉண்மையில் இது மிகவும் பயனுள்ளதாக இருக்கும், எனவே அமைப்பு அப்படி இருக்கும்.

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0  # Check for the latest stable version on the pre-commit-hooks repo!
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
# Add other repositories and their specific hooks below
# -   repo: ...
#     rev: ...
#     hooks:
#     -   id: ...

ஆங்கிலத்தில் இதை Single Orgasm, Multiple Orgasm என்றும் கூறுகிறார்கள்.pre-commit-hooksநீங்கள் பயன்படுத்தும் மற்ற ஹேக் ஹேக் ஹேக் (or any other hook repositories you use) for the latest stable version tag andrevஅல்லது Renovate அல்லது Dependabot போன்ற வடிவமைப்புகளை அமைக்க, அவற்றை நேரடியாக புதுப்பிக்க வேண்டும்.


You can find a large list of pre-existing hooks on the அட்டவணைPre-Commit வலைப்பதிவுஉங்கள் பின்னூட்டத்திற்கு நன்றி.Anonymous: If you remove black money from India, our country will be really a super power..pre-commit-hooks.yamlஹோட்டல்கள் கிடைக்கும் என்று பாருங்கள்.

Pre-Commit வலைப்பதிவு

Pre-Commit பயன்படுத்தும் போது தெரிந்து கொள்ள நல்லது

ஒருமுறை நீங்கள் அடிப்படைகள் சுலபமாக இருந்தால், pre-commit உங்கள் வேலையை நன்றாக அமைக்க மேம்பட்ட அம்சங்களை வழங்குகிறது.

கையெழுத்து Hooks Manual

ஹோஸ்டிங் களை automatically run ongit commit, நீங்கள் மற்ற நேரங்களில் அவற்றை கையாள விரும்பலாம்:

  • ஒரு குறிப்பிட்ட ஹேக் இயக்க: ஒரே ஒரு ஹேக் இயக்க (பின்னர், அதன் அமைப்பை சோதிக்க அல்லது மாற்றங்களை செயல்படுத்தாமல்), பயன்படுத்தவும்:
pre-commit run <hook_id>


மாற்று<hook_id>உண்மையான ID உங்கள் அமைப்பு கோப்பு இருந்து.)

  • அனைத்து கோப்புகளில் இயக்க: உங்கள் சேவையில் ஒவ்வொரு கண்காணிக்கப்பட்ட கோப்புகளுக்கும் அனைத்து அமைக்கப்பட்ட ஹேக்களை இயக்கவும் (தொடர்பான மாற்றங்கள் அல்ல), பயன்படுத்தவும்:
pre-commit run --all-files


இது ஒரு முதலாவது சுத்தம் அல்லது ஒரு உள்ளடக்கமான திட்டத்தில் புதிய ஹேக் சேர்க்கும் போது உதவுகிறது.

உங்களுடைய Local Hooks உருவாக்க

சில நேரங்களில், நீங்கள் ஒரு Public Hook Repository ஒரு பகுதியாக இல்லை ஒரு திட்ட பொருத்தமான ஸ்கிரிப்டுகள் அல்லது சோதனைகள் இருக்கலாம்.Pre-commit நீங்கள் "Local" Hooks அமைக்க அனுமதிக்கிறது.

  1. உங்கள் பதிவிறக்கத்தில் உங்கள் பதிவிறக்கத்தை உருவாக்கவும்: உங்கள் பதிவிறக்கத்தில் உங்கள் பதிவிறக்கத்தை உருவாக்கவும் (எனவே, ஒரு shell பதிவிறக்க, Python பதிவிறக்க).For this example, let's say you create my_custom_script.sh.
  2. முன்பே ஏற்றப்பட்ட (preloaded) Multi-Turbo மற்றும் Ultra Game Mode ஆகியவை உள்ளன.
# .pre-commit-config.yaml
-   repo: local
    hooks:
    -   id: my-custom-check
        name: My custom check
        entry: ./my_custom_script.sh # Path to your script
        language: script             # Or python, node, etc.
        files: \.(py)$               # Example: regex to run only on Python files
        # verbose: true              # Uncomment for more output
        # args: [--custom-arg]       # Optional arguments for your script

Pre-commit to Run என்று சொல்வார்கள்.my_custom_script.shபிக்பாஸ் மாற்றங்கள் (.pyபதிவுகள் - Thelanguage: scriptType is very flexible; for specific environments such as Python or Node, you can specify those to manage dependencies if needed.bashஹோக்


முன்பே ஏற்றப்பட்ட (preloaded) Multi-Turbo மற்றும் Ultra Game Mode ஆகியவை உள்ளன.


அனைத்து ஹேக், ஆச்சரியமாக, அறுவை சிகிச்சை அம்சத்தை பயன்படுத்தி இல்லை, மற்றும் நீங்கள் ஹேக் இயக்க முடியும் வரை உங்களால் கருவிகளை நிறுவ வேண்டும் (நான் Terraform பற்றி நினைக்கிறேன், உதாரணமாக)

Pre-Commit in a Team மற்றும் CI / CD Environment இல்

ஒரு முதியவன் பாதாளங்களைத் தாண்டும் தன் மந்திரக்கோலால் சாய்த்தபடியிருக்கிறான் நாட்சத்திரங்களை. .............................................................................................................................................................................. இது எத்தனையாவது [...]git commit --no-verify) அல்லது ஒரு பழைய ஹேக் அமைப்பு வேண்டும்.உங்கள் CI / CD pipeline முடிந்த gatekeeper செயல்பட முடியும்.


உங்களுடைய வலைத்தளத்தில் pre-commit checks ஐ இயங்குவதன் மூலம், உங்கள் திட்டத்தின் தரவுகளைப் பொறுத்தவரை எந்த குறியீடுகளும் இணைக்கப்படவில்லை என்பதை நீங்கள் உறுதி செய்யலாம்.

pre-commit run --all-files


இந்த கட்டுரையில், மாற்றப்பட்ட கோப்புகளைத் தவிர்க்கவும், Repository உள்ள அனைத்து கோப்புகளை சரிபார்க்கவும், முழுமையான சான்றிதழ் வழங்கும்.


CI pipeline step (e.g., GitHub Actions) என்பதன் பொருள்:

# Example for a GitHub Actions workflow
# ... (other steps like checkout, setup python/node, etc.)
- name: Install pre-commit and dependencies
  run: |
    pip install pre-commit
    # Install any other dependencies your hooks might need (e.g., linters)
    # This might be minimal if your hooks install their own dependencies (common).
- name: Run pre-commit checks
  run: pre-commit run --all-files


எந்த CI அமைப்புடன் வேலை செய்கிறது ஒரு புரிதலான pipeline வேண்டும், ஆனால் நீங்கள் GitHub நடவடிக்கைகளை பயன்படுத்தினால், நீங்கள் கவலைப்பட தேவையில்லை; பயன்படுத்தOfficial நடவடிக்கை.

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-python@v3
    - uses: pre-commit/action@v3.0.1


வெப்பநிலை ஆட்சி 0 முதல் 40 டிகிரி செல்சியஸ் வரை இருக்க வேண்டும்; per month As its name suggests, a VPN is about privacy.

முடிவு

அங்கு புரிந்துநீஇந்த மாதிரி think different type விளம்பரங்கள் தான் add industriesla இப்போ Hot...pre-commitஉங்கள் workflow மாற்றங்கள்


Whitespace errors மற்றும் secret detection, code formatting மற்றும் linting இல் இருந்து எல்லாவற்றையும் கண்காணித்தல் மூலம், pre-commit உங்கள் குறியீட்டின் தரத்தை உள்நாட்டு பாதுகாவலனாக செயல்படுகிறது, இது ஒரு முடிவான தரத்தைப் பெறுவதற்காக CI / CD pipelines இல் "விரைவாக" இணைக்க முடியும்.

Trending Topics

blockchaincryptocurrencyhackernoon-top-storyprogrammingsoftware-developmenttechnologystartuphackernoon-booksBitcoinbooks