Fixes #68. Fix error when beautifying file that is "untitled".

This commit is contained in:
Glavin Wiechert 2014-09-10 10:25:43 -03:00
parent de52acfcf6
commit 2cd3bef6e0
1 changed files with 31 additions and 27 deletions

View File

@ -229,34 +229,38 @@ beautify = ->
# and how path.dirname(DIRECTORY) returns the parent directory of DIRECTORY # and how path.dirname(DIRECTORY) returns the parent directory of DIRECTORY
homeOptions = getConfig(path.join(userHome,"FAKEFILENAME"), false) homeOptions = getConfig(path.join(userHome,"FAKEFILENAME"), false)
# Handle EditorConfig options if editedFilePath?
# http://editorconfig.org/ # Handle EditorConfig options
editorconfig ?= require('editorconfig'); # http://editorconfig.org/
editorConfigOptions = editorconfig.parse(editedFilePath); editorconfig ?= require('editorconfig');
# Transform EditorConfig to Atom Beautify's config structure and naming editorConfigOptions = editorconfig.parse(editedFilePath);
if editorConfigOptions.indent_style is 'space' # Transform EditorConfig to Atom Beautify's config structure and naming
editorConfigOptions.indent_char = " " if editorConfigOptions.indent_style is 'space'
# if (editorConfigOptions.indent_size) editorConfigOptions.indent_char = " "
# editorConfigOptions.indent_size = config.indent_size # if (editorConfigOptions.indent_size)
else if editorConfigOptions.indent_style is 'tab' # editorConfigOptions.indent_size = config.indent_size
editorConfigOptions.indent_char = "\t" else if editorConfigOptions.indent_style is 'tab'
editorConfigOptions.indent_with_tabs = true editorConfigOptions.indent_char = "\t"
if (editorConfigOptions.tab_width) editorConfigOptions.indent_with_tabs = true
editorConfigOptions.indent_size = config.tab_width if (editorConfigOptions.tab_width)
editorConfigOptions.indent_size = config.tab_width
# Get all options in configuration files from this directory upwards to root # Get all options in configuration files from this directory upwards to root
projectOptions = [] projectOptions = []
p = path.dirname(editedFilePath) p = path.dirname(editedFilePath)
# Check if p is root (top directory) # Check if p is root (top directory)
while p isnt "/" while p isnt "/"
# Get config for p # Get config for p
pf = path.join(p, "FAKEFILENAME") pf = path.join(p, "FAKEFILENAME")
pc = getConfig(pf, false) pc = getConfig(pf, false)
# Add config for p to project's config options # Add config for p to project's config options
projectOptions.push(pc) projectOptions.push(pc)
# console.log p, pc # console.log p, pc
# Move upwards # Move upwards
p = path.resolve(p,"../") p = path.resolve(p,"../")
else
editorConfigOptions = {}
projectOptions = []
# Combine all options together # Combine all options together
allOptions = [ allOptions = [