Ответ 1
Обновление 4
Отметьте prettier, а не тот, который настраивается как esformatter, но в настоящее время используется для форматирования некоторых крупных проектов (как и само реагирование)
Обновление 3
Отметьте sublime jsfmt. Если вы добавите esformatter-jsx в конфигурацию и установите пакет внутри forlder для sublime-jsfmt. Вы сможете форматировать файлы JSX непосредственно из Sublime. Вот руководство для этого
Обновление 2
из командной строки вы также можете использовать esbeautifier. Это оболочка esformatter, которая принимает список глобусов для форматирования
# install the dependencies globally
npm i -g esbeautifier
# beautify the files under src/ and specs/ both .js and .jsx
esbeautifier src/**/*.js* specs/**/*.js*
Обновление
Итак, я включил плагин для esformatter, чтобы включить форматирование JSX файлов:
https://www.npmjs.com/package/esformatter-jsx
Ниже приведена живая демонстрация по требованию
Как-то можно было бы вызвать esformatter из Sublime, передавая текущий файл в качестве аргумента. В любом случае, чтобы использовать его из командной строки, вы можете выполнить следующие инструкции:
В командной строке его можно использовать следующим образом:
# install the dependencies globally
npm i -g esformatter esformatter-jsx
# call it (this will print to stdout)
esformatter --plugins=esformatter-jsx ./path/to/your/file
# to actually modify the file
esformatter --plugins=esformatter-jsx ./path/to/your/file > ./path/to/your/file
# to specify a config file (where you can also specify the plugins)
# check esformatter for more info about the configuration options
esformatter -c ./path/to/.esformatter ./path/to/your/file > ./path/to/your/file
==== старый ответ ниже ===
Итак, если вы ищете просто, чтобы ваши файлы jsx были отформатированы, позволяя синтаксис jsx
(в основном украсить все синтаксисы javascript и игнорировать теги jsx
, то есть оставить их как есть), это что я делаю, используя esformatter
// needed for grunt.file.expand
var grunt = require('grunt');
// use it with care, I haven't check if there
// isn't any side effect from using proxyquire to
// inject esprima-fb into the esformatter
// but this type of dependency replacement
// seems to be very fragile... if rocambole deps change
// this will certainly break, same is true for esformatter
// use it with care
var proxyquire = require('proxyquire');
var rocambole = proxyquire('rocambole', {
'esprima': require('esprima-fb')
});
var esformatter = proxyquire('esformatter', {
rocambole: rocambole
});
// path to your esformatter configuration
var cfg = grunt.file.readJSON('./esformatter.json');
// expand the files from the glob
var files = grunt.file.expand('./js/**/*.jsx');
// do the actual formatting
files.forEach(function (fIn) {
console.log('formatting', fIn);
var output = esformatter.format(grunt.file.read(fIn), cfg);
grunt.file.write(fIn, output);
});
Мне бы очень хотелось, чтобы esformatter использовал версию rocambole, которая использует esprima-fb вместо esprima, чтобы избежать использования proxyquire.