Skip to content

amirelemam/eslint_git_hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESlint + Git Hooks

This project has the basic config for ESLint with ES6. You can configure it to be used in combination with Git Hooks. By doing so, every time you commit changes to Git, Git Hooks will run ESLint and, if any syntax error is found, ESLint will accuse it and your changes won't be committed to the Git repository.

Instalation

For a new project

I assume you're creating a new project based on this project.

  1. Install dependencies (it must be globally)
$ npm install -g
  1. Start a git repository
$ git init
  1. Add ESLint command to the end of file .git/hooks/precommit.sample
$ echo 'eslint src' >> .git/hooks/precommit.sample
  1. Rename .git/hooks/precommit.sample to .git/hooks/precommit
$ mv .git/hooks/precommit.sample .git/hooks/precommit

For an existing project

  1. Copy .eslintrc to your project folder
$ cp .eslintrc /path/to/project/folder/
  1. Navigate to the project folder
$ cd /path/to/project/folder/
  1. Install dependencies
$ npm install -g --save eslint babel-eslint
  1. Add ESLint command to the end of file .git/hooks/precommit.sample
$ echo 'eslint src' >> .git/hooks/precommit.sample
  1. Rename .git/hooks/precommit.sample to .git/hooks/precommit
$ mv .git/hooks/precommit.sample .git/hooks/precommit

Usage

Every time you commit, git hooks will automatically run ESLint. Usual workflow:

  1. Change file /path/to/file/file.js

  2. Add file to be committed

$ git add /path/to/file/file.js
  1. Commit file
$ git commit -m "Your commit message here"

If there's any syntax error, ESLint will accuse it and won't let you commit your changes to the Git repository.

Tutorial

[Medium[(https://amirelemam.medium.com/commit-better-with-git-hooks-803a2814b36b)

License

These files are licensed under the MIT License

About

Configure ESLint + Git Hooks to prevent commit with syntax errors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published