Skip to content

Commit

Permalink
Merge pull request #1127 from emileber/json-warning
Browse files Browse the repository at this point in the history
Added notification for both YAML and JSON .jsbeautifyrc parse error
  • Loading branch information
Glavin001 committed Aug 22, 2016
2 parents 3310941 + ac11278 commit 94fc58d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Closes [#776] (https://github.com/Glavin001/atom-beautify/issues/776) Add support for `collapse-preserve-inline` brace_style for javascript.
- Closes [#786](https://github.com/Glavin001/atom-beautify/issues/786) YAPF configuration files are ignored.
- Fix phpcbf hanging issue by closing stdin. See [#893](https://github.com/Glavin001/atom-beautify/issues/893)
- Add warning notification when parsing `.jsbeautifyrc` as JSON or YAML fails. See [#1106](https://github.com/Glavin001/atom-beautify/issues/1106)

# v0.29.0
- Closes [#447](https://github.com/Glavin001/atom-beautify/issues/447). Improved Handlebars language support
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
{
"name": "Arman Yessenamanov",
"url": "https://github.com/yesenarman"
},
{
"name": "Émile Bergeron",
"url": "https://github.com/emileber"
}
],
"engines": {
Expand Down Expand Up @@ -270,4 +274,4 @@
"lint": "coffeelint src/ spec/",
"code-docs": "codo && open docs/code/index.html"
}
}
}
12 changes: 11 additions & 1 deletion src/beautifiers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,23 @@ module.exports = class Beautifiers extends EventEmitter
strip ?= require("strip-json-comments")
externalOptions = JSON.parse(strip(contents))
catch e

jsonError = e.message
logger.debug "Failed parsing config as JSON: " + configPath
# Attempt as YAML
try
yaml ?= require("yaml-front-matter")
externalOptions = yaml.safeLoad(contents)
catch e
title = "Atom Beautify failed to parse config as JSON or YAML"
detail = """
Parsing '.jsbeautifyrc' at #{configPath}
JSON: #{jsonError}
YAML: #{e.message}
"""
atom?.notifications.addWarning(title, {
detail
dismissable : true
})
logger.debug "Failed parsing config as YAML and JSON: " + configPath
externalOptions = {}
else
Expand Down

0 comments on commit 94fc58d

Please sign in to comment.