From 3e653766b81d32a510df5b382009e45e35b60928 Mon Sep 17 00:00:00 2001 From: Jeff Byrnes Date: Tue, 8 Oct 2024 16:03:41 -0400 Subject: [PATCH] Replace File.exists? with File.exist? Fixes #2169 Closes #2167 Signed-off-by: Jeff Byrnes --- cli/features/step_definitions/command_line_steps.rb | 4 ++-- cli/lib/compass/actions.rb | 8 ++++---- cli/lib/compass/app_integration/stand_alone/installer.rb | 2 +- cli/lib/compass/commands/project_base.rb | 2 +- cli/lib/compass/commands/project_stats.rb | 2 +- cli/lib/compass/commands/update_project.rb | 2 +- cli/lib/compass/compiler.rb | 2 +- cli/lib/compass/configuration/helpers.rb | 2 +- cli/lib/compass/installers/manifest.rb | 4 ++-- cli/lib/compass/sass_extensions/sprites/image.rb | 2 +- cli/lib/compass/sass_extensions/sprites/sprite_methods.rb | 4 ++-- cli/test/integrations/compass_test.rb | 8 ++++---- cli/test/units/command_line_test.rb | 6 +++--- cli/test/units/sprites/layout_test.rb | 6 +++--- cli/test/units/sprites/sprite_command_test.rb | 4 ++-- cli/test/units/sprites/sprite_map_test.rb | 8 ++++---- .../help/documentation/configuration-reference.markdown | 4 ++-- core/lib/compass/core/sass_extensions/functions/files.rb | 2 +- .../compass/core/sass_extensions/functions/image_size.rb | 4 ++-- core/lib/compass/frameworks.rb | 4 ++-- core/test/integrations/projects_test.rb | 4 ++-- 21 files changed, 42 insertions(+), 42 deletions(-) diff --git a/cli/features/step_definitions/command_line_steps.rb b/cli/features/step_definitions/command_line_steps.rb index a33b1e90e6..069dd0b3b1 100644 --- a/cli/features/step_definitions/command_line_steps.rb +++ b/cli/features/step_definitions/command_line_steps.rb @@ -114,11 +114,11 @@ end Then /an? \w+ file ([^ ]+) is (not )?removed/ do |filename, negated| - File.exists?(filename).should == !!negated + File.exist?(filename).should == !!negated end Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated| - File.exists?(filename).should == !negated + File.exist?(filename).should == !negated end Then "the following files are reported removed:" do |table| diff --git a/cli/lib/compass/actions.rb b/cli/lib/compass/actions.rb index e7d469c5a0..0f059358f2 100644 --- a/cli/lib/compass/actions.rb +++ b/cli/lib/compass/actions.rb @@ -22,9 +22,9 @@ def copy(from, to, options = nil, binary = false) def directory(dir, options = nil) options ||= self.options if self.respond_to?(:options) options ||= {} - if File.exists?(dir) && File.directory?(dir) + if File.exist?(dir) && File.directory?(dir) # do nothing - elsif File.exists?(dir) + elsif File.exist?(dir) msg = "#{basename(dir)} already exists and is not a directory." raise Compass::FilesystemConflict.new(msg) else @@ -38,7 +38,7 @@ def write_file(file_name, contents, options = nil, binary = false) options ||= self.options if self.respond_to?(:options) skip_write = false contents = process_erb(contents, options[:erb]) if options[:erb] - if File.exists?(file_name) + if File.exist?(file_name) existing_contents = IO.read(file_name) if existing_contents == contents log_action :identical, basename(file_name), options @@ -73,7 +73,7 @@ def remove(file_name) if File.directory?(file_name) FileUtils.rm_rf file_name log_action :remove, basename(file_name)+"/", options - elsif File.exists?(file_name) + elsif File.exist?(file_name) File.unlink file_name log_action :remove, basename(file_name), options end diff --git a/cli/lib/compass/app_integration/stand_alone/installer.rb b/cli/lib/compass/app_integration/stand_alone/installer.rb index 4a0664f161..a97814f8f8 100644 --- a/cli/lib/compass/app_integration/stand_alone/installer.rb +++ b/cli/lib/compass/app_integration/stand_alone/installer.rb @@ -21,7 +21,7 @@ def write_configuration_files(config_file = nil) end def config_files_exist? - File.exists? targetize('config.rb') + File.exist? targetize('config.rb') end def config_contents diff --git a/cli/lib/compass/commands/project_base.rb b/cli/lib/compass/commands/project_base.rb index cf51abfc86..54d31fed3f 100644 --- a/cli/lib/compass/commands/project_base.rb +++ b/cli/lib/compass/commands/project_base.rb @@ -60,7 +60,7 @@ def project_images_subdirectory end def assert_project_directory_exists! - if File.exists?(project_directory) && !File.directory?(project_directory) + if File.exist?(project_directory) && !File.directory?(project_directory) raise Compass::FilesystemConflict.new("#{project_directory} is not a directory.") elsif !File.directory?(project_directory) raise Compass::Error.new("#{project_directory} does not exist.") diff --git a/cli/lib/compass/commands/project_stats.rb b/cli/lib/compass/commands/project_stats.rb index 9c0b5c2a7e..7a5a365b6b 100644 --- a/cli/lib/compass/commands/project_stats.rb +++ b/cli/lib/compass/commands/project_stats.rb @@ -121,7 +121,7 @@ def sass_columns(sass_file) end def css_columns(css_file) - if File.exists?(css_file) + if File.exist?(css_file) cf = Compass::Stats::CssFile.new(css_file) cf.analyze! %w(selector_count prop_count file_size).map do |t| diff --git a/cli/lib/compass/commands/update_project.rb b/cli/lib/compass/commands/update_project.rb index 087b5e38b3..bf94837655 100644 --- a/cli/lib/compass/commands/update_project.rb +++ b/cli/lib/compass/commands/update_project.rb @@ -73,7 +73,7 @@ def new_config?(compiler) return false unless config_file config_mtime = File.mtime(config_file) compiler.file_list.each do |(_, css_filename, _)| - return config_file if File.exists?(css_filename) && config_mtime > File.mtime(css_filename) + return config_file if File.exist?(css_filename) && config_mtime > File.mtime(css_filename) end nil end diff --git a/cli/lib/compass/compiler.rb b/cli/lib/compass/compiler.rb index 638d52bd85..8a2b3d559b 100644 --- a/cli/lib/compass/compiler.rb +++ b/cli/lib/compass/compiler.rb @@ -93,7 +93,7 @@ def new_config? return false unless config_file config_mtime = File.mtime(config_file) css_files.each do |css_filename| - return config_file if File.exists?(css_filename) && config_mtime > File.mtime(css_filename) + return config_file if File.exist?(css_filename) && config_mtime > File.mtime(css_filename) end nil end diff --git a/cli/lib/compass/configuration/helpers.rb b/cli/lib/compass/configuration/helpers.rb index a9aef82e38..f86e43fc74 100644 --- a/cli/lib/compass/configuration/helpers.rb +++ b/cli/lib/compass/configuration/helpers.rb @@ -86,7 +86,7 @@ def add_project_configuration(*args) # Finds the configuration file, if it exists in a known location. def detect_configuration_file(project_path = nil) possible_files = KNOWN_CONFIG_LOCATIONS.map{|f| projectize(f, project_path) } - possible_files.detect{|f| File.exists?(f)} + possible_files.detect{|f| File.exist?(f)} end def handle_configuration_change! diff --git a/cli/lib/compass/installers/manifest.rb b/cli/lib/compass/installers/manifest.rb index 6e4f0cfb7f..f5d2d2d0e5 100644 --- a/cli/lib/compass/installers/manifest.rb +++ b/cli/lib/compass/installers/manifest.rb @@ -141,8 +141,8 @@ def with_manifest(manifest_file) # evaluated in a Manifest instance context def parse(manifest_file) with_manifest(manifest_file) do - if File.exists?(manifest_file) - open(manifest_file) do |f| + if File.exist?(manifest_file) + open(manifest_file) do |f| eval(f.read, instance_binding, manifest_file) end else diff --git a/cli/lib/compass/sass_extensions/sprites/image.rb b/cli/lib/compass/sass_extensions/sprites/image.rb index 941a3038c7..aa46dfe9a8 100644 --- a/cli/lib/compass/sass_extensions/sprites/image.rb +++ b/cli/lib/compass/sass_extensions/sprites/image.rb @@ -32,7 +32,7 @@ def file def find_file Compass.configuration.sprite_load_path.compact.each do |path| f = File.join(path, relative_file) - if File.exists?(f) + if File.exist?(f) return f end end diff --git a/cli/lib/compass/sass_extensions/sprites/sprite_methods.rb b/cli/lib/compass/sass_extensions/sprites/sprite_methods.rb index a5295aee2a..438006990f 100644 --- a/cli/lib/compass/sass_extensions/sprites/sprite_methods.rb +++ b/cli/lib/compass/sass_extensions/sprites/sprite_methods.rb @@ -72,7 +72,7 @@ def cleanup_old_sprites # Does this sprite need to be generated def generation_required? - !File.exists?(filename) || outdated? || options[:force] + !File.exist?(filename) || outdated? || options[:force] end # Returns the uniqueness hash for this sprite object @@ -109,7 +109,7 @@ def image_filenames # Checks whether this sprite is outdated def outdated? - if File.exists?(filename) + if File.exist?(filename) return @images.any? {|image| image.mtime.to_i > self.mtime.to_i } end true diff --git a/cli/test/integrations/compass_test.rb b/cli/test/integrations/compass_test.rb index 59eeed29cd..0ded5421de 100644 --- a/cli/test/integrations/compass_test.rb +++ b/cli/test/integrations/compass_test.rb @@ -46,7 +46,7 @@ def test_on_stylesheet_error_callback def test_empty_project # With no sass files, we should have no css files. within_project(:empty) do |proj| - return unless proj.css_path && File.exists?(proj.css_path) + return unless proj.css_path && File.exist?(proj.css_path) Dir.new(proj.css_path).each do |f| fail "This file should not have been generated: #{f}" unless f == "." || f == ".." end @@ -186,7 +186,7 @@ def assert_renders_correctly(*arguments) def within_project(project_name, config_block = nil) @current_project = project_name - Compass.add_configuration(configuration_file(project_name)) if File.exists?(configuration_file(project_name)) + Compass.add_configuration(configuration_file(project_name)) if File.exist?(configuration_file(project_name)) Compass.configuration.project_path = project_path(project_name) Compass.configuration.environment = :production Compass.configuration.sourcemap = false unless Compass.configuration.sourcemap_set? @@ -195,7 +195,7 @@ def within_project(project_name, config_block = nil) config_block.call(Compass.configuration) end - if Compass.configuration.sass_path && File.exists?(Compass.configuration.sass_path) + if Compass.configuration.sass_path && File.exist?(Compass.configuration.sass_path) compiler = Compass.sass_compiler compiler.logger = Compass::NullLogger.new compiler.clean! @@ -221,7 +221,7 @@ def each_sass_file(sass_dir = nil) def save_output(dir) FileUtils.rm_rf(save_path(dir)) - FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exists?(tempfile_path(dir)) + FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exist?(tempfile_path(dir)) end def project_path(project_name) diff --git a/cli/test/units/command_line_test.rb b/cli/test/units/command_line_test.rb index 8771280286..7dbae6b508 100644 --- a/cli/test/units/command_line_test.rb +++ b/cli/test/units/command_line_test.rb @@ -21,7 +21,7 @@ def test_print_version def test_basic_install within_tmp_directory do compass(*%w(create --boring basic)) - assert File.exists?("basic/sass/screen.scss") + assert File.exist?("basic/sass/screen.scss") assert_action_performed :directory, "basic/" assert_action_performed :create, "basic/sass/screen.scss" end @@ -34,8 +34,8 @@ def test_basic_install define_method "test_#{framework.name}_installation" do within_tmp_directory do compass(*%W(create --boring --using #{framework.name} #{framework.name}_project)) - assert File.exists?("#{framework.name}_project/sass/screen.scss"), "sass/screen.scss is missing. Found: #{Dir.glob("#{framework.name}_project/**/*").join(", ")}" - assert File.exists?("#{framework.name}_project/stylesheets/screen.css") + assert File.exist?("#{framework.name}_project/sass/screen.scss"), "sass/screen.scss is missing. Found: #{Dir.glob("#{framework.name}_project/**/*").join(", ")}" + assert File.exist?("#{framework.name}_project/stylesheets/screen.css") assert_action_performed :directory, "#{framework.name}_project/" assert_action_performed :create, "#{framework.name}_project/sass/screen.scss" assert_action_performed :write, "#{framework.name}_project/stylesheets/screen.css" diff --git a/cli/test/units/sprites/layout_test.rb b/cli/test/units/sprites/layout_test.rb index 8eca41eaac..93f78924e5 100644 --- a/cli/test/units/sprites/layout_test.rb +++ b/cli/test/units/sprites/layout_test.rb @@ -117,7 +117,7 @@ def horizontal(options= {}, uri=URI) assert_equal 400, base.width assert_equal 60, base.height assert_equal [[0, 0], [20, 120], [20, 0], [20, 100], [20, 160]], base.images.map {|i| [i.top, i.left]} - assert File.exists?(base.filename) + assert File.exist?(base.filename) FileUtils.rm base.filename end @@ -130,7 +130,7 @@ def horizontal(options= {}, uri=URI) assert_equal 40, base.width assert_equal 40, base.height assert_equal [[30, 0], [20, 10], [10, 20], [0, 30]], base.images.map {|i| [i.top, i.left]} - assert File.exists?(base.filename) + assert File.exist?(base.filename) FileUtils.rm base.filename end @@ -173,7 +173,7 @@ def horizontal(options= {}, uri=URI) it "should generate a horrizontal sprite" do base = horizontal base.generate - assert File.exists?(base.filename) + assert File.exist?(base.filename) FileUtils.rm base.filename end diff --git a/cli/test/units/sprites/sprite_command_test.rb b/cli/test/units/sprites/sprite_command_test.rb index 2c30c1681c..d4c10d7d72 100644 --- a/cli/test/units/sprites/sprite_command_test.rb +++ b/cli/test/units/sprites/sprite_command_test.rb @@ -42,14 +42,14 @@ def options_to_cli(options) def teardown ::Dir.chdir @before_dir clean_up_sprites - if File.exists?(@test_dir) + if File.exist?(@test_dir) ::FileUtils.rm_r @test_dir end end it "should create sprite file" do assert_equal 0, run_compass_with_options(['sprite', "-f", 'stylesheet.scss', "squares/*.png"]).to_i - assert File.exists?(File.join(test_dir, 'stylesheet.scss')) + assert File.exist?(File.join(test_dir, 'stylesheet.scss')) end end \ No newline at end of file diff --git a/cli/test/units/sprites/sprite_map_test.rb b/cli/test/units/sprites/sprite_map_test.rb index dc930607f5..b38077ebac 100644 --- a/cli/test/units/sprites/sprite_map_test.rb +++ b/cli/test/units/sprites/sprite_map_test.rb @@ -78,7 +78,7 @@ def teardown it "should generate sprite" do @base.generate - assert File.exists?(@base.filename) + assert File.exist?(@base.filename) assert !@base.generation_required? assert !@base.outdated? end @@ -86,13 +86,13 @@ def teardown it "should remove old sprite when generating new" do @base.generate file = @base.filename - assert File.exists?(file), "Original file does not exist" + assert File.exist?(file), "Original file does not exist" file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png') FileUtils.rm file_to_remove - assert !File.exists?(file_to_remove), "Failed to remove sprite file" + assert !File.exist?(file_to_remove), "Failed to remove sprite file" @base = sprite_map_test(@options) @base.generate - assert !File.exists?(file), "Sprite file did not get removed" + assert !File.exist?(file), "Sprite file did not get removed" end test "should get correct relative_name" do diff --git a/compass-style.org/content/help/documentation/configuration-reference.markdown b/compass-style.org/content/help/documentation/configuration-reference.markdown index 3b83f688b6..a75cc2910a 100644 --- a/compass-style.org/content/help/documentation/configuration-reference.markdown +++ b/compass-style.org/content/help/documentation/configuration-reference.markdown @@ -393,7 +393,7 @@ To disable the asset cache buster: more than once. Example: watch "images/**/*" do |project_dir, relative_path| - if File.exists?(File.join(project_dir, relative_path)) + if File.exist?(File.join(project_dir, relative_path)) puts "File size of #{relative_path} is: #{File.size(File.join(project_dir, relative_path))}" end end @@ -406,7 +406,7 @@ to avoid crashing the watcher in the case where the file has been removed. **`on_sprite_saved`** -- Pass this function a block of code that gets executed after a sprite is saved to disk. The block will be passed the filename. Can be invoked more then once. Example: on_sprite_saved do |filename| - post_process(filename) if File.exists?(filename) + post_process(filename) if File.exist?(filename) end **`on_sprite_generated`** -- Pass this function a block of code that gets executed after a sprite is generated but before its saved to disk. The block will be passed an instance of `ChunkyPNG::Image`. Can be invoked more then once. Example: diff --git a/core/lib/compass/core/sass_extensions/functions/files.rb b/core/lib/compass/core/sass_extensions/functions/files.rb index ebb88d3988..2962a9fe84 100644 --- a/core/lib/compass/core/sass_extensions/functions/files.rb +++ b/core/lib/compass/core/sass_extensions/functions/files.rb @@ -7,7 +7,7 @@ module Compass::Core::SassExtensions::Functions::Files def md5sum(file, format = nil) assert_type file, :String filename = nil - if options[:css_filename] && File.exists?(options[:css_filename]) + if options[:css_filename] && File.exist?(options[:css_filename]) filename = File.expand_path(file.value, File.dirname(options[:css_filename])) elsif Pathname.new(file.value).absolute? filename = file.value diff --git a/core/lib/compass/core/sass_extensions/functions/image_size.rb b/core/lib/compass/core/sass_extensions/functions/image_size.rb index fad357d1e5..1a2e303abb 100644 --- a/core/lib/compass/core/sass_extensions/functions/image_size.rb +++ b/core/lib/compass/core/sass_extensions/functions/image_size.rb @@ -55,8 +55,8 @@ def image_dimensions(image_file) end def image_path_for_size(image_file) - if File.exists?(image_file) - return image_file + if File.exist?(image_file) + return image_file end real_path(image_file) end diff --git a/core/lib/compass/frameworks.rb b/core/lib/compass/frameworks.rb index fdb1346583..c2f8c4d9f1 100644 --- a/core/lib/compass/frameworks.rb +++ b/core/lib/compass/frameworks.rb @@ -94,7 +94,7 @@ def register_directory(directory) File.join(directory, 'lib', File.basename(directory)+".rb"), File.join(directory, File.basename(directory)+".rb") ] - loader = loaders.detect{|l| File.exists?(l)} + loader = loaders.detect{|l| File.exist?(l)} registered_framework = detect_registration do require loader if loader end @@ -117,7 +117,7 @@ def template_usage(template) framework = self[framework_name] template ||= "project" usage_file = File.join(framework.templates_directory, template, "USAGE.markdown") - if File.exists?(usage_file) + if File.exist?(usage_file) File.read(usage_file) elsif help = framework.manifest(template).help help diff --git a/core/test/integrations/projects_test.rb b/core/test/integrations/projects_test.rb index c9f3c7333e..24ede7675f 100755 --- a/core/test/integrations/projects_test.rb +++ b/core/test/integrations/projects_test.rb @@ -75,7 +75,7 @@ def assert_renders_correctly(*arguments) for name in arguments actual_result_file = "#{tempfile_path(@current_project)}/#{name}".gsub(/s[ac]ss/, "css") expected_result_file = "#{result_path(@current_project)}/#{name}.#{Sass.version[:major]}.#{Sass.version[:minor]}".gsub(/s[ac]ss/, "css") - expected_result_file = "#{result_path(@current_project)}/#{name}".gsub(/s[ac]ss/, "css") unless File.exists?(expected_result_file) + expected_result_file = "#{result_path(@current_project)}/#{name}".gsub(/s[ac]ss/, "css") unless File.exist?(expected_result_file) actual_lines = File.read(actual_result_file) actual_lines.gsub!(/^@charset[^;]+;/,'') if options[:ignore_charset] actual_lines = actual_lines.split("\n").reject{|l| l=~/\A\Z/} @@ -140,7 +140,7 @@ def each_sass_file(sass_dir = nil) def save_output(dir) FileUtils.rm_rf(save_path(dir)) - FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exists?(tempfile_path(dir)) + FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exist?(tempfile_path(dir)) end def projects