Last active
January 18, 2023 13:56
-
-
Save tomas-stefano/fa46e26b5778ec1f7030 to your computer and use it in GitHub Desktop.
Revisions
-
tomas-stefano revised this gist
Jun 27, 2017 . No changes.There are no files selected for viewing
-
tomas-stefano revised this gist
Jun 27, 2017 . 1 changed file with 1 addition and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class Check def run if files.empty? puts "Diff does not contain relevant files. \033[0;33m [SKIPPED]\e[0m" true else run_command end -
tomas-stefano renamed this gist
Jun 16, 2017 . 1 changed file with 2 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ ## Pre-commit hook This is a pre-commit script that will see the git diff and run the appropriate checks like JSHint and Rubocop You can add to your `.git/hooks` of any repo that you like. -
tomas-stefano revised this gist
Jun 16, 2017 . 1 changed file with 6 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,12 @@ This is a pre-commit script that will see the git diff and run the appropriate c You can add to your `.git/hooks` of any repo that you like. ## Notes 1) Don't forget to add the executable permission to this file and have the following installed: * Git * Rubocop * JShint 2) This script will only run on "Changes to be committed" because it uses the --cached option for the git diff. -
tomas-stefano revised this gist
Jun 16, 2017 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ This is a pre-commit script that will see the git diff and run the appropriate checks like JSHint and Rubocop You can add to your `.git/hooks` of any repo that you like. -
tomas-stefano revised this gist
Jun 16, 2017 . 1 changed file with 9 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ This is a pre-commit script You can add to your `.git/hooks` of any repo that you like. Don't forget to add the executable permission to this file and have the following installed: * Git * Rubocop * JShint -
tomas-stefano created this gist
Jan 13, 2015 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,124 @@ #!/usr/bin/env ruby class GitDiff attr_reader :filenames def initialize @filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n") end end class Check attr_reader :diff, :exit_status, :files def initialize(diff) @diff = diff end def check before_run puts "Running \033[1;34m#{self.class}#check\e[0m: #{command}" report_error unless run after_run end def before_run end def after_run end def files @files ||= Array(diff.filenames) end def run if files.empty? puts "Diff does not contain relevant files. \033[0;33m [SKIPPED]\e[0m" else run_command end end def run_command system(command) end def command raise NotImplementedError end def report_error raise NotImplementedError end private def select_files(extension:) @files = diff.filenames.select { |filename| File.extname(filename) == ".#{extension}" } end end class Keywords < Check BAD = %w( binding.pry throw console.log debugger ) def run_command result = `#{command}` puts result report_error unless result.empty? result.empty? end def command %(git diff --cached -G"#{BAD.join('|')}" #{files.join(' ')}) end def report_error puts "There are files that contain this keywords: #{BAD.join(', ')}.\n" exit 1 end end class Rubocop < Check def before_run @files = select_files(extension: :rb) end def command "rubocop #{files.join(' ')}" end def report_error puts "Rubocop reported some offenses. Aborting commit" exit 1 end end class JSHint < Check def before_run @files = select_files(extension: :js) end def command "jshint #{files.join(' ')}" end def report_error end end diff = GitDiff.new [ Keywords, Rubocop, JSHint ].each do |klass| klass.new(diff).check end