{
+ render() {
+ return (
+
+
+ {this.foo.bar}
+
+ {this.foo.bar.children}
+
+ );
+ }
+}
\ No newline at end of file
diff --git a/examples/simple-jsbeautifyrc/tsx/original/test.tsx b/examples/simple-jsbeautifyrc/tsx/original/test.tsx
new file mode 100644
index 0000000..5d2797f
--- /dev/null
+++ b/examples/simple-jsbeautifyrc/tsx/original/test.tsx
@@ -0,0 +1,12 @@
+class Test extends React.Component {
+render() {
+ return (
+
+
+ {this.foo.bar}
+
+{this.foo.bar.children}
+
+ );
+}
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index aeda73b..cf3115b 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,12 @@
{
"name": "atom-beautify",
"main": "./src/beautify",
- "version": "0.30.6",
+ "version": "0.30.9",
"private": true,
"description": "Beautify HTML, CSS, JavaScript, PHP, Python, Ruby, Java, C, C++, C#, Objective-C, CoffeeScript, TypeScript, Coldfusion, SQL, and more in Atom",
"repository": {
"type": "git",
- "url": "https://github.com/Glavin001/atom-beautify"
+ "url": "git@github.com:Glavin001/atom-beautify.git"
},
"bugs": {
"url": "https://github.com/Glavin001/atom-beautify/issues"
@@ -158,31 +158,31 @@
}
],
"engines": {
- "atom": ">=1.6.0 <2.0.0"
+ "atom": ">=1.21.0 <2.0.0"
},
"dependencies": {
"align-yaml": "^0.1.8",
- "async": "^2.4.1",
+ "async": "^2.6.0",
"atom-message-panel": "^1.3.0",
"atom-space-pen-views": "^2.2.0",
- "bluebird": "^3.5.0",
+ "bluebird": "^3.5.1",
"coffee-fmt": "^0.12.0",
"coffee-formatter": "^0.1.2",
"coffee-script": "^1.12.6",
"csscomb": "^4.2.0",
- "diff": "^3.2.0",
- "editorconfig": "^0.13.2",
- "eslint": "^4.0.0",
- "event-kit": "^2.3.0",
+ "diff": "^3.4.0",
+ "editorconfig": "^0.15.0",
+ "eslint": "^4.16.0",
+ "event-kit": "^2.4.0",
"expand-home-dir": "0.0.3",
"extend": "^3.0.1",
"gherkin": "^2.12.2",
- "handlebars": "^4.0.10",
- "js-beautify": "^1.6.14",
+ "handlebars": "^4.0.11",
+ "js-beautify": "^1.7.5",
"jscs": "^3.0.7",
"lodash": "^4.17.4",
"loophole": "^1.1.0",
- "marko-prettyprint": "^1.3.6",
+ "marko-prettyprint": "^1.4.0",
"nginxbeautify": "^2.0.1",
"node-cljfmt": "0.5.3",
"node-dir": "0.1.17",
@@ -191,19 +191,19 @@
"prettydiff2": "^2.2.7",
"pug-beautify": "^0.1.1",
"remark": "6.0.1",
- "season": "6.0.0",
- "semver": "^5.3.0",
+ "season": "^6.0.2",
+ "semver": "^5.5.0",
"shell-env": "^0.3.0",
"space-pen": "5.1.2",
"strip-json-comments": "^2.0.1",
"temp": "^0.8.3",
- "tidy-markdown": "2.0.3",
- "typescript": "2.4.1",
- "typescript-formatter": "5.2.0",
+ "tidy-markdown": "2.0.4",
+ "typescript": "^2.6.2",
+ "typescript-formatter": "^7.0.0",
"underscore-plus": "^1.6.6",
- "universal-analytics": "0.4.13",
- "which": "1.2.14",
- "winston": "2.3.1",
+ "universal-analytics": "^0.4.16",
+ "which": "^1.3.0",
+ "winston": "^2.4.0",
"yaml-front-matter": "3.4.0"
},
"activationHooks": [
@@ -282,7 +282,8 @@
"atom-beautify:beautify-language-xml",
"atom-beautify:beautify-language-xtemplate",
"atom-beautify:beautify-language-yaml",
- "atom-beautify:beautify-language-terraform"
+ "atom-beautify:beautify-language-terraform",
+ "atom-beautify:beautify-language-tsx"
],
".tree-view .file .name": [
"atom-beautify:beautify-file"
@@ -419,7 +420,8 @@
"align-yaml",
"goimports",
"terraform",
- "terraformfmt"
+ "terraformfmt",
+ "tsx"
],
"devDependencies": {
"coffeelint": "1.16.0"
diff --git a/packages.config b/packages.config
new file mode 100644
index 0000000..0c544bc
--- /dev/null
+++ b/packages.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..e3d1477
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,4 @@
+autopep8
+isort
+sqlparse
+beautysh
diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee
index 87204cc..4310acd 100644
--- a/spec/beautify-languages-spec.coffee
+++ b/spec/beautify-languages-spec.coffee
@@ -54,6 +54,7 @@ describe "BeautifyLanguages", ->
dependentPackages = [
'autocomplete-plus'
'fuse'
+ 'react'
# 'linter'
# 'atom-typescript' # it logs too much...
]
diff --git a/src/beautifiers/ocp-indent.coffee b/src/beautifiers/ocp-indent.coffee
index 22c0463..7c196de 100644
--- a/src/beautifiers/ocp-indent.coffee
+++ b/src/beautifiers/ocp-indent.coffee
@@ -8,7 +8,24 @@ Beautifier = require('./beautifier')
module.exports = class OCPIndent extends Beautifier
name: "ocp-indent"
link: "https://www.typerex.org/ocp-indent.html"
- isPreInstalled: false
+ executables: [
+ {
+ name: "ocp-indent"
+ cmd: "ocp-indent"
+ homepage: "https://www.typerex.org/ocp-indent.html"
+ installation: "https://www.typerex.org/ocp-indent.html#installation"
+ version: {
+ parse: (text) ->
+ try
+ text.match(/(\d+\.\d+\.\d+)/)[1]
+ catch
+ text.match(/(\d+\.\d+)/)[1] + ".0"
+ }
+ docker: {
+ image: "unibeautify/ocp-indent"
+ }
+ }
+ ]
options: {
OCaml: true
@@ -21,4 +38,4 @@ module.exports = class OCPIndent extends Beautifier
help: {
link: "https://www.typerex.org/ocp-indent.html"
}
- })
+ })
\ No newline at end of file
diff --git a/src/beautifiers/puppet-fix.coffee b/src/beautifiers/puppet-fix.coffee
index 4ae96ed..4a22325 100644
--- a/src/beautifiers/puppet-fix.coffee
+++ b/src/beautifiers/puppet-fix.coffee
@@ -8,21 +8,28 @@ module.exports = class PuppetFix extends Beautifier
# this is what displays as your Default Beautifier in Language Config
name: "puppet-lint"
link: "http://puppet-lint.com/"
- isPreInstalled: false
options: {
Puppet: true
}
- cli: (options) ->
- if not options.puppet_path?
- return new Error("'puppet-lint' path is not set!" +
- " Please set this in the Atom Beautify package settings.")
- else
- return options.puppet_path
+ executables: [
+ {
+ name: "puppet-lint"
+ cmd: "puppet-lint"
+ homepage: "http://puppet-lint.com/"
+ installation: "http://puppet-lint.com/"
+ version: {
+ parse: (text) -> text.match(/puppet-lint (\d+\.\d+\.\d+)/)[1]
+ }
+ docker: {
+ image: "unibeautify/puppet-lint"
+ }
+ }
+ ]
beautify: (text, language, options) ->
- @run("puppet-lint", [
+ @exe("puppet-lint").run([
'--fix'
tempFile = @tempFile("input", text)
], {
diff --git a/src/beautifiers/typescript-formatter.coffee b/src/beautifiers/typescript-formatter.coffee
index 1a0f204..7ca7fd7 100644
--- a/src/beautifiers/typescript-formatter.coffee
+++ b/src/beautifiers/typescript-formatter.coffee
@@ -6,13 +6,14 @@ module.exports = class TypeScriptFormatter extends Beautifier
link: "https://github.com/vvakame/typescript-formatter"
options: {
TypeScript: true
+ TSX: true
}
beautify: (text, language, options) ->
return new @Promise((resolve, reject) =>
try
- format = require("typescript-formatter/lib/formatter").default
+ format = require("typescript-formatter/lib/formatter").format
formatterUtils = require("typescript-formatter/lib/utils")
# @verbose('format', format, formatterUtils)
@@ -25,8 +26,13 @@ module.exports = class TypeScriptFormatter extends Beautifier
opts.indentSize = options.indent_size
opts.indentStyle = 'space'
+ if language is "TSX"
+ fileName = 'test.tsx'
+ else
+ fileName = ''
+
@verbose('typescript', text, opts)
- result = format('', text, opts)
+ result = format(fileName, text, opts)
@verbose(result)
resolve result
catch e
diff --git a/src/beautify.coffee b/src/beautify.coffee
index 3a850a4..af517ec 100644
--- a/src/beautify.coffee
+++ b/src/beautify.coffee
@@ -96,9 +96,10 @@ beautify = ({ editor, onSave, language }) ->
if not text?
# Do nothing, is undefined
# console.log 'beautifyCompleted'
+ return resolve(text)
else if text instanceof Error
showError(text)
- return reject(text)
+ return resolve(text)
else if typeof text is "string"
if oldText isnt text
@@ -127,15 +128,18 @@ beautify = ({ editor, onSave, language }) ->
# otherwise setScrollTop is not working, probably because the cursor
# addition happens asynchronously
setTimeout ( ->
-
# console.log "setScrollTop"
setScrollTop editor, origScrollTop
return resolve(text)
), 0
+ else
+ return setTimeout(() ->
+ resolve(text)
+ , 0)
else
error = new Error("Unsupported beautification result '#{text}'.")
showError(error)
- return reject(error)
+ return resolve(text)
# else
# console.log "Already Beautiful!"
@@ -506,20 +510,17 @@ debug = () ->
handleSaveEvent = ->
atom.workspace.observeTextEditors (editor) ->
- pendingPaths = {}
beautifyOnSaveHandler = ({path: filePath}) ->
- logger.verbose('Should beautify on this save?')
- if pendingPaths[filePath]
- logger.verbose("Editor with file path #{filePath} already beautified!")
- return
- buffer = editor.getBuffer()
path ?= require('path')
- # Get Grammar
- grammar = editor.getGrammar().name
# Get file extension
fileExtension = path.extname(filePath)
# Remove prefix "." (period) in fileExtension
fileExtension = fileExtension.substr(1)
+ # Set path of buffer for unsaved files
+ if editor.getPath() is undefined
+ editor.getBuffer().setPath(filePath)
+ # Get Grammar from the editor
+ grammar = editor.getGrammar().name
# Get language
languages = beautifier.languages.getLanguages({grammar, extension: fileExtension})
if languages.length < 1
@@ -535,23 +536,11 @@ handleSaveEvent = ->
beautify({editor, onSave: true})
.then(() ->
logger.verbose('Done beautifying file', filePath)
- if editor.isAlive() is true
- logger.verbose('Saving TextEditor...')
- # Store the filePath to prevent infinite looping
- # When Whitespace package has option "Ensure Single Trailing Newline" enabled
- # It will add a newline and keep the file from converging on a beautified form
- # and saving without emitting onDidSave event, because there were no changes.
- pendingPaths[filePath] = true
- Promise.resolve(editor.save()).then(() ->
- delete pendingPaths[filePath]
- logger.verbose('Saved TextEditor.')
- )
)
.catch((error) ->
return showError(error)
)
- disposable = editor.onDidSave(({path : filePath}) ->
- # TODO: Implement debouncing
+ disposable = editor.getBuffer().onWillSave(({path: filePath}) ->
beautifyOnSaveHandler({path: filePath})
)
plugin.subscriptions.add disposable
@@ -632,4 +621,4 @@ plugin.activate = ->
@addLanguageCommands()
plugin.deactivate = ->
- @subscriptions.dispose()
+ @subscriptions.dispose()
\ No newline at end of file
diff --git a/src/languages/index.coffee b/src/languages/index.coffee
index 7cc1e5c..69c14a8 100644
--- a/src/languages/index.coffee
+++ b/src/languages/index.coffee
@@ -68,6 +68,7 @@ module.exports = class Languages
"svg"
"swig"
"tss"
+ "tsx"
"twig"
"typescript"
"ux_markup"
diff --git a/src/languages/tsx.coffee b/src/languages/tsx.coffee
new file mode 100644
index 0000000..7625b88
--- /dev/null
+++ b/src/languages/tsx.coffee
@@ -0,0 +1,21 @@
+module.exports = {
+
+ name: "TSX"
+ namespace: "tsx"
+ fallback: ['ts']
+
+ ###
+ Supported Grammars
+ ###
+ grammars: [
+ "TypeScriptReact"
+ ]
+
+ ###
+ Supported extensions
+ ###
+ extensions: [
+ "tsx"
+ ]
+
+}
diff --git a/src/options.json b/src/options.json
index a68b359..2168e0c 100644
--- a/src/options.json
+++ b/src/options.json
@@ -7369,6 +7369,47 @@
}
}
},
+ "tsx": {
+ "title": "TSX",
+ "type": "object",
+ "description": "Options for language TSX",
+ "collapsed": true,
+ "beautifiers": [
+ "TypeScript Formatter"
+ ],
+ "grammars": [
+ "TypeScriptReact"
+ ],
+ "extensions": [
+ "tsx"
+ ],
+ "properties": {
+ "disabled": {
+ "title": "Disable Beautifying Language",
+ "order": -3,
+ "type": "boolean",
+ "default": false,
+ "description": "Disable TSX Beautification"
+ },
+ "default_beautifier": {
+ "title": "Default Beautifier",
+ "order": -2,
+ "type": "string",
+ "default": "TypeScript Formatter",
+ "description": "Default Beautifier to be used for TSX",
+ "enum": [
+ "TypeScript Formatter"
+ ]
+ },
+ "beautify_on_save": {
+ "title": "Beautify On Save",
+ "order": -1,
+ "type": "boolean",
+ "default": false,
+ "description": "Automatically beautify TSX files on save"
+ }
+ }
+ },
"twig": {
"title": "Twig",
"type": "object",
@@ -9324,6 +9365,22 @@
}
}
},
+ "ocp-indent": {
+ "key": "ocp-indent",
+ "title": "ocp-indent",
+ "type": "object",
+ "collapsed": true,
+ "description": "Options for ocp-indent executable.",
+ "properties": {
+ "path": {
+ "key": "path",
+ "title": "Binary/Script Path",
+ "type": "string",
+ "default": "",
+ "description": "Absolute path to the \"ocp-indent\" executable's binary/script."
+ }
+ }
+ },
"php": {
"key": "php",
"title": "PHP",
@@ -9372,6 +9429,22 @@
}
}
},
+ "puppet-lint": {
+ "key": "puppet-lint",
+ "title": "puppet-lint",
+ "type": "object",
+ "collapsed": true,
+ "description": "Options for puppet-lint executable.",
+ "properties": {
+ "path": {
+ "key": "path",
+ "title": "Binary/Script Path",
+ "type": "string",
+ "default": "",
+ "description": "Absolute path to the \"puppet-lint\" executable's binary/script."
+ }
+ }
+ },
"sass-convert": {
"key": "sass-convert",
"title": "SassConvert",