@@ -2,7 +2,10 @@ import PropTypes from 'prop-types';
22import React from 'react' ;
33import CodeMirror from 'codemirror' ;
44import emmet from '@emmetio/codemirror-plugin' ;
5- import beautifyJS from 'js-beautify' ;
5+ import prettier from 'prettier' ;
6+ import parserBabel from 'prettier/parser-babel' ;
7+ import htmlParser from 'prettier/parser-html' ;
8+ import cssParser from 'prettier/parser-postcss' ;
69import { withTranslation } from 'react-i18next' ;
710import 'codemirror/mode/css/css' ;
811import 'codemirror/addon/selection/active-line' ;
@@ -59,14 +62,10 @@ import * as ConsoleActions from '../actions/console';
5962
6063emmet ( CodeMirror ) ;
6164
62- const beautifyCSS = beautifyJS . css ;
63- const beautifyHTML = beautifyJS . html ;
64-
6565window . JSHINT = JSHINT ;
6666window . CSSLint = CSSLint ;
6767window . HTMLHint = HTMLHint ;
6868
69- const IS_TAB_INDENT = false ;
7069const INDENTATION_AMOUNT = 2 ;
7170
7271class Editor extends React . Component {
@@ -337,23 +336,28 @@ class Editor extends React.Component {
337336 }
338337
339338 tidyCode ( ) {
340- const beautifyOptions = {
341- indent_size : INDENTATION_AMOUNT ,
342- indent_with_tabs : IS_TAB_INDENT
343- } ;
344339 const mode = this . _cm . getOption ( 'mode' ) ;
345340 const currentPosition = this . _cm . doc . getCursor ( ) ;
346341 if ( mode === 'javascript' ) {
347342 this . _cm . doc . setValue (
348- beautifyJS ( this . _cm . doc . getValue ( ) , beautifyOptions )
343+ prettier . format ( this . _cm . doc . getValue ( ) , {
344+ parser : 'babel' ,
345+ plugins : [ parserBabel ]
346+ } )
349347 ) ;
350348 } else if ( mode === 'css' ) {
351349 this . _cm . doc . setValue (
352- beautifyCSS ( this . _cm . doc . getValue ( ) , beautifyOptions )
350+ prettier . format ( this . _cm . doc . getValue ( ) , {
351+ parser : 'css' ,
352+ plugins : [ cssParser ]
353+ } )
353354 ) ;
354355 } else if ( mode === 'htmlmixed' ) {
355356 this . _cm . doc . setValue (
356- beautifyHTML ( this . _cm . doc . getValue ( ) , beautifyOptions )
357+ prettier . format ( this . _cm . doc . getValue ( ) , {
358+ parser : 'html' ,
359+ plugins : [ htmlParser ]
360+ } )
357361 ) ;
358362 }
359363 this . _cm . focus ( ) ;
0 commit comments