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

Linting: Update standard yml to ruby 24 syntax #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .standard.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby_version: 2.3
ruby_version: 2.4
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ task default: [:spec, "standard:fix"]
task :clobber_package do
begin
rm_r "pkg"
rescue StandardError
rescue
nil
end
end
Expand All @@ -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}"
Expand All @@ -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"
Expand Down
18 changes: 9 additions & 9 deletions autoprefixer-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions lib/autoprefixer-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
74 changes: 39 additions & 35 deletions lib/autoprefixer-rails/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"])
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/autoprefixer-rails/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/autoprefixer-rails/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,28 +32,28 @@ 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

# Register postprocessor in Sprockets depend on issues with other gems
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
Expand Down
2 changes: 1 addition & 1 deletion lib/rake/autoprefixer_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AutoprefixerTasks < Rake::TaskLib
attr_reader :browsers

def initialize(params = {})
@params = params
@params = params
@processor = AutoprefixerRails.processor(@params)
define
end
Expand Down
22 changes: 11 additions & 11 deletions spec/autoprefixer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(["<css input>: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
Expand Down
12 changes: 6 additions & 6 deletions spec/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down