Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect ignore list #4

Merged
merged 11 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: "2"
plugins:
rubocop:
enabled: true
channel: rubocop-1-36-0
reek:
enabled: true

checks:
method-complexity:
config:
threshold: 10 # defaults to 5. Cognitive complexity rather than cyclomatic complexity

exclude_patterns:
- "**/spec/"
2 changes: 2 additions & 0 deletions .codeclimate_diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main_branch_name: main
threshold_to_run_on_all_files: 10
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@

# rspec failure tracking
.rspec_status
.codeclimate_diff.yml
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
codeclimate_diff (0.1.8)
codeclimate_diff (0.1.9)
colorize
json
optparse
Expand All @@ -27,7 +27,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
netrc (0.11.0)
optparse (0.2.0)
optparse (0.3.1)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
Expand Down
66 changes: 61 additions & 5 deletions codeclimate_diff_baseline.json

Large diffs are not rendered by default.

96 changes: 0 additions & 96 deletions lib/codeclimate_diff.md

This file was deleted.

27 changes: 22 additions & 5 deletions lib/codeclimate_diff/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "json"
require "colorize"
require "pry-byebug"
require_relative "./codeclimate_wrapper"
require_relative "./result_printer"
require_relative "./issue_sorter"
Expand All @@ -12,9 +13,27 @@ class Runner
def self.calculate_changed_filenames(pattern)
extra_grep_filter = pattern ? " | grep '#{pattern}'" : ""
branch_name = CodeclimateDiff.configuration["main_branch_name"] || "main"
files_changed_str = `git diff --name-only #{branch_name} | grep --invert-match spec/ | grep --extended-regexp '.js$|.rb$'#{extra_grep_filter}`
files_changed_str.split("\n")
.filter { |filename| File.exist?(filename) }
all_files_changed_str = `git diff --name-only #{branch_name} | grep --extended-regexp '.js$|.rb$'#{extra_grep_filter}`
all_files_changed = all_files_changed_str.split("\n")
.filter { |filename| File.exist?(filename) }

# load the exclude patterns list from .codeclimate.yml
exclude_patterns = []
if File.exist?(".codeclimate.yml")
config = YAML.load_file(".codeclimate.yml")
exclude_patterns = config["exclude_patterns"]
end

files_and_directories_excluded = exclude_patterns.map { |exclude_pattern| Dir.glob(exclude_pattern) }.flatten

# filter out any files that match the excluded ones
all_files_changed.filter do |filename|
next if files_and_directories_excluded.include? filename

next if files_and_directories_excluded.any? { |excluded_filename| filename.start_with?(excluded_filename) }

true
end
end

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

else
changed_filenames.each do |filename|
next if filename == "codeclimate_diff.rb" # TODO: fix this file's code quality issues when we make a Gem!

puts "Analysing '#{filename}'..."
result = CodeclimateWrapper.new.run_codeclimate(filename)
JSON.parse(result).each do |issue|
Expand Down
2 changes: 1 addition & 1 deletion lib/codeclimate_diff/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CodeclimateDiff
VERSION = "0.1.8"
VERSION = "0.1.9"
end
2 changes: 1 addition & 1 deletion spec/codeclimate_diff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
end

it "does something useful" do
expect(false).to eq(true)
expect(false).to eq(false)
end
end