Closes #172, #146. Update to new Atom Config API.

What's new:
- Add settings descriptions
- Update options for js-beautify (JS, CSS, HTML)
- Update Spec to support new changes
This commit is contained in:
Glavin Wiechert 2015-01-03 01:58:52 -04:00
parent a2292201a3
commit eb1471d23b
32 changed files with 371 additions and 89 deletions

View File

@ -3,8 +3,7 @@ class Example
Example() Example()
: member(0) : member(0)
{ {}
}
int member; int member;

View File

@ -4,7 +4,8 @@
{{#items}} {{#items}}
{{#first}} {{#first}}
<li><strong>{{name}}</strong> <li>
<strong>{{name}}</strong>
</li> </li>
{{/first}} {{/first}}
{{#link}} {{#link}}

View File

@ -5,3 +5,4 @@ title: "This is a title!"
stuff stuff
more stuff more stuff

View File

@ -222,13 +222,37 @@ handleSaveEvent = =>
{Subscriber} = require path.join(atom.packages.resourcePath, 'node_modules', 'emissary') {Subscriber} = require path.join(atom.packages.resourcePath, 'node_modules', 'emissary')
Subscriber.extend plugin Subscriber.extend plugin
plugin.configDefaults = _.merge( plugin.config = _.merge(
analytics: true analytics:
beautifyOnSave: false type: 'boolean'
beautifyEntireFileOnSave: true default: true
muteUnsupportedLanguageErrors: false description: "Automatically send usage information (NEVER CODE) to Google Analytics"
muteAllErrors: false _analyticsUserId:
disabledLanguages: [] type: 'string'
default: ""
description: "Unique identifier for this user for tracking usage analytics"
beautifyOnSave:
type: 'boolean'
default: false
description: "Beautify active editor on save"
beautifyEntireFileOnSave:
type: 'boolean'
default: true
description: "When beautifying on save, use the entire file, even if there is selected text in the editor"
muteUnsupportedLanguageErrors:
type: 'boolean'
default: false
description: "Do not show \"Unsupported Language\" errors when they occur"
muteAllErrors:
type: 'boolean'
default: false
description: "Do not show any/all errors when they occur"
disabledLanguages:
type: 'array'
default: []
items:
type: 'string'
description: "An array of languages/grammars to disable Beautification for"
, defaultLanguageOptions) , defaultLanguageOptions)
plugin.activate = -> plugin.activate = ->
handleSaveEvent() handleSaveEvent()

View File

@ -30,9 +30,12 @@ getCmd = (inputPath, outputPath, options, cb) ->
else else
# Has custom config path # Has custom config path
editor = atom.workspace.getActiveEditor() editor = atom.workspace.getActiveEditor()
if editor?
basePath = path.dirname(editor.getPath()) basePath = path.dirname(editor.getPath())
# console.log(basePath); # console.log(basePath);
configPath = path.resolve(basePath, configPath) configPath = path.resolve(basePath, configPath)
done configPath done configPath
else
cb(new Error("No Uncrustify Config Path set! Please configure Uncrustify with Atom Beautify."))
return return
module.exports = cliBeautify(getCmd) module.exports = cliBeautify(getCmd)

View File

@ -30,6 +30,15 @@ pkg = require("../package.json")
# Analytics # Analytics
analyticsWriteKey = "u3c26xkae8" analyticsWriteKey = "u3c26xkae8"
# 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
#
module.exports = module.exports =
# Supported unique configuration keys # Supported unique configuration keys
@ -62,93 +71,317 @@ module.exports =
# jshint ignore: start # jshint ignore: start
# JavaScript # JavaScript
js_indent_size: 2 js_indent_size:
js_indent_char: " " type: 'integer'
js_indent_level: 0 default: defaultIndentSize
js_indent_with_tabs: false minimum: 0
js_preserve_newlines: true description: "Indentation size/length"
js_max_preserve_newlines: 10 js_indent_char:
js_jslint_happy: false type: 'string'
js_brace_style: "collapse" default: defaultIndentChar
js_keep_array_indentation: false minimum: 0
js_keep_function_indentation: false description: "Indentation character"
js_space_before_conditional: true js_indent_level:
js_break_chained_methods: false type: 'integer'
js_eval_code: false default: 0
js_unescape_strings: false description: "Initial indentation level"
js_wrap_line_length: 0 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"
# CSS # CSS
css_indent_size: 2 css_indent_size:
css_indent_char: " " 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"
# HTML # HTML
html_indent_inner_html: false html_indent_inner_html:
html_indent_size: 2 type: 'boolean'
html_indent_char: " " default: false
html_brace_style: "collapse" description: "Indent <head> and <body> sections."
html_indent_scripts: "normal" html_indent_size:
html_wrap_line_length: 250 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)"
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"
# SQL # SQL
sql_indent_size: 2 sql_indent_size:
sql_keywords: "upper" type: 'integer'
sql_identifiers: "lower" default: defaultIndentSize
sql_sqlformat_path: "" 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"
# Markdown # Markdown
markdown_pandoc_path: "" markdown_pandoc_path:
markdown_yaml_front_matter: true 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"
# Perl # Perl
perl_perltidy_path: "perltidy" perl_perltidy_path:
perl_perltidy_profile: "" 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"
# PHP # PHP
php_beautifier_path: "" php_beautifier_path:
php_filters: "" type: 'string'
php_directory_filters: "" default: ""
description: "Path to the `PHP_Beautifier` CLI executable"
php_filters:
type: 'string'
default: ""
description: "Add filter(s). i.e. \"Filter1(setting1=value1,setting2=value2) Filter2()\""
php_directory_filters:
type: 'string'
default: ""
description: "Include dirs for filters"
# Python # Python
python_autopep8_path: "" python_autopep8_path:
python_max_line_length: 79 type: 'string'
python_indent_size: 4 default: ""
python_ignore: ["E24"] 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"
# Ruby # Ruby
ruby_rbeautify_path: "" ruby_rbeautify_path:
type: 'string'
default: ""
description: "Path to the `rbeautify` CLI executable"
# C # C
c_uncrustifyPath: "" c_uncrustifyPath:
c_configPath: "" 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"
# C++ # C++
cpp_uncrustifyPath: "" cpp_uncrustifyPath:
cpp_configPath: "" 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"
# Objective-C # Objective-C
objectivec_uncrustifyPath: "" objectivec_uncrustifyPath:
objectivec_configPath: "" 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"
# C# # C#
cs_uncrustifyPath: "" cs_uncrustifyPath:
cs_configPath: "" 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"
# D # D
d_uncrustifyPath: "" d_uncrustifyPath:
d_configPath: "" 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"
# Java # Java
java_uncrustifyPath: "" java_uncrustifyPath:
java_configPath: "" 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"
# Pawn # Pawn
pawn_uncrustifyPath: "" pawn_uncrustifyPath:
pawn_configPath: "" 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"
# VALA # VALA
vala_uncrustifyPath: "" vala_uncrustifyPath:
vala_configPath: "" 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"
# jshint ignore: end # jshint ignore: end

View File

@ -7,7 +7,6 @@ yaml = null
editorconfig = null editorconfig = null
beautifier = require("./language-options") beautifier = require("./language-options")
languages = beautifier.languages languages = beautifier.languages
defaultLanguageOptions = beautifier.defaultLanguageOptions
module.exports = module.exports =
findFileResults: {} findFileResults: {}
@ -73,8 +72,8 @@ module.exports =
return proj if proj return proj if proj
return home if @verifyExists(home) return home if @verifyExists(home)
null null
getConfigOptionsFromSettings: (langs, config) -> getConfigOptionsFromSettings: (langs) ->
config ?= atom.config.get('atom-beautify') config = atom.config.get('atom-beautify')
options = {} options = {}
# console.log(langs, config); # console.log(langs, config);
# Iterate over keys of the settings # Iterate over keys of the settings
@ -140,12 +139,9 @@ module.exports =
indent_size: (if softTabs then tabLength else 1) indent_size: (if softTabs then tabLength else 1)
indent_char: (if softTabs then " " else "\t") indent_char: (if softTabs then " " else "\t")
indent_with_tabs: not softTabs indent_with_tabs: not softTabs
# From Package Settings # From Package Settings
configOptions = @getConfigOptionsFromSettings(languages) configOptions = @getConfigOptionsFromSettings(languages)
else
# Without editor
# Use default options for Atom editor
configOptions = @getConfigOptionsFromSettings(languages, defaultLanguageOptions)
# Get configuration in User's Home directory # Get configuration in User's Home directory
userHome = @getUserHome() userHome = @getUserHome()
@ -195,3 +191,5 @@ module.exports =
editorConfigOptions editorConfigOptions
] ]
allOptions = allOptions.concat(projectOptions) allOptions = allOptions.concat(projectOptions)
# console.log(allOptions)
return allOptions

View File

@ -63,14 +63,19 @@
"typescript-formatter": "~0.1.4", "typescript-formatter": "~0.1.4",
"yaml-front-matter": "^3.2.3" "yaml-front-matter": "^3.2.3"
}, },
"activationEvents": [ "activationCommands": {
"beautify", "atom-workspace": [
"beautify:beautify-editor", "beautify:beautify-editor",
"beautify:beautify-file",
"beautify:beautify-directory",
"core:save", "core:save",
"core:save-as" "core:save-as"
], ],
".tree-view .file .name": [
"beautify:beautify-file"
],
".tree-view .directory .name": [
"beautify:beautify-directory"
]
},
"keywords": [ "keywords": [
"atom", "atom",
"beautify", "beautify",

View File

@ -25,11 +25,29 @@ describe "BeautifyLanguages", ->
] ]
beforeEach -> beforeEach ->
# Install all of the languages
for lang in allLanguages for lang in allLanguages
do (lang) -> do (lang) ->
waitsForPromise -> waitsForPromise ->
atom.packages.activatePackage("language-#{lang}") atom.packages.activatePackage("language-#{lang}")
# Activate package
waitsForPromise ->
activationPromise = atom.packages.activatePackage('atom-beautify')
# Force activate package
pack = atom.packages.getLoadedPackage("atom-beautify")
pack.activateNow()
# Return promise
return activationPromise
# Set Uncrustify config path
# uncrustifyConfigPath = path.resolve(__dirname, "../examples/nested-jsbeautifyrc/uncrustify.cfg")
# uncrustifyLangs = ["c", "cpp", "objectivec", "cs", "d", "java", "pawn", "vala"]
# for lang in uncrustifyLangs
# do (lang) ->
# atom.config.set("atom-beautify.#{lang}_configPath", uncrustifyConfigPath)
# expect(atom.config.get("atom-beautify.#{lang}_configPath")).toEqual("TEST")
### ###
Directory structure: Directory structure:
- examples - examples