Merge pull request #744 from ra100/master
PHPCBF (PHP_CodeSniffer) + Remark for Markdown support
This commit is contained in:
commit
e43952c7d3
306
docs/options.md
306
docs/options.md
|
@ -1571,6 +1571,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`
|
||||
|
@ -1715,6 +1791,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) [`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`
|
||||
|
||||
**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`
|
||||
|
@ -3317,7 +3441,7 @@ Disable Markdown Beautification
|
|||
|
||||
**Type**: `string`
|
||||
|
||||
**Enum**: `Tidy Markdown`
|
||||
**Enum**: `Remark` `Tidy Markdown`
|
||||
|
||||
**Description**:
|
||||
|
||||
|
@ -3647,7 +3771,7 @@ Disable PHP Beautification
|
|||
|
||||
**Type**: `string`
|
||||
|
||||
**Enum**: `PHP-CS-Fixer`
|
||||
**Enum**: `PHP-CS-Fixer` `PHPCBF`
|
||||
|
||||
**Description**:
|
||||
|
||||
|
@ -6478,6 +6602,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)
|
||||
|
@ -6579,6 +6782,105 @@ 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) [`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`
|
||||
|
||||
**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 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`
|
||||
|
||||
**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
|
||||
|
||||
|
|
|
@ -53,3 +53,5 @@
|
|||
indent_size: 4
|
||||
erb:
|
||||
indent_size: 4
|
||||
markdown:
|
||||
listItemIndent: 1
|
||||
|
|
|
@ -26,5 +26,8 @@
|
|||
"indent_char": " ",
|
||||
"indent_level": 0,
|
||||
"indent_with_tabs": false
|
||||
},
|
||||
"markdown": {
|
||||
"listItemIndent": "1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -49,8 +49,10 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
'jscs'
|
||||
'perltidy'
|
||||
'php-cs-fixer'
|
||||
'phpcbf'
|
||||
'prettydiff'
|
||||
'puppet-fix'
|
||||
'remark'
|
||||
'rubocop'
|
||||
'ruby-beautify'
|
||||
'rustfmt'
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
###
|
||||
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"
|
||||
]
|
||||
phpcbf_path: (phpcbf_path) -> phpcbf_path or @which('phpcbf')
|
||||
|
||||
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
|
||||
"--no-patch"
|
||||
"--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", [
|
||||
"--no-patch"
|
||||
"--standard=#{options.standard}" if options.standard
|
||||
tempFile = @tempFile("temp", text)
|
||||
], {
|
||||
ignoreReturnCode: true
|
||||
help: {
|
||||
link: "https://github.com/squizlabs/PHP_CodeSniffer"
|
||||
}
|
||||
})
|
||||
.then(=>
|
||||
@readFile(tempFile)
|
||||
)
|
|
@ -0,0 +1,43 @@
|
|||
"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
|
||||
remark = require 'remark'
|
||||
cleanMarkdown = remark.process(text, options)
|
||||
resolve cleanMarkdown
|
||||
catch err
|
||||
@error("Remark error: #{err}")
|
||||
reject(err)
|
||||
)
|
|
@ -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.'
|
||||
}
|
||||
|
|
|
@ -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 Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS rules"
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue