From 2cd3bef6e0d6493d85dd85796ad67e0305e7ffc9 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Wed, 10 Sep 2014 10:25:43 -0300 Subject: [PATCH] Fixes #68. Fix error when beautifying file that is "untitled". --- lib/beautify.coffee | 58 ++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/beautify.coffee b/lib/beautify.coffee index 6f752e9..1fe4a90 100644 --- a/lib/beautify.coffee +++ b/lib/beautify.coffee @@ -229,34 +229,38 @@ beautify = -> # and how path.dirname(DIRECTORY) returns the parent directory of DIRECTORY homeOptions = getConfig(path.join(userHome,"FAKEFILENAME"), false) - # Handle EditorConfig options - # http://editorconfig.org/ - editorconfig ?= require('editorconfig'); - editorConfigOptions = editorconfig.parse(editedFilePath); - # Transform EditorConfig to Atom Beautify's config structure and naming - if editorConfigOptions.indent_style is 'space' - editorConfigOptions.indent_char = " " - # if (editorConfigOptions.indent_size) - # editorConfigOptions.indent_size = config.indent_size - else if editorConfigOptions.indent_style is 'tab' - editorConfigOptions.indent_char = "\t" - editorConfigOptions.indent_with_tabs = true - if (editorConfigOptions.tab_width) - editorConfigOptions.indent_size = config.tab_width + if editedFilePath? + # Handle EditorConfig options + # http://editorconfig.org/ + editorconfig ?= require('editorconfig'); + editorConfigOptions = editorconfig.parse(editedFilePath); + # Transform EditorConfig to Atom Beautify's config structure and naming + if editorConfigOptions.indent_style is 'space' + editorConfigOptions.indent_char = " " + # if (editorConfigOptions.indent_size) + # editorConfigOptions.indent_size = config.indent_size + else if editorConfigOptions.indent_style is 'tab' + editorConfigOptions.indent_char = "\t" + editorConfigOptions.indent_with_tabs = true + if (editorConfigOptions.tab_width) + editorConfigOptions.indent_size = config.tab_width - # Get all options in configuration files from this directory upwards to root - projectOptions = [] - p = path.dirname(editedFilePath) - # Check if p is root (top directory) - while p isnt "/" - # Get config for p - pf = path.join(p, "FAKEFILENAME") - pc = getConfig(pf, false) - # Add config for p to project's config options - projectOptions.push(pc) - # console.log p, pc - # Move upwards - p = path.resolve(p,"../") + # Get all options in configuration files from this directory upwards to root + projectOptions = [] + p = path.dirname(editedFilePath) + # Check if p is root (top directory) + while p isnt "/" + # Get config for p + pf = path.join(p, "FAKEFILENAME") + pc = getConfig(pf, false) + # Add config for p to project's config options + projectOptions.push(pc) + # console.log p, pc + # Move upwards + p = path.resolve(p,"../") + else + editorConfigOptions = {} + projectOptions = [] # Combine all options together allOptions = [