Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Compares rules across files
Browse files Browse the repository at this point in the history
Previously some comparisons were dropped due to minimums within a file

refs: #16
  • Loading branch information
zmoazeni committed Apr 12, 2013
1 parent 236552e commit c80ad2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* --compass now grabs config.rb by default if it exists
* Adds --compass-with-config that lets users specify a config
* Fixes parser error bug when trying to parse blank files
* Fixes bug where rules from multiple files aren't consolidated

## 1.0.0 - 4/7/2013 ##

Expand Down
38 changes: 13 additions & 25 deletions lib/csscss/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def run
def execute
warn_old_debug_flag if ENV["CSSCSS_DEBUG"]

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

if contents.strip.empty?
{}
else
RedundancyAnalyzer.new(contents).redundancies(
minimum: @minimum,
ignored_properties: @ignored_properties,
ignored_selectors: @ignored_selectors
)
end
end
unless all_contents.strip.empty?
redundancies = RedundancyAnalyzer.new(all_contents).redundancies(
minimum: @minimum,
ignored_properties: @ignored_properties,
ignored_selectors: @ignored_selectors
)

combined_redundancies = all_redundancies.inject({}) do |combined, redundancies|
if combined.empty?
redundancies
if @json
puts JSONReporter.new(redundancies).report
else
combined.merge(redundancies) do |_, v1, v2|
(v1 + v2).uniq
end
report = Reporter.new(redundancies).report(verbose:@verbose, color:@color)
puts report unless report.empty?
end
end

if @json
puts JSONReporter.new(combined_redundancies).report
else
report = Reporter.new(combined_redundancies).report(verbose:@verbose, color:@color)
puts report unless report.empty?
end

rescue Parslet::ParseFailed => e
line, column = e.cause.source.line_and_column(e.cause.pos)
puts "Had a problem parsing the css at line: #{line}, column: #{column}".red
Expand Down

0 comments on commit c80ad2a

Please sign in to comment.