Skip to content

Commit c80ad2a

Browse files
committed
Compares rules across files
Previously some comparisons were dropped due to minimums within a file refs: zmoazeni#16
1 parent 236552e commit c80ad2a

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* --compass now grabs config.rb by default if it exists
1111
* Adds --compass-with-config that lets users specify a config
1212
* Fixes parser error bug when trying to parse blank files
13+
* Fixes bug where rules from multiple files aren't consolidated
1314

1415
## 1.0.0 - 4/7/2013 ##
1516

lib/csscss/cli.rb

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def run
1818
def execute
1919
warn_old_debug_flag if ENV["CSSCSS_DEBUG"]
2020

21-
all_redundancies = @argv.map do |filename|
22-
contents = if %w(.scss .sass).include?(File.extname(filename).downcase) && !(filename =~ URI.regexp)
21+
all_contents = @argv.map do |filename|
22+
if %w(.scss .sass).include?(File.extname(filename).downcase) && !(filename =~ URI.regexp)
2323
begin
2424
require "sass"
2525
rescue LoadError
@@ -41,35 +41,23 @@ def execute
4141
else
4242
open(filename) {|f| f.read }
4343
end
44+
end.join("\n")
4445

45-
if contents.strip.empty?
46-
{}
47-
else
48-
RedundancyAnalyzer.new(contents).redundancies(
49-
minimum: @minimum,
50-
ignored_properties: @ignored_properties,
51-
ignored_selectors: @ignored_selectors
52-
)
53-
end
54-
end
46+
unless all_contents.strip.empty?
47+
redundancies = RedundancyAnalyzer.new(all_contents).redundancies(
48+
minimum: @minimum,
49+
ignored_properties: @ignored_properties,
50+
ignored_selectors: @ignored_selectors
51+
)
5552

56-
combined_redundancies = all_redundancies.inject({}) do |combined, redundancies|
57-
if combined.empty?
58-
redundancies
53+
if @json
54+
puts JSONReporter.new(redundancies).report
5955
else
60-
combined.merge(redundancies) do |_, v1, v2|
61-
(v1 + v2).uniq
62-
end
56+
report = Reporter.new(redundancies).report(verbose:@verbose, color:@color)
57+
puts report unless report.empty?
6358
end
6459
end
6560

66-
if @json
67-
puts JSONReporter.new(combined_redundancies).report
68-
else
69-
report = Reporter.new(combined_redundancies).report(verbose:@verbose, color:@color)
70-
puts report unless report.empty?
71-
end
72-
7361
rescue Parslet::ParseFailed => e
7462
line, column = e.cause.source.line_and_column(e.cause.pos)
7563
puts "Had a problem parsing the css at line: #{line}, column: #{column}".red

0 commit comments

Comments
 (0)