diff --git a/examples/nested-jsbeautifyrc/.jsbeautifyrc b/examples/nested-jsbeautifyrc/.jsbeautifyrc index 53b6f08..feb1813 100644 --- a/examples/nested-jsbeautifyrc/.jsbeautifyrc +++ b/examples/nested-jsbeautifyrc/.jsbeautifyrc @@ -18,7 +18,6 @@ indent_char: " " indent_size: 2 preserve_newlines: true - # newline_between_rules: true js: indent_size: 2 indent_char: " " diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 1bd1b15..6bf0e0f 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -183,8 +183,15 @@ describe "BeautifyLanguages", -> newStr=expectedContents oldHeader="beautified" newHeader="expected" - diff = JsDiff.createPatch(fileName, oldStr, newStr, oldHeader, newHeader) - expect(text).toEqual(expectedContents, "Beautifier output does not match expected output:\n"+diff) + diff = JsDiff.createPatch(fileName, oldStr, \ + newStr, oldHeader, newHeader) + opts = beautifier.getOptions(allOptions, \ + grammarName, testFileName) + expect(text).toEqual(expectedContents, \ + "Beautifier output does not match expected \ + output:\n#{diff}\n\n\ + With options:\n\ + #{JSON.stringify(opts, undefined, 4)}") # All done! beautifyCompleted = true diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 818af10..c854e20 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -289,6 +289,22 @@ module.exports = class Beautifiers extends EventEmitter _.contains(beautifier.languages, language) ) + getOptions : (allOptions, 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 + else + # TODO: select appropriate language + language = languages[0] + # Options for Language + options = @getOptions([language.namespace]\ + .concat(language.fallback or []), allOptions) or {} beautify : (text, allOptions, grammar, filePath, {onSave} = {}) -> return Promise.all(allOptions)