Skip to content

Commit

Permalink
Fixes #68. Fix error when beautifying file that is "untitled".
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Sep 10, 2014
1 parent de52acf commit 2cd3bef
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions lib/beautify.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 2cd3bef

Please sign in to comment.