Skip to content

Commit 710c367

Browse files
Merge pull request #4 from boost/respect-ignore-list
Respect ignore list
2 parents 8d4b1e9 + 6c27935 commit 710c367

File tree

9 files changed

+105
-111
lines changed

9 files changed

+105
-111
lines changed

.codeclimate.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
version: "2"
3+
plugins:
4+
rubocop:
5+
enabled: true
6+
channel: rubocop-1-36-0
7+
reek:
8+
enabled: true
9+
10+
checks:
11+
method-complexity:
12+
config:
13+
threshold: 10 # defaults to 5. Cognitive complexity rather than cyclomatic complexity
14+
15+
exclude_patterns:
16+
- "**/spec/"

.codeclimate_diff.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main_branch_name: main
2+
threshold_to_run_on_all_files: 10

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99

1010
# rspec failure tracking
1111
.rspec_status
12-
.codeclimate_diff.yml

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
codeclimate_diff (0.1.8)
4+
codeclimate_diff (0.1.9)
55
colorize
66
json
77
optparse
@@ -27,7 +27,7 @@ GEM
2727
mime-types-data (~> 3.2015)
2828
mime-types-data (3.2022.0105)
2929
netrc (0.11.0)
30-
optparse (0.2.0)
30+
optparse (0.3.1)
3131
parallel (1.22.1)
3232
parser (3.1.2.1)
3333
ast (~> 2.4.1)

codeclimate_diff_baseline.json

Lines changed: 61 additions & 5 deletions
Large diffs are not rendered by default.

lib/codeclimate_diff.md

Lines changed: 0 additions & 96 deletions
This file was deleted.

lib/codeclimate_diff/runner.rb

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "json"
44
require "colorize"
5+
require "pry-byebug"
56
require_relative "./codeclimate_wrapper"
67
require_relative "./result_printer"
78
require_relative "./issue_sorter"
@@ -12,9 +13,27 @@ class Runner
1213
def self.calculate_changed_filenames(pattern)
1314
extra_grep_filter = pattern ? " | grep '#{pattern}'" : ""
1415
branch_name = CodeclimateDiff.configuration["main_branch_name"] || "main"
15-
files_changed_str = `git diff --name-only #{branch_name} | grep --invert-match spec/ | grep --extended-regexp '.js$|.rb$'#{extra_grep_filter}`
16-
files_changed_str.split("\n")
17-
.filter { |filename| File.exist?(filename) }
16+
all_files_changed_str = `git diff --name-only #{branch_name} | grep --extended-regexp '.js$|.rb$'#{extra_grep_filter}`
17+
all_files_changed = all_files_changed_str.split("\n")
18+
.filter { |filename| File.exist?(filename) }
19+
20+
# load the exclude patterns list from .codeclimate.yml
21+
exclude_patterns = []
22+
if File.exist?(".codeclimate.yml")
23+
config = YAML.load_file(".codeclimate.yml")
24+
exclude_patterns = config["exclude_patterns"]
25+
end
26+
27+
files_and_directories_excluded = exclude_patterns.map { |exclude_pattern| Dir.glob(exclude_pattern) }.flatten
28+
29+
# filter out any files that match the excluded ones
30+
all_files_changed.filter do |filename|
31+
next if files_and_directories_excluded.include? filename
32+
33+
next if files_and_directories_excluded.any? { |excluded_filename| filename.start_with?(excluded_filename) }
34+
35+
true
36+
end
1837
end
1938

2039
def self.calculate_issues_in_changed_files(changed_filenames, always_analyze_all_files)
@@ -36,8 +55,6 @@ def self.calculate_issues_in_changed_files(changed_filenames, always_analyze_all
3655

3756
else
3857
changed_filenames.each do |filename|
39-
next if filename == "codeclimate_diff.rb" # TODO: fix this file's code quality issues when we make a Gem!
40-
4158
puts "Analysing '#{filename}'..."
4259
result = CodeclimateWrapper.new.run_codeclimate(filename)
4360
JSON.parse(result).each do |issue|

lib/codeclimate_diff/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CodeclimateDiff
4-
VERSION = "0.1.8"
4+
VERSION = "0.1.9"
55
end

spec/codeclimate_diff_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
end
77

88
it "does something useful" do
9-
expect(false).to eq(true)
9+
expect(false).to eq(false)
1010
end
1111
end

0 commit comments

Comments
 (0)