Added notification for both YAML and JSON .jsbeautifyrc parse error

This commit is contained in:
ebergeron 2016-08-07 23:00:28 -04:00
parent 06773e35df
commit ac11278bf4
3 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -94,6 +94,10 @@
{
"name": "Arman Yessenamanov",
"url": "https://github.com/yesenarman"
},
{
"name": "Émile Bergeron",
"url": "https://github.com/emileber"
}
],
"engines": {
@ -270,4 +274,4 @@
"lint": "coffeelint src/ spec/",
"code-docs": "codo && open docs/code/index.html"
}
}
}

View File

@ -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