Merge pull request #1127 from emileber/json-warning

Added notification for both YAML and JSON .jsbeautifyrc parse error
This commit is contained in:
Glavin Wiechert 2016-08-22 09:44:32 -03:00 committed by GitHub
commit 94fc58dc5d
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 [#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. - 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) - 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 # v0.29.0
- Closes [#447](https://github.com/Glavin001/atom-beautify/issues/447). Improved Handlebars language support - Closes [#447](https://github.com/Glavin001/atom-beautify/issues/447). Improved Handlebars language support

View File

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

View File

@ -478,13 +478,23 @@ module.exports = class Beautifiers extends EventEmitter
strip ?= require("strip-json-comments") strip ?= require("strip-json-comments")
externalOptions = JSON.parse(strip(contents)) externalOptions = JSON.parse(strip(contents))
catch e catch e
jsonError = e.message
logger.debug "Failed parsing config as JSON: " + configPath logger.debug "Failed parsing config as JSON: " + configPath
# Attempt as YAML # Attempt as YAML
try try
yaml ?= require("yaml-front-matter") yaml ?= require("yaml-front-matter")
externalOptions = yaml.safeLoad(contents) externalOptions = yaml.safeLoad(contents)
catch e 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 logger.debug "Failed parsing config as YAML and JSON: " + configPath
externalOptions = {} externalOptions = {}
else else