2014-08-10 15:51:44 -06:00
|
|
|
###
|
|
|
|
Language Support and default options.
|
|
|
|
###
|
|
|
|
"use strict"
|
2014-09-07 16:32:08 -06:00
|
|
|
# Lazy loaded dependencies
|
|
|
|
_ = null
|
|
|
|
extend = null
|
2014-08-10 15:51:44 -06:00
|
|
|
# Language Beautifiers
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyJS = null
|
|
|
|
beautifyHTML = null
|
|
|
|
beautifyCSS = null
|
|
|
|
beautifySQL = null
|
2014-11-05 05:46:06 -07:00
|
|
|
beautifyPerl = null
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyPHP = null
|
|
|
|
beautifyPython = null
|
|
|
|
beautifyRuby = null
|
|
|
|
beautifyLESS = null
|
|
|
|
beautifyCoffeeScript = null
|
|
|
|
uncrustifyBeautifier = null
|
2014-09-08 15:50:54 -06:00
|
|
|
beautifyHTMLERB = null
|
2014-09-15 15:06:37 -06:00
|
|
|
beautifyMarkdown = null
|
2014-10-14 01:09:38 -06:00
|
|
|
beautifyTypeScript = null
|
2014-10-05 07:15:57 -06:00
|
|
|
Analytics = null
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# Misc
|
2014-10-05 07:15:57 -06:00
|
|
|
{allowUnsafeEval} = require 'loophole'
|
|
|
|
allowUnsafeEval ->
|
|
|
|
Analytics = require("analytics-node")
|
2014-08-10 15:51:44 -06:00
|
|
|
pkg = require("../package.json")
|
|
|
|
|
|
|
|
# Analytics
|
|
|
|
analyticsWriteKey = "u3c26xkae8"
|
2015-01-02 22:58:52 -07:00
|
|
|
|
|
|
|
# Get Atom defaults
|
|
|
|
tabLength = atom.config.get('editor.tabLength')
|
|
|
|
softTabs = atom.config.get('editor.softTabs')
|
|
|
|
defaultIndentSize = (if softTabs then tabLength else 1)
|
|
|
|
defaultIndentChar = (if softTabs then " " else "\t")
|
|
|
|
defaultIndentWithTabs = not softTabs
|
|
|
|
|
|
|
|
#
|
2014-08-10 15:51:44 -06:00
|
|
|
module.exports =
|
|
|
|
|
|
|
|
# Supported unique configuration keys
|
|
|
|
# Used for detecting nested configurations in .jsbeautifyrc
|
|
|
|
languages: [
|
|
|
|
"js"
|
|
|
|
"html"
|
|
|
|
"css"
|
|
|
|
"sql"
|
2014-11-05 05:46:06 -07:00
|
|
|
"perl"
|
2014-08-10 15:51:44 -06:00
|
|
|
"php"
|
|
|
|
"python"
|
|
|
|
"ruby"
|
|
|
|
"coffeescript"
|
|
|
|
"c"
|
|
|
|
"cpp"
|
|
|
|
"cs"
|
2014-09-15 15:06:37 -06:00
|
|
|
"markdown"
|
2014-08-10 15:51:44 -06:00
|
|
|
"objectivec"
|
|
|
|
"java"
|
|
|
|
"d"
|
|
|
|
"pawn"
|
|
|
|
"vala"
|
2014-10-14 01:09:38 -06:00
|
|
|
"typescript"
|
2014-08-10 15:51:44 -06:00
|
|
|
]
|
|
|
|
|
|
|
|
# Default options per language
|
|
|
|
defaultLanguageOptions:
|
|
|
|
|
|
|
|
# jshint ignore: start
|
|
|
|
|
|
|
|
# JavaScript
|
2015-01-02 22:58:52 -07:00
|
|
|
js_indent_size:
|
|
|
|
type: 'integer'
|
|
|
|
default: defaultIndentSize
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation size/length"
|
|
|
|
js_indent_char:
|
|
|
|
type: 'string'
|
|
|
|
default: defaultIndentChar
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation character"
|
|
|
|
js_indent_level:
|
|
|
|
type: 'integer'
|
|
|
|
default: 0
|
|
|
|
description: "Initial indentation level"
|
|
|
|
js_indent_with_tabs:
|
|
|
|
type: 'boolean'
|
|
|
|
default: defaultIndentWithTabs
|
|
|
|
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
|
|
|
|
js_preserve_newlines:
|
|
|
|
type: 'boolean'
|
|
|
|
default: true
|
|
|
|
description: "Preserve line-breaks"
|
|
|
|
js_max_preserve_newlines:
|
|
|
|
type: 'integer'
|
|
|
|
default: 10
|
|
|
|
description: "Number of line-breaks to be preserved in one chunk"
|
|
|
|
js_space_in_paren:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Add padding spaces within paren, ie. f( a, b )"
|
|
|
|
js_jslint_happy:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Enable jslint-stricter mode"
|
|
|
|
js_space_after_anon_function:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Add a space before an anonymous function's parens, ie. function ()"
|
|
|
|
js_brace_style:
|
|
|
|
type: 'string'
|
|
|
|
default: "collapse"
|
|
|
|
enum: ["collapse", "expand", "end-expand", "none"]
|
|
|
|
description: "[collapse|expand|end-expand|none]"
|
|
|
|
js_break_chained_methods:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Break chained method calls across subsequent lines"
|
|
|
|
js_keep_array_indentation:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Preserve array indentation"
|
|
|
|
js_keep_function_indentation:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: ""
|
|
|
|
js_space_before_conditional:
|
|
|
|
type: 'boolean'
|
|
|
|
default: true
|
|
|
|
description: ""
|
|
|
|
js_eval_code:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: ""
|
|
|
|
js_unescape_strings:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Decode printable characters encoded in xNN notation"
|
|
|
|
js_wrap_line_length:
|
|
|
|
type: 'integer'
|
|
|
|
default: 0
|
|
|
|
description: "Wrap lines at next opportunity after N characters"
|
|
|
|
js_end_with_newline:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "End output with newline"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# CSS
|
2015-01-02 22:58:52 -07:00
|
|
|
css_indent_size:
|
|
|
|
type: 'integer'
|
|
|
|
default: defaultIndentSize
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation size/length"
|
|
|
|
css_indent_char:
|
|
|
|
type: 'string'
|
|
|
|
default: defaultIndentChar
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation character"
|
|
|
|
css_selector_separator_newline:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Add a newline between multiple selectors"
|
|
|
|
css_newline_between_rules:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Add a newline between CSS rules"
|
2015-03-20 11:06:02 -06:00
|
|
|
css_preserve_newlines:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "(Only LESS/SASS/SCSS with Prettydiff) "+
|
|
|
|
"Retain empty lines. "+
|
|
|
|
"Consecutive empty lines will be converted to a single empty line."
|
|
|
|
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# HTML
|
2015-03-12 10:33:27 -06:00
|
|
|
html_htmlbeautifier_path:
|
|
|
|
title: "htmlbeautifier path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `htmlbeautifier` CLI executable"
|
2015-01-02 22:58:52 -07:00
|
|
|
html_indent_inner_html:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "Indent <head> and <body> sections."
|
|
|
|
html_indent_size:
|
|
|
|
type: 'integer'
|
|
|
|
default: defaultIndentSize
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation size/length"
|
|
|
|
html_indent_char:
|
|
|
|
type: 'string'
|
|
|
|
default: defaultIndentChar
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation character"
|
|
|
|
html_brace_style:
|
|
|
|
type: 'string'
|
|
|
|
default: "collapse"
|
|
|
|
enum: ["collapse", "expand", "end-expand", "none"]
|
|
|
|
description: "[collapse|expand|end-expand|none]"
|
|
|
|
html_indent_scripts:
|
|
|
|
type: 'string'
|
|
|
|
default: "normal"
|
|
|
|
enum: ["keep", "separate", "normal"]
|
|
|
|
description: "[keep|separate|normal]"
|
|
|
|
html_wrap_line_length:
|
|
|
|
type: 'integer'
|
|
|
|
default: 250
|
|
|
|
description: "Maximum characters per line (0 disables)"
|
2015-03-07 14:21:28 -07:00
|
|
|
html_wrap_attributes:
|
|
|
|
type: 'string'
|
|
|
|
default: "auto"
|
|
|
|
enum: ["auto", "force"]
|
|
|
|
description: "Wrap attributes to new lines [auto|force]"
|
|
|
|
html_wrap_attributes_indent_size:
|
|
|
|
type: 'integer'
|
|
|
|
default: defaultIndentSize
|
|
|
|
minimum: 0
|
|
|
|
description: "Indent wrapped attributes to after N characters"
|
2015-01-02 22:58:52 -07:00
|
|
|
html_preserve_newlines:
|
|
|
|
type: 'boolean'
|
|
|
|
default: true
|
|
|
|
description: "Preserve line-breaks"
|
|
|
|
html_max_preserve_newlines:
|
|
|
|
type: 'integer'
|
|
|
|
default: 10
|
|
|
|
description: "Number of line-breaks to be preserved in one chunk"
|
|
|
|
html_unformatted:
|
|
|
|
type: 'array'
|
|
|
|
default: ['a', 'sub', 'sup', 'b', 'i', 'u']
|
|
|
|
items:
|
|
|
|
type: 'string'
|
|
|
|
description: "List of tags (defaults to inline) that should not be reformatted"
|
|
|
|
html_end_with_newline:
|
|
|
|
type: 'boolean'
|
|
|
|
default: false
|
|
|
|
description: "End output with newline"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# SQL
|
2015-01-02 22:58:52 -07:00
|
|
|
sql_indent_size:
|
|
|
|
type: 'integer'
|
|
|
|
default: defaultIndentSize
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation size/length"
|
|
|
|
sql_keywords:
|
|
|
|
type: 'string'
|
|
|
|
default: "upper"
|
|
|
|
description: "Change case of keywords"
|
|
|
|
enum: ["lower","upper","capitalize"]
|
|
|
|
sql_identifiers:
|
|
|
|
type: 'string'
|
|
|
|
default: "lower"
|
|
|
|
description: "Change case of identifiers"
|
|
|
|
enum: ["lower","upper","capitalize"]
|
|
|
|
sql_sqlformat_path:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `sqlformat` CLI executable"
|
2014-09-28 13:22:29 -06:00
|
|
|
|
2014-09-15 15:06:37 -06:00
|
|
|
# Markdown
|
2015-01-02 22:58:52 -07:00
|
|
|
markdown_pandoc_path:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `pandoc` CLI executable"
|
|
|
|
markdown_yaml_front_matter:
|
|
|
|
type: 'boolean'
|
|
|
|
default: true
|
|
|
|
description: "Should also format YAML Front Matter (Jekyll) in Markdown"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
2014-11-05 05:46:06 -07:00
|
|
|
# Perl
|
2015-01-02 22:58:52 -07:00
|
|
|
perl_perltidy_path:
|
|
|
|
type: 'string'
|
|
|
|
default: "perltidy"
|
|
|
|
description: "Path to the `perltidy` CLI executable"
|
|
|
|
perl_perltidy_profile:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Specify a configuration file which will override the default name of .perltidyrc"
|
2014-11-05 05:46:06 -07:00
|
|
|
|
2014-08-10 15:51:44 -06:00
|
|
|
# PHP
|
2015-03-18 23:09:11 -06:00
|
|
|
php_cs_fixer_path:
|
2015-01-02 22:58:52 -07:00
|
|
|
type: 'string'
|
|
|
|
default: ""
|
2015-03-18 22:01:57 -06:00
|
|
|
description: "Path to the `php-cs-fixer` CLI executable"
|
|
|
|
php_fixers:
|
2015-01-02 22:58:52 -07:00
|
|
|
type: 'string'
|
|
|
|
default: ""
|
2015-03-18 22:01:57 -06:00
|
|
|
description: "Add fixer(s). i.e. linefeed,-short_tag,indentation"
|
|
|
|
php_level:
|
2015-01-02 22:58:52 -07:00
|
|
|
type: 'string'
|
|
|
|
default: ""
|
2015-03-18 22:01:57 -06:00
|
|
|
description: "By default, all PSR-2 fixers and some additional ones are run."
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# Python
|
2015-01-02 22:58:52 -07:00
|
|
|
python_autopep8_path:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `autopep8` CLI executable"
|
|
|
|
python_max_line_length:
|
|
|
|
type: 'integer'
|
|
|
|
default: 79
|
|
|
|
description: "set maximum allowed line length"
|
|
|
|
python_indent_size:
|
|
|
|
type: 'integer'
|
|
|
|
default: defaultIndentSize
|
|
|
|
minimum: 0
|
|
|
|
description: "Indentation size/length"
|
|
|
|
python_ignore:
|
|
|
|
type: 'array'
|
|
|
|
default: ["E24"]
|
|
|
|
items:
|
|
|
|
type: 'string'
|
|
|
|
description: "do not fix these errors/warnings"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# Ruby
|
2015-01-02 22:58:52 -07:00
|
|
|
ruby_rbeautify_path:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `rbeautify` CLI executable"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# C
|
2015-01-02 22:58:52 -07:00
|
|
|
c_uncrustifyPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
c_configPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# C++
|
2015-01-02 22:58:52 -07:00
|
|
|
cpp_uncrustifyPath:
|
|
|
|
title: "C++ Uncrustify Path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
cpp_configPath:
|
|
|
|
title: "C++ Config Path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# Objective-C
|
2015-01-02 22:58:52 -07:00
|
|
|
objectivec_uncrustifyPath:
|
|
|
|
title: "Objective-C Uncrustify Path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
objectivec_configPath:
|
|
|
|
title: "Objective-C Config Path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# C#
|
2015-01-02 22:58:52 -07:00
|
|
|
cs_uncrustifyPath:
|
|
|
|
title: "C# Uncrustify Path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
cs_configPath:
|
|
|
|
title: "C# Config Path"
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
2014-09-14 21:04:28 -06:00
|
|
|
# D
|
2015-01-02 22:58:52 -07:00
|
|
|
d_uncrustifyPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
d_configPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# Java
|
2015-01-02 22:58:52 -07:00
|
|
|
java_uncrustifyPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
java_configPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# Pawn
|
2015-01-02 22:58:52 -07:00
|
|
|
pawn_uncrustifyPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
pawn_configPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# VALA
|
2015-01-02 22:58:52 -07:00
|
|
|
vala_uncrustifyPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to the `uncrustify` CLI executable"
|
|
|
|
vala_configPath:
|
|
|
|
type: 'string'
|
|
|
|
default: ""
|
|
|
|
description: "Path to uncrustify config file. i.e. uncrustify.cfg"
|
2014-08-10 15:51:44 -06:00
|
|
|
|
|
|
|
# jshint ignore: end
|
|
|
|
|
|
|
|
# Process each language
|
|
|
|
beautify: (text, grammar, allOptions, beautifyCompleted) ->
|
|
|
|
self = this
|
|
|
|
# Beautify!
|
|
|
|
unsupportedGrammar = false
|
|
|
|
options = undefined
|
2014-12-27 23:25:17 -07:00
|
|
|
if atom.config.get("atom-beautify.disabledLanguages")?.indexOf(grammar) > - 1
|
2014-11-16 07:28:20 -07:00
|
|
|
return beautifyCompleted(null)
|
2014-08-10 15:51:44 -06:00
|
|
|
switch grammar
|
|
|
|
# Treat JSON as JavaScript, because it will support comments.
|
|
|
|
# And Glavin001 has tested JSON beauifying with beautifyJS.
|
|
|
|
when "JSON", "JavaScript"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyJS ?= require("js-beautify")
|
2014-08-10 15:51:44 -06:00
|
|
|
text = beautifyJS(text, self.getOptions("js", allOptions))
|
|
|
|
beautifyCompleted text
|
|
|
|
when "CoffeeScript"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyCoffeeScript ?= require("./langs/coffeescript-beautify")
|
2014-08-10 15:51:44 -06:00
|
|
|
beautifyCoffeeScript text, self.getOptions("js", allOptions), beautifyCompleted
|
2014-10-26 13:11:44 -06:00
|
|
|
when "Handlebars", "HTML (Mustache)"
|
2014-08-10 15:51:44 -06:00
|
|
|
# jshint ignore: start
|
|
|
|
allOptions.push indent_handlebars: true # Force jsbeautify to indent_handlebars
|
2014-10-05 10:20:15 -06:00
|
|
|
# jshint ignore: end
|
|
|
|
beautifyHTML ?= require("js-beautify").html
|
|
|
|
text = beautifyHTML(text, self.getOptions("html", allOptions))
|
|
|
|
beautifyCompleted text
|
2015-03-12 10:35:21 -06:00
|
|
|
when "HTML (Liquid)", "HTML", "XML", "Marko", "Web Form/Control (C#)", "Web Handler (C#)"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyHTML ?= require("js-beautify").html
|
2014-08-10 15:51:44 -06:00
|
|
|
text = beautifyHTML(text, self.getOptions("html", allOptions))
|
|
|
|
beautifyCompleted text
|
2014-11-07 00:46:10 -07:00
|
|
|
when "HTML (Ruby - ERB)", "HTML (Rails)"
|
2014-09-08 15:50:54 -06:00
|
|
|
beautifyHTMLERB ?= require("./langs/html-erb-beautify")
|
|
|
|
beautifyHTMLERB text, self.getOptions("html", allOptions), beautifyCompleted
|
2014-08-10 15:51:44 -06:00
|
|
|
when "CSS"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyCSS ?= require("js-beautify").css
|
2014-08-10 15:51:44 -06:00
|
|
|
text = beautifyCSS(text, self.getOptions("css", allOptions))
|
|
|
|
beautifyCompleted text
|
|
|
|
when "Sass", "SCSS", "LESS"
|
2015-02-02 09:26:40 -07:00
|
|
|
beautifyLESS ?= require("./langs/css-prettydiff-beautify")
|
2014-08-10 15:51:44 -06:00
|
|
|
beautifyLESS text, self.getOptions("css", allOptions), beautifyCompleted
|
|
|
|
when "SQL (Rails)", "SQL"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifySQL ?= require("./langs/sql-beautify")
|
2014-08-17 08:01:53 -06:00
|
|
|
beautifySQL text, self.getOptions("sql", allOptions), beautifyCompleted
|
2014-11-05 05:46:06 -07:00
|
|
|
when "Perl"
|
|
|
|
beautifyPerl ?= require("./langs/perl-beautify")
|
|
|
|
beautifyPerl text, self.getOptions("perl", allOptions), beautifyCompleted
|
2014-08-10 15:51:44 -06:00
|
|
|
when "PHP"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyPHP ?= require("./langs/php-beautify")
|
2014-08-10 15:51:44 -06:00
|
|
|
beautifyPHP text, self.getOptions("php", allOptions), beautifyCompleted
|
|
|
|
when "Python"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyPython ?= require("./langs/python-beautify")
|
2014-08-10 15:51:44 -06:00
|
|
|
beautifyPython text, self.getOptions("python", allOptions), beautifyCompleted
|
2014-11-07 00:46:10 -07:00
|
|
|
when "Ruby", "Ruby on Rails"
|
2014-09-07 16:32:08 -06:00
|
|
|
beautifyRuby ?= require("./langs/ruby-beautify")
|
2014-08-10 15:51:44 -06:00
|
|
|
beautifyRuby text, self.getOptions("ruby", allOptions), beautifyCompleted
|
2014-09-15 15:06:37 -06:00
|
|
|
when "GitHub Markdown"
|
|
|
|
beautifyMarkdown ?= require("./langs/markdown-beautify")
|
|
|
|
beautifyMarkdown text, self.getOptions("markdown", allOptions), beautifyCompleted
|
2014-08-10 15:51:44 -06:00
|
|
|
when "C"
|
|
|
|
options = self.getOptions("c", allOptions)
|
|
|
|
options.languageOverride = "C"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "C++"
|
|
|
|
options = self.getOptions("cpp", allOptions)
|
|
|
|
options.languageOverride = "CPP"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "C#"
|
|
|
|
options = self.getOptions("cs", allOptions)
|
|
|
|
options.languageOverride = "CS"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "Objective-C", "Objective-C++"
|
|
|
|
options = self.getOptions("objectivec", allOptions)
|
|
|
|
options.languageOverride = "OC+"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "D"
|
|
|
|
options = self.getOptions("d", allOptions)
|
|
|
|
options.languageOverride = "D"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "Pawn"
|
|
|
|
options = self.getOptions("pawn", allOptions)
|
|
|
|
options.languageOverride = "PAWN"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "Vala"
|
|
|
|
options = self.getOptions("vala", allOptions)
|
|
|
|
options.languageOverride = "VALA"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
|
|
|
when "Java"
|
|
|
|
options = self.getOptions("java", allOptions)
|
|
|
|
options.languageOverride = "JAVA"
|
2014-09-07 16:32:08 -06:00
|
|
|
uncrustifyBeautifier ?= require("./langs/uncrustify/")
|
2014-08-10 15:51:44 -06:00
|
|
|
uncrustifyBeautifier text, options, beautifyCompleted
|
2014-10-14 01:09:38 -06:00
|
|
|
when "TypeScript"
|
|
|
|
beautifyTypeScript ?= require("./langs/typescript-beautify")
|
|
|
|
beautifyTypeScript text, self.getOptions("js", allOptions), beautifyCompleted
|
2014-08-10 15:51:44 -06:00
|
|
|
else
|
|
|
|
unsupportedGrammar = true
|
|
|
|
|
|
|
|
# Check if Analytics is enabled
|
|
|
|
if atom.config.get("atom-beautify.analytics")
|
|
|
|
# Setup Analytics
|
|
|
|
analytics = new Analytics(analyticsWriteKey)
|
|
|
|
unless atom.config.get("atom-beautify._analyticsUserId")
|
|
|
|
uuid = require("node-uuid")
|
|
|
|
atom.config.set "atom-beautify._analyticsUserId", uuid.v4()
|
|
|
|
# Setup Analytics User Id
|
|
|
|
userId = atom.config.get("atom-beautify._analyticsUserId")
|
|
|
|
analytics.identify userId: userId
|
|
|
|
version = pkg.version
|
|
|
|
analytics.track
|
|
|
|
userId: atom.config.get("atom-beautify._analyticsUserId")
|
|
|
|
event: "Beautify"
|
|
|
|
properties:
|
|
|
|
grammar: grammar
|
|
|
|
version: version
|
|
|
|
options: allOptions
|
|
|
|
label: grammar
|
|
|
|
category: version
|
2014-09-07 22:02:23 -06:00
|
|
|
#
|
|
|
|
if unsupportedGrammar
|
2014-09-28 13:22:29 -06:00
|
|
|
if atom.config.get("atom-beautify.muteUnsupportedLanguageErrors")
|
|
|
|
return beautifyCompleted(null)
|
|
|
|
else
|
|
|
|
throw new Error("Unsupported language for grammar '#{grammar}'.")
|
2014-08-10 15:51:44 -06:00
|
|
|
return
|
|
|
|
|
|
|
|
getOptions: (selection, allOptions) ->
|
|
|
|
self = this
|
2014-09-07 16:32:08 -06:00
|
|
|
_ ?= require("lodash")
|
|
|
|
extend ?= require("extend")
|
2014-08-10 15:51:44 -06:00
|
|
|
# console.log(selection, allOptions);
|
|
|
|
# Reduce all options into correctly merged options.
|
|
|
|
options = _.reduce(allOptions, (result, currOptions) ->
|
|
|
|
containsNested = false
|
|
|
|
collectedConfig = {}
|
|
|
|
key = undefined
|
|
|
|
# Check to see if config file uses nested object format to split up js/css/html options
|
|
|
|
for key of currOptions
|
|
|
|
# Check if is supported language
|
|
|
|
if _.indexOf(self.languages, key) >= 0 and typeof currOptions[key] is "object" # Check if nested object (more options in value)
|
|
|
|
containsNested = true
|
|
|
|
break # Found, break out of loop, no need to continue
|
|
|
|
# console.log(containsNested, currOptions);
|
|
|
|
# Create a flat object of config options if nested format was used
|
|
|
|
unless containsNested
|
|
|
|
_.merge collectedConfig, currOptions
|
|
|
|
else
|
|
|
|
# Merge with selected options
|
|
|
|
# where `selection` could be `html`, `js`, 'css', etc
|
|
|
|
# console.log(selection, currOptions[selection]);
|
|
|
|
_.merge collectedConfig, currOptions[selection]
|
|
|
|
extend result, collectedConfig
|
2014-09-15 15:06:37 -06:00
|
|
|
, {} )
|
2014-08-10 15:51:44 -06:00
|
|
|
# TODO: Clean.
|
|
|
|
# There is a bug in nopt
|
|
|
|
# See https://github.com/npm/nopt/issues/38#issuecomment-45971505
|
|
|
|
# console.log('pre-clean', JSON.stringify(options));
|
|
|
|
#options = cleanOptions(options, knownOpts);
|
|
|
|
#console.log('post-clean', JSON.stringify(options));
|
|
|
|
options
|