Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typescript-formatter and add tsx support #2021

Merged
merged 3 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new language tsx, add tsx support to typescript-formatter
  • Loading branch information
stevenzeck committed Jan 30, 2018
commit aefb7794d669ad853490e005b1ea7b075c96f099
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti
| Swig | `HTML (Swig)`, `SWIG` |`.swig` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
| Terraform | `Terraform` |`.tf` | **[`terraformfmt`](https://www.terraform.io/docs/commands/fmt.html)** |
| TSS | `TSS` |`.tss` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
| TSX | `TypeScriptReact` |`.tsx` | **[`TypeScript Formatter`](https://github.com/vvakame/typescript-formatter)** |
| Twig | `HTML (Twig)` |`.twig` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
| TypeScript | `TypeScript` |`.ts` | **[`TypeScript Formatter`](https://github.com/vvakame/typescript-formatter)** |
| UX Markup | `UX` |`.ux` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** |
Expand Down
69 changes: 69 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12622,6 +12622,75 @@ Maximum amount of characters per line (0 = disable) (Supported by Pretty Diff)
}
```

#### [TSX](#tsx)

**Supported Beautifiers**: [`TypeScript Formatter`](#typescript-formatter)

| Option | TypeScript Formatter |
| --- | --- |
| `disabled` | :white_check_mark: |
| `default_beautifier` | :white_check_mark: |
| `beautify_on_save` | :white_check_mark: |

**Description**:

Options for language TSX

##### [Disable Beautifying Language](#disable-beautifying-language)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `boolean`

**Description**:

Disable TSX Beautification

**How to Configure**

1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Disable Beautifying Language*" and change it to your desired configuration.

##### [Default Beautifier](#default-beautifier)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Default**: `TypeScript Formatter`

**Type**: `string`

**Enum**: `TypeScript Formatter`

**Description**:

Default Beautifier to be used for TSX

**How to Configure**

1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Default Beautifier*" and change it to your desired configuration.

##### [Beautify On Save](#beautify-on-save)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `boolean`

**Description**:

Automatically beautify TSX files on save

**How to Configure**

1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Beautify On Save*" and change it to your desired configuration.

#### [Twig](#twig)

**Supported Beautifiers**: [`Pretty Diff`](#pretty-diff)
Expand Down
12 changes: 12 additions & 0 deletions examples/simple-jsbeautifyrc/tsx/expected/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Test extends React.Component<Foo> {
render() {
return (
<div className="class" >
<h2 className="anotherClass" >
{ this.foo.bar }
< /h2>
{ this.foo.bar.children }
</div>
);
}
}
12 changes: 12 additions & 0 deletions examples/simple-jsbeautifyrc/tsx/original/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Test extends React.Component<Foo> {
render() {
return (
<div className="class">
<h2 className="anotherClass">
{this.foo.bar}
</h2>
{this.foo.bar.children}
</div>
);
}
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,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"
Expand Down Expand Up @@ -412,7 +413,8 @@
"align-yaml",
"goimports",
"terraform",
"terraformfmt"
"terraformfmt",
"tsx"
],
"devDependencies": {
"coffeelint": "1.16.0"
Expand Down Expand Up @@ -449,4 +451,4 @@
"prettydiff2"
]
}
}
}
1 change: 1 addition & 0 deletions src/beautifiers/typescript-formatter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = class TypeScriptFormatter extends Beautifier
link: "https://github.com/vvakame/typescript-formatter"
options: {
TypeScript: true
TSX: true
}

beautify: (text, language, options) ->
Expand Down
1 change: 1 addition & 0 deletions src/languages/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = class Languages
"svg"
"swig"
"tss"
"tsx"
"twig"
"typescript"
"ux_markup"
Expand Down
21 changes: 21 additions & 0 deletions src/languages/tsx.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {

name: "TSX"
namespace: "tsx"
fallback: ['ts']

###
Supported Grammars
###
grammars: [
"TypeScriptReact"
]

###
Supported extensions
###
extensions: [
"tsx"
]

}
41 changes: 41 additions & 0 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -7365,6 +7365,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",
Expand Down