Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added notification for both YAML and JSON .jsbeautifyrc parse error #1127

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -477,13 +477,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