From 269d434a16e04e1aecaf9f301a4abf62f0c19972 Mon Sep 17 00:00:00 2001 From: Ra100 Date: Wed, 13 Jan 2016 15:14:16 +0100 Subject: [PATCH 1/5] adding support for phpcbf (in progress) --- src/beautifiers/index.coffee | 1 + src/beautifiers/phpcbf.coffee | 77 +++++++++++++++++++++++++++++++++++ src/languages/php.coffee | 12 ++++++ 3 files changed, 90 insertions(+) create mode 100644 src/beautifiers/phpcbf.coffee diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index da3dce7..7909d6c 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -48,6 +48,7 @@ module.exports = class Beautifiers extends EventEmitter 'jscs' 'perltidy' 'php-cs-fixer' + 'phpcbf' 'prettydiff' 'puppet-fix' 'rubocop' diff --git a/src/beautifiers/phpcbf.coffee b/src/beautifiers/phpcbf.coffee new file mode 100644 index 0000000..d18c95f --- /dev/null +++ b/src/beautifiers/phpcbf.coffee @@ -0,0 +1,77 @@ +### +Requires https://github.com/FriendsOfPHP/phpcbf +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class PHPCBF extends Beautifier + name: "PHPCBF" + + options: { + _: + standard: ["standard", (standard) -> + if (standard) then \ + standard else "PEAR" + ] + PHP: true + } + + beautify: (text, language, options) -> + @debug('phpcbf', options) + + isWin = @isWindows + if isWin + # Find phpcbf.phar script + @Promise.all([ + @which(options.phpcbf_path) if options.phpcbf_path + @which('phpcbf') + ]).then((paths) => + @debug('phpcbf paths', paths) + _ = require 'lodash' + path = require 'path' + # Get first valid, absolute path + phpcbfPath = _.find(paths, (p) -> p and path.isAbsolute(p) ) + @verbose('phpcbfPath', phpcbfPath) + @debug('phpcbfPath', phpcbfPath, paths) + # Check if phpcbf path was found + if phpcbfPath? + # Found phpcbf path + @run("php", [ + phpcbfPath + "--standard=#{options.standard}" if options.standard + tempFile = @tempFile("temp", text) + ], { + ignoreReturnCode: true + help: { + link: "http://php.net/manual/en/install.php" + } + }) + .then(=> + @readFile(tempFile) + ) + else + @verbose('phpcbf not found!') + # Could not find phpcbf path + @Promise.reject(@commandNotFoundError( + 'phpcbf' + { + link: "https://github.com/squizlabs/PHP_CodeSniffer" + program: "phpcbf.phar" + pathOption: "PHPCBF Path" + }) + ) + ) + else + @run("phpcbf", [ + "--standard=#{options.standard}" if options.standard + tempFile = @tempFile("temp", text) + ], { + ignoreReturnCode: true + help: { + link: "https://github.com/squizlabs/PHP_CodeSniffer" + } + }) + .then(=> + @readFile(tempFile) + ) diff --git a/src/languages/php.coffee b/src/languages/php.coffee index 3fd1b4b..1542611 100644 --- a/src/languages/php.coffee +++ b/src/languages/php.coffee @@ -15,6 +15,8 @@ module.exports = { ### extensions: [ "php" + "module" + "inc" ] options: @@ -31,5 +33,15 @@ module.exports = { type: 'string' default: "" description: "By default, all PSR-2 fixers and some additional ones are run." + phpcbf_path: + title: "PHPCBF Path" + type: 'string' + default: "" + description: "Path to the `phpcbf` CLI executable", + standard: + title: "PHPCBF Standard" + type: 'string' + default: "", + description: "Standard name PEAR, PSR-1, PSR-2, Symphony... or path to CS rules" } From 2bc18dd601db59f0a473b215909180c9da9945c2 Mon Sep 17 00:00:00 2001 From: Ra100 Date: Wed, 13 Jan 2016 17:05:57 +0100 Subject: [PATCH 2/5] PHPCBF support --- docs/options.md | 125 +++++++++++++++++++++++++++++++++- src/beautifiers/phpcbf.coffee | 2 + src/languages/php.coffee | 2 +- 3 files changed, 127 insertions(+), 2 deletions(-) diff --git a/docs/options.md b/docs/options.md index c57fabe..5f25324 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1691,6 +1691,54 @@ By default, all PSR-2 fixers and some additional ones are run. (Supported by PHP } ``` +#### [PHP - PHPCBF Path](#php---phpcbf-path) + +**Namespace**: `php` + +**Key**: `phpcbf_path` + +**Type**: `string` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "php": { + "phpcbf_path": "" + } +} +``` + +#### [PHP - PHPCBF Standard](#php---phpcbf-standard) + +**Namespace**: `php` + +**Key**: `standard` + +**Type**: `string` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) [`PHPCBF`](#phpcbf) + +**Description**: + +Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS rules (Supported by PHP-CS-Fixer, PHPCBF) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "php": { + "standard": "" + } +} +``` + #### [Python - Max line length](#python---max-line-length) **Namespace**: `python` @@ -3568,7 +3616,7 @@ Disable PHP Beautification **Type**: `string` -**Enum**: `PHP-CS-Fixer` +**Enum**: `PHP-CS-Fixer` `PHPCBF` **Description**: @@ -6500,6 +6548,81 @@ By default, all PSR-2 fixers and some additional ones are run. (Supported by PHP } ``` +#### [PHP - PHPCBF Path](#php---phpcbf-path) + +**Namespace**: `php` + +**Key**: `phpcbf_path` + +**Type**: `string` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "php": { + "phpcbf_path": "" + } +} +``` + +#### [PHP - PHPCBF Standard](#php---phpcbf-standard) + +**Namespace**: `php` + +**Key**: `standard` + +**Type**: `string` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) [`PHPCBF`](#phpcbf) + +**Description**: + +Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS rules (Supported by PHP-CS-Fixer, PHPCBF) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "php": { + "standard": "" + } +} +``` + + +### PHPCBF + +#### [PHP - PHPCBF Standard](#php---phpcbf-standard) + +**Namespace**: `php` + +**Key**: `standard` + +**Type**: `string` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) [`PHPCBF`](#phpcbf) + +**Description**: + +Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS rules (Supported by PHP-CS-Fixer, PHPCBF) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "php": { + "standard": "" + } +} +``` + ### autopep8 diff --git a/src/beautifiers/phpcbf.coffee b/src/beautifiers/phpcbf.coffee index d18c95f..1f88c27 100644 --- a/src/beautifiers/phpcbf.coffee +++ b/src/beautifiers/phpcbf.coffee @@ -39,6 +39,7 @@ module.exports = class PHPCBF extends Beautifier # Found phpcbf path @run("php", [ phpcbfPath + "--no-patch" "--standard=#{options.standard}" if options.standard tempFile = @tempFile("temp", text) ], { @@ -64,6 +65,7 @@ module.exports = class PHPCBF extends Beautifier ) else @run("phpcbf", [ + "--no-patch" "--standard=#{options.standard}" if options.standard tempFile = @tempFile("temp", text) ], { diff --git a/src/languages/php.coffee b/src/languages/php.coffee index 1542611..c50aa8a 100644 --- a/src/languages/php.coffee +++ b/src/languages/php.coffee @@ -42,6 +42,6 @@ module.exports = { title: "PHPCBF Standard" type: 'string' default: "", - description: "Standard name PEAR, PSR-1, PSR-2, Symphony... or path to CS rules" + description: "Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS rules" } From b0dab1ea2317b49e1cf8d33afae4ab77b1b48f0a Mon Sep 17 00:00:00 2001 From: Ra100 Date: Thu, 28 Jan 2016 12:52:56 +0100 Subject: [PATCH 3/5] add settings to beautifier --- src/beautifiers/phpcbf.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/beautifiers/phpcbf.coffee b/src/beautifiers/phpcbf.coffee index 1f88c27..9cd2392 100644 --- a/src/beautifiers/phpcbf.coffee +++ b/src/beautifiers/phpcbf.coffee @@ -14,6 +14,8 @@ module.exports = class PHPCBF extends Beautifier if (standard) then \ standard else "PEAR" ] + phpcbf_path: (phpcbf_path) -> phpcbf_path or @which('phpcbf') + PHP: true } From 2dce172228853bf79816d3148091e73606aca3cc Mon Sep 17 00:00:00 2001 From: Ra100 Date: Thu, 28 Jan 2016 13:11:09 +0100 Subject: [PATCH 4/5] add: remark for markdown --- docs/options.md | 189 +++++++++++++++++- examples/nested-jsbeautifyrc/.jsbeautifyrc | 2 + .../nested-jsbeautifyrc/.jsbeautifyrc_json | 3 + package.json | 1 + src/beautifiers/index.coffee | 1 + src/beautifiers/remark.coffee | 44 ++++ src/languages/markdown.coffee | 15 +- 7 files changed, 249 insertions(+), 6 deletions(-) create mode 100644 src/beautifiers/remark.coffee diff --git a/docs/options.md b/docs/options.md index 5f25324..da42f7e 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1547,6 +1547,82 @@ If a terminating comma should be inserted into arrays, object literals, and dest } ``` +#### [Markdown - Gfm](#markdown---gfm) + +**Namespace**: `markdown` + +**Key**: `gfm` + +**Default**: `true` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Remark`](#remark) + +**Description**: + +GitHub Flavoured Markdown (Supported by Remark) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "markdown": { + "gfm": true + } +} +``` + +#### [Markdown - Yaml](#markdown---yaml) + +**Namespace**: `markdown` + +**Key**: `yaml` + +**Default**: `true` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Remark`](#remark) + +**Description**: + +Enables raw YAML front matter to be detected (thus ignoring markdown-like syntax). (Supported by Remark) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "markdown": { + "yaml": true + } +} +``` + +#### [Markdown - Commonmark](#markdown---commonmark) + +**Namespace**: `markdown` + +**Key**: `commonmark` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Remark`](#remark) + +**Description**: + +Allows and disallows several constructs. (Supported by Remark) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "markdown": { + "commonmark": false + } +} +``` + #### [Objective-C - Config Path](#objective-c---config-path) **Namespace**: `objectivec` @@ -1699,11 +1775,11 @@ By default, all PSR-2 fixers and some additional ones are run. (Supported by PHP **Type**: `string` -**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) [`PHPCBF`](#phpcbf) **Description**: -Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer) +Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer, PHPCBF) **Example `.jsbeautifyrc` Configuration** @@ -3286,7 +3362,7 @@ Disable Markdown Beautification **Type**: `string` -**Enum**: `Tidy Markdown` +**Enum**: `Remark` `Tidy Markdown` **Description**: @@ -6447,6 +6523,85 @@ Path to the emacs script (Supported by Fortran Beautifier) ``` +### Remark + +#### [Markdown - Gfm](#markdown---gfm) + +**Namespace**: `markdown` + +**Key**: `gfm` + +**Default**: `true` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Remark`](#remark) + +**Description**: + +GitHub Flavoured Markdown (Supported by Remark) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "markdown": { + "gfm": true + } +} +``` + +#### [Markdown - Yaml](#markdown---yaml) + +**Namespace**: `markdown` + +**Key**: `yaml` + +**Default**: `true` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Remark`](#remark) + +**Description**: + +Enables raw YAML front matter to be detected (thus ignoring markdown-like syntax). (Supported by Remark) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "markdown": { + "yaml": true + } +} +``` + +#### [Markdown - Commonmark](#markdown---commonmark) + +**Namespace**: `markdown` + +**Key**: `commonmark` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Remark`](#remark) + +**Description**: + +Allows and disallows several constructs. (Supported by Remark) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "markdown": { + "commonmark": false + } +} +``` + + ### Perltidy #### [Perl - Perltidy profile](#perl---perltidy-profile) @@ -6556,11 +6711,11 @@ By default, all PSR-2 fixers and some additional ones are run. (Supported by PHP **Type**: `string` -**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) [`PHPCBF`](#phpcbf) **Description**: -Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer) +Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer, PHPCBF) **Example `.jsbeautifyrc` Configuration** @@ -6599,6 +6754,30 @@ Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS ru ### PHPCBF +#### [PHP - PHPCBF Path](#php---phpcbf-path) + +**Namespace**: `php` + +**Key**: `phpcbf_path` + +**Type**: `string` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) [`PHPCBF`](#phpcbf) + +**Description**: + +Path to the `phpcbf` CLI executable (Supported by PHP-CS-Fixer, PHPCBF) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "php": { + "phpcbf_path": "" + } +} +``` + #### [PHP - PHPCBF Standard](#php---phpcbf-standard) **Namespace**: `php` diff --git a/examples/nested-jsbeautifyrc/.jsbeautifyrc b/examples/nested-jsbeautifyrc/.jsbeautifyrc index 515c921..ecb81ca 100644 --- a/examples/nested-jsbeautifyrc/.jsbeautifyrc +++ b/examples/nested-jsbeautifyrc/.jsbeautifyrc @@ -38,3 +38,5 @@ indent_size: 4 erb: indent_size: 4 + markdown: + listItemIndent: 1 diff --git a/examples/nested-jsbeautifyrc/.jsbeautifyrc_json b/examples/nested-jsbeautifyrc/.jsbeautifyrc_json index 784aa30..5023d6c 100644 --- a/examples/nested-jsbeautifyrc/.jsbeautifyrc_json +++ b/examples/nested-jsbeautifyrc/.jsbeautifyrc_json @@ -26,5 +26,8 @@ "indent_char": " ", "indent_level": 0, "indent_with_tabs": false + }, + "markdown": { + "listItemIndent": "1" } } diff --git a/package.json b/package.json index 678c2e0..a090236 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "node-dir": "^0.1.8", "node-uuid": "^1.4.3", "prettydiff": "^1.16.8", + "remark": "^3.2.2", "season": "^5.3.0", "space-pen": "^5.1.1", "strip-json-comments": "^1.0.2", diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 7909d6c..abbf8ee 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -51,6 +51,7 @@ module.exports = class Beautifiers extends EventEmitter 'phpcbf' 'prettydiff' 'puppet-fix' + 'remark' 'rubocop' 'ruby-beautify' 'rustfmt' diff --git a/src/beautifiers/remark.coffee b/src/beautifiers/remark.coffee new file mode 100644 index 0000000..9def8de --- /dev/null +++ b/src/beautifiers/remark.coffee @@ -0,0 +1,44 @@ +"use strict" +Beautifier = require('./beautifier') + +module.exports = class Remark extends Beautifier + name: "Remark" + options: { + _: { + gfm: true + yaml: true + commonmark: true + footnotes: true + pedantic: true + breaks: true + entities: true + setext: true + closeAtx: true + looseTable: true + spacedTable: true + fence: true + fences: true + bullet: true + listItemIndent: true + incrementListMarker: true + rule: true + ruleRepetition: true + ruleSpaces: true + strong: true + emphasis: true + position: true + } + Markdown: true + } + + beautify: (text, language, options) -> + return new @Promise((resolve, reject) -> + try + console.log(options) + remark = require 'remark' + cleanMarkdown = remark.process(text, options) + resolve cleanMarkdown + catch err + @error("Remark error: #{err}") + reject(err) + ) diff --git a/src/languages/markdown.coffee b/src/languages/markdown.coffee index 4bc1ad7..2f6aaea 100644 --- a/src/languages/markdown.coffee +++ b/src/languages/markdown.coffee @@ -18,6 +18,19 @@ module.exports = { "md" ] - options: [] + defaultBeautifier: "Tidy Markdown" + options: + gfm: + type: 'boolean' + default: true + description: 'GitHub Flavoured Markdown' + yaml: + type: 'boolean' + default: true + description: 'Enables raw YAML front matter to be detected (thus ignoring markdown-like syntax).' + commonmark: + type: 'boolean' + default: false + description: 'Allows and disallows several constructs.' } From 6d73fa02347d3f5de2589297f39ed5802439ddfa Mon Sep 17 00:00:00 2001 From: Ra100 Date: Thu, 28 Jan 2016 15:43:56 +0100 Subject: [PATCH 5/5] remove console.log --- src/beautifiers/remark.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/beautifiers/remark.coffee b/src/beautifiers/remark.coffee index 9def8de..8cd8861 100644 --- a/src/beautifiers/remark.coffee +++ b/src/beautifiers/remark.coffee @@ -34,7 +34,6 @@ module.exports = class Remark extends Beautifier beautify: (text, language, options) -> return new @Promise((resolve, reject) -> try - console.log(options) remark = require 'remark' cleanMarkdown = remark.process(text, options) resolve cleanMarkdown