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
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 = [