diff --git a/.standard.yml b/.standard.yml index 9d38ec4..4bcf6e5 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1 +1 @@ -ruby_version: 2.3 +ruby_version: 2.4 diff --git a/Rakefile b/Rakefile index bbac934..bb4ccbe 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ task default: [:spec, "standard:fix"] task :clobber_package do begin rm_r "pkg" - rescue StandardError + rescue nil end end @@ -26,10 +26,10 @@ desc "Test all Gemfiles from spec/*.gemfile" task :test_all do require "pty" require "shellwords" - cmd = "bundle update && bundle exec rake --trace" - statuses = Dir.glob("./sprockets*.gemfile").map do |gemfile| + cmd = "bundle update && bundle exec rake --trace" + statuses = Dir.glob("./sprockets*.gemfile").map { |gemfile| Bundler.with_clean_env do - env = { "BUNDLE_GEMFILE" => gemfile } + env = {"BUNDLE_GEMFILE" => gemfile} warn "Testing #{File.basename(gemfile)}:" warn " export BUNDLE_GEMFILE=#{gemfile}" warn " #{cmd}" @@ -44,7 +44,7 @@ task :test_all do end [$CHILD_STATUS&.exitstatus&.zero?, gemfile] end - end + } failed = statuses.reject(&:first).map(&:last) if failed.empty? warn "✓ Tests pass with all #{statuses.size} gemfiles" diff --git a/autoprefixer-rails.gemspec b/autoprefixer-rails.gemspec index d87ea5f..98e1f26 100644 --- a/autoprefixer-rails.gemspec +++ b/autoprefixer-rails.gemspec @@ -3,22 +3,22 @@ require File.expand_path("lib/autoprefixer-rails/version", __dir__) Gem::Specification.new do |s| - s.platform = Gem::Platform::RUBY - s.name = "autoprefixer-rails" - s.version = AutoprefixerRails::VERSION.dup - s.date = Time.now.strftime("%Y-%m-%d") - s.summary = "Parse CSS and add vendor prefixes to CSS rules using " \ + s.platform = Gem::Platform::RUBY + s.name = "autoprefixer-rails" + s.version = AutoprefixerRails::VERSION.dup + s.date = Time.now.strftime("%Y-%m-%d") + s.summary = "Parse CSS and add vendor prefixes to CSS rules using " \ "values from the Can I Use website." s.files = Dir["{lib,vendor}/**/*", "LICENSE", "CHANGELOG.md", "README.md"] s.extra_rdoc_files = ["README.md", "LICENSE", "CHANGELOG.md"] - s.require_path = "lib" + s.require_path = "lib" s.required_ruby_version = ">= 2.4" - s.author = "Andrey Sitnik" - s.email = "andrey@sitnik.ru" + s.author = "Andrey Sitnik" + s.email = "andrey@sitnik.ru" s.homepage = "https://github.com/ai/autoprefixer-rails" - s.license = "MIT" + s.license = "MIT" s.add_dependency "execjs", "~> 2" diff --git a/lib/autoprefixer-rails.rb b/lib/autoprefixer-rails.rb index 1985cd6..ca12f5a 100644 --- a/lib/autoprefixer-rails.rb +++ b/lib/autoprefixer-rails.rb @@ -10,9 +10,9 @@ def self.process(css, opts = {}) params = {} params[:overrideBrowserslist] = opts.delete(:overrideBrowserslist) if opts.key?(:overrideBrowserslist) params[:browsers] = opts.delete(:browsers) if opts.key?(:browsers) - params[:cascade] = opts.delete(:cascade) if opts.key?(:cascade) - params[:remove] = opts.delete(:remove) if opts.key?(:remove) - params[:env] = opts.delete(:env) if opts.key?(:env) + params[:cascade] = opts.delete(:cascade) if opts.key?(:cascade) + params[:remove] = opts.delete(:remove) if opts.key?(:remove) + params[:env] = opts.delete(:env) if opts.key?(:env) processor(params).process(css, opts) end diff --git a/lib/autoprefixer-rails/processor.rb b/lib/autoprefixer-rails/processor.rb index 20600ce..5b07536 100644 --- a/lib/autoprefixer-rails/processor.rb +++ b/lib/autoprefixer-rails/processor.rb @@ -55,14 +55,14 @@ def info # Parse Browserslist config def parse_config(config) - sections = { "defaults" => [] } - current = "defaults" + sections = {"defaults" => []} + current = "defaults" config.gsub(/#[^\n]*/, "") - .split(/\n/) - .map(&:strip) - .reject(&:empty?) - .each do |line| - if IS_SECTION =~ line + .split(/\n/) + .map(&:strip) + .reject(&:empty?) + .each do |line| + if IS_SECTION.match?(line) current = line.match(IS_SECTION)[1].strip sections[current] ||= [] else @@ -76,16 +76,16 @@ def parse_config(config) def params_with_browsers(from = nil) from ||= if defined?(Rails) && Rails.respond_to?(:root) && Rails.root - Rails.root.join("app/assets/stylesheets").to_s - else - "." - end + Rails.root.join("app/assets/stylesheets").to_s + else + "." + end params = @params if !params.key?(:browsers) && !params.key?(:overrideBrowserslist) && from file = find_config(from) if file - env = params[:env].to_s || "development" + env = params[:env].to_s || "development" config = parse_config(file) params = params.dup params[:overrideBrowserslist] = (config[env] || config["defaults"]) @@ -100,7 +100,7 @@ def convert_options(opts) converted = {} opts.each_pair do |name, value| - if /_/ =~ name + if /_/.match?(name) name = name.to_s.gsub(/_\w/) { |i| i.delete("_").upcase }.to_sym end value = convert_options(value) if value.is_a? Hash @@ -131,28 +131,32 @@ def find_config(file) def runtime @runtime ||= begin ExecJS.compile(build_js) - rescue ExecJS::RuntimeError - # Only complain about unsupported runtimes when it failed to parse our script. - - case ExecJS.runtime - when ExecJS::Runtimes::Node - node_command = ExecJS.runtime.send(:binary) rescue "Unknown" - - raise <<~MSG - Your nodejs binary failed to load autoprefixer script file, - please check if you're running a supported version (10, 12, 14+) - - ENV["PATH"] = #{ENV["PATH"]} - binary = #{node_command} - MSG - when *SUPPORTED_RUNTIMES - raise - else - raise <<~MSG - Your ExecJS runtime #{ExecJS.runtime.name} isn't supported by autoprefixer-rails, - please switch to #{SUPPORTED_RUNTIMES.map(&:name).join(' or ')} - MSG - end + rescue ExecJS::RuntimeError + # Only complain about unsupported runtimes when it failed to parse our script. + + case ExecJS.runtime + when ExecJS::Runtimes::Node + node_command = begin + ExecJS.runtime.send(:binary) + rescue + "Unknown" + end + + raise <<~MSG + Your nodejs binary failed to load autoprefixer script file, + please check if you're running a supported version (10, 12, 14+) + + ENV["PATH"] = #{ENV["PATH"]} + binary = #{node_command} + MSG + when *SUPPORTED_RUNTIMES + raise + else + raise <<~MSG + Your ExecJS runtime #{ExecJS.runtime.name} isn't supported by autoprefixer-rails, + please switch to #{SUPPORTED_RUNTIMES.map(&:name).join(" or ")} + MSG + end end end diff --git a/lib/autoprefixer-rails/result.rb b/lib/autoprefixer-rails/result.rb index 133db82..c1e1363 100644 --- a/lib/autoprefixer-rails/result.rb +++ b/lib/autoprefixer-rails/result.rb @@ -14,8 +14,8 @@ class Result def initialize(css, map, warnings) @warnings = warnings - @css = css - @map = map + @css = css + @map = map end # Stringify prefixed CSS diff --git a/lib/autoprefixer-rails/sprockets.rb b/lib/autoprefixer-rails/sprockets.rb index 02b7389..04ec974 100644 --- a/lib/autoprefixer-rails/sprockets.rb +++ b/lib/autoprefixer-rails/sprockets.rb @@ -12,7 +12,7 @@ def self.register_processor(processor) # Sprockets 3 and 4 API def self.call(input) filename = input[:filename] - source = input[:data] + source = input[:data] run(filename, source) end @@ -32,10 +32,10 @@ def self.run(filename, css) def self.install(env) if ::Sprockets::VERSION.to_f < 4 env.register_postprocessor("text/css", - ::AutoprefixerRails::Sprockets) + ::AutoprefixerRails::Sprockets) else env.register_bundle_processor("text/css", - ::AutoprefixerRails::Sprockets) + ::AutoprefixerRails::Sprockets) end end @@ -43,17 +43,17 @@ def self.install(env) def self.uninstall(env) if ::Sprockets::VERSION.to_f < 4 env.unregister_postprocessor("text/css", - ::AutoprefixerRails::Sprockets) + ::AutoprefixerRails::Sprockets) else env.unregister_bundle_processor("text/css", - ::AutoprefixerRails::Sprockets) + ::AutoprefixerRails::Sprockets) end end # Sprockets 2 API new and render def initialize(filename) @filename = filename - @source = yield + @source = yield end # Sprockets 2 API new and render diff --git a/lib/rake/autoprefixer_tasks.rb b/lib/rake/autoprefixer_tasks.rb index 4d5f8c7..ffa252d 100644 --- a/lib/rake/autoprefixer_tasks.rb +++ b/lib/rake/autoprefixer_tasks.rb @@ -13,7 +13,7 @@ class AutoprefixerTasks < Rake::TaskLib attr_reader :browsers def initialize(params = {}) - @params = params + @params = params @processor = AutoprefixerRails.processor(@params) define end diff --git a/spec/autoprefixer_spec.rb b/spec/autoprefixer_spec.rb index 4c15507..20fc303 100644 --- a/spec/autoprefixer_spec.rb +++ b/spec/autoprefixer_spec.rb @@ -44,32 +44,32 @@ end it "generates separated source map" do - result = AutoprefixerRails.process(@css, map: { inline: false }) + result = AutoprefixerRails.process(@css, map: {inline: false}) expect(result.map).to be_a(String) end it "uses file name in syntax errors", not_jruby: true do - expect do + expect { AutoprefixerRails.process("a {", from: "a.css") - end.to raise_error(/a.css:/) + }.to raise_error(/a.css:/) end it "includes sourcesContent by default" do - map = AutoprefixerRails.process("a{}", map: { inline: false }).map + map = AutoprefixerRails.process("a{}", map: {inline: false}).map expect(map).to include("sourcesContent") end it "maps options from Ruby style" do map = AutoprefixerRails.process("a{}", map: { - sources_content: false, - inline: false - }).map + sources_content: false, + inline: false + }).map expect(map).not_to include("sourcesContent") end it "does not remove old prefixes on request" do - css = "a { -moz-border-radius: 5px; border-radius: 5px }" + css = "a { -moz-border-radius: 5px; border-radius: 5px }" result = AutoprefixerRails.process(css, remove: false) expect(result.css).to eq(css) end @@ -81,16 +81,16 @@ end it "returns warnings" do - css = "a{background:linear-gradient(top,white,black)}" + css = "a{background:linear-gradient(top,white,black)}" result = AutoprefixerRails.process(css) expect(result.warnings).to eq([":1:3: Gradient has outdated " \ "direction syntax. New syntax is like `to left` instead of `right`."]) end it "shows correct error on country statistics" do - expect do + expect { AutoprefixerRails.process("", overrideBrowserslist: "> 1% in US") - end.to raise_error(/Use Autoprefixer with webpack/) + }.to raise_error(/Use Autoprefixer with webpack/) end context "Sprockets" do diff --git a/spec/processor_spec.rb b/spec/processor_spec.rb index 8e8574b..e00c5eb 100644 --- a/spec/processor_spec.rb +++ b/spec/processor_spec.rb @@ -4,12 +4,12 @@ describe AutoprefixerRails::Processor do it "parses config" do - config = "# Comment\n ie 11\n \nie 8 # sorry\n[test ]\nios 8" + config = "# Comment\n ie 11\n \nie 8 # sorry\n[test ]\nios 8" processor = AutoprefixerRails::Processor.new expect(processor.parse_config(config)).to eql({ - "defaults" => ["ie 11", "ie 8"], - "test" => ["ios 8"] - }) + "defaults" => ["ie 11", "ie 8"], + "test" => ["ios 8"] + }) end context "without Rails" do @@ -19,9 +19,9 @@ it "doesn't raise error during processing" do processor = AutoprefixerRails::Processor.new - expect do + expect { processor.process("") - end.not_to raise_error + }.not_to raise_error end end end diff --git a/spec/rails_spec.rb b/spec/rails_spec.rb index ccf1d05..e2c5569 100644 --- a/spec/rails_spec.rb +++ b/spec/rails_spec.rb @@ -10,7 +10,7 @@ def test_file(file) if Rails.version.split(".").first.to_i >= 5 - get :test, params: { file: file } + get :test, params: {file: file} else get :test, file: file end