forked from prettier/plugin-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve perf by using --disable-gems (prettier#479)
Loading rubygems can be a slow operation. Worse yet, the load time performance degrades as more gems are installed on the system. Luckily, Ruby provides a flag to fix this: `--disable-gems`. Using this flag significantly improves performance on my machine, here are some results. | file | lint time | |--------------------------------------------------|-----------| | apps/admin/application.rb | 215ms | | apps/admin/config/routes.rb | 165ms | | apps/admin/controllers/about/show.rb | 149ms | | apps/admin/controllers/accounts/index.rb | 147ms | | apps/admin/controllers/authentication_helpers.rb | 151ms | | apps/admin/controllers/deployments/index.rb | 148ms | | apps/admin/controllers/docs/index.rb | 147ms | | apps/admin/controllers/docs/show.rb | 144ms | | file | lint time | |--------------------------------------------------|-----------| | apps/admin/application.rb | 140ms | | apps/admin/config/routes.rb | 90ms | | apps/admin/controllers/about/show.rb | 94ms | | apps/admin/controllers/accounts/index.rb | 89ms | | apps/admin/controllers/authentication_helpers.rb | 92ms | | apps/admin/controllers/deployments/index.rb | 87ms | | apps/admin/controllers/docs/index.rb | 84ms | | apps/admin/controllers/docs/show.rb | 88ms |
- Loading branch information
Showing
7 changed files
with
53 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Prettier | ||
module PluginRuby | ||
module Utils | ||
# We implement our own version checking here instead of using | ||
# Gem::Version so that we can use the --disable-gems flag. | ||
# | ||
# @see https://github.com/prettier/plugin-ruby/pull/479#issue-380389558 | ||
def self.compatible_ruby_version?(current_version) | ||
required_version = '2.5' | ||
min_major, min_minor = required_version.split('.').map(&:to_i) | ||
major, minor, _patch = current_version.split('.').map(&:to_i) | ||
|
||
return true if major > min_major | ||
return true if minor >= min_minor | ||
|
||
false | ||
end | ||
|
||
def self.ensure_compatible_ruby_version!(current_version = RUBY_VERSION) | ||
return if compatible_ruby_version?(current_version) | ||
|
||
warn( | ||
"Ruby version #{current_version} not s upported. " \ | ||
"Please upgrade to #{required_version} or above." | ||
) | ||
|
||
exit 1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class UtilsTest < Minitest::Test | ||
def test_compatible_ruby_version | ||
assert Prettier::PluginRuby::Utils.compatible_ruby_version?('2.5.0') | ||
end | ||
|
||
def test_incompatible_ruby_version | ||
refute Prettier::PluginRuby::Utils.compatible_ruby_version?('2.4.0') | ||
end | ||
end |