From 3a0298a124506da43d94086071df4c738ceec64e Mon Sep 17 00:00:00 2001 From: Alexander Berezovsky Date: Fri, 9 Aug 2019 19:33:28 -0700 Subject: [PATCH 1/2] Add GinkgoFocus This hook warn about focused ginkgo tests left in the code --- config/default.yml | 7 ++++++ .../hook/pre_commit/ginkgo_focus.rb | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/overcommit/hook/pre_commit/ginkgo_focus.rb diff --git a/config/default.yml b/config/default.yml index 233f77fc..216a963e 100644 --- a/config/default.yml +++ b/config/default.yml @@ -330,6 +330,13 @@ PreCommit: quiet: true branch_patterns: ['master'] + GinkgoFocus: + enabled: false + description: 'Check for "token" strings' + required_executable: 'grep' + flags: ['-IEHnw'] + keywords: ['FContext','FDescribe','FIt','FMeasure','FSpecify','FWhen'] + GoLint: enabled: false description: 'Analyze with golint' diff --git a/lib/overcommit/hook/pre_commit/ginkgo_focus.rb b/lib/overcommit/hook/pre_commit/ginkgo_focus.rb new file mode 100644 index 00000000..8528926e --- /dev/null +++ b/lib/overcommit/hook/pre_commit/ginkgo_focus.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Overcommit::Hook::PreCommit + # Check for "focused" tests + class GinkgoFocus < Base + def run + keywords = config['keywords'] + result = execute(command, args: [keywords.join('|')] + applicable_files) + + extract_messages( + result.stdout.split("\n"), + /^(?(?:\w:)?[^:]+):(?\d+)/, + lambda { |_type| :warning } + ) + end + + def applicable_test_files + applicable_files.select do |f| + f if f =~ /_test\.go/ + end + end + end +end From 3473f70c359a6a3cf1561d6deec0bc6e7b52afb4 Mon Sep 17 00:00:00 2001 From: Alexander Berezovsky Date: Fri, 9 Aug 2019 19:36:45 -0700 Subject: [PATCH 2/2] Update copy --- config/default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/default.yml b/config/default.yml index 216a963e..02777c7e 100644 --- a/config/default.yml +++ b/config/default.yml @@ -332,7 +332,7 @@ PreCommit: GinkgoFocus: enabled: false - description: 'Check for "token" strings' + description: 'Check for "focused" tests' required_executable: 'grep' flags: ['-IEHnw'] keywords: ['FContext','FDescribe','FIt','FMeasure','FSpecify','FWhen']