From 86465ff084e1f845197bb2b9813fc4112e03ae21 Mon Sep 17 00:00:00 2001 From: Matthew Prestifilippo Date: Thu, 30 Mar 2017 09:29:14 -0400 Subject: [PATCH] Fix #1423 - extname is deprecated --- src/beautifiers/index.coffee | 47 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 077190e..e229452 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -140,20 +140,32 @@ module.exports = class Beautifiers extends EventEmitter ) or beautifiers[0] return beautifier - getLanguage : (grammar, filePath) -> + getExtension : (filePath) -> + if filePath + return path.extname(filePath).substr(1) + + getLanguages : (grammar, filePath) -> # Get language - fileExtension = path.extname(filePath) - # Remove prefix "." (period) in fileExtension - fileExtension = fileExtension.substr(1) - languages = @languages.getLanguages({grammar, extension: fileExtension}) - logger.verbose(languages, grammar, fileExtension) - # Check if unsupported language - if languages.length < 1 - return null + fileExtension = @getExtension(filePath) + + if fileExtension + languages = @languages.getLanguages({grammar, extension: fileExtension}) else - # TODO: select appropriate language + languages = @languages.getLanguages({grammar}) + + logger.verbose(languages, grammar, fileExtension) + + return languages + + getLanguage : (grammar, filePath) -> + languages = @getLanguages(grammar, filePath) + + # Check if unsupported language + if languages.length > 0 language = languages[0] + return language + getOptionsForLanguage : (allOptions, language) -> # Options for Language selections = (language.fallback or []).concat([language.namespace]) @@ -241,15 +253,10 @@ module.exports = class Beautifiers extends EventEmitter logger.info('beautify', text, allOptions, grammar, filePath, onSave) logger.verbose(allOptions) - # Get language - fileExtension = path.extname(filePath) - # Remove prefix "." (period) in fileExtension - fileExtension = fileExtension.substr(1) - languages = @languages.getLanguages({grammar, extension: fileExtension}) - logger.verbose(languages, grammar, fileExtension) + language = @getLanguage(grammar, filePath) # Check if unsupported language - if languages.length < 1 + if !language unsupportedGrammar = true logger.verbose('Unsupported language') @@ -260,19 +267,14 @@ module.exports = class Beautifiers extends EventEmitter # not intended to be beautified return resolve( null ) else - # TODO: select appropriate language - language = languages[0] - logger.verbose("Language #{language.name} supported") # Get language config langDisabled = atom.config.get("atom-beautify.#{language.namespace}.disabled") - # Beautify! unsupportedGrammar = false - # Check if Language is disabled if langDisabled logger.verbose("Language #{language.name} is disabled") @@ -370,6 +372,7 @@ module.exports = class Beautifiers extends EventEmitter if atom.config.get("atom-beautify.general.muteUnsupportedLanguageErrors") return resolve( null ) else + fileExtension = @getExtension(filePath) repoBugsUrl = pkg.bugs.url title = "Atom Beautify could not find a supported beautifier for this file" detail = """