adding support for phpcbf (in progress)

This commit is contained in:
Ra100 2016-01-13 15:14:16 +01:00
parent 2959adb4eb
commit 269d434a16
3 changed files with 90 additions and 0 deletions

View File

@ -48,6 +48,7 @@ module.exports = class Beautifiers extends EventEmitter
'jscs'
'perltidy'
'php-cs-fixer'
'phpcbf'
'prettydiff'
'puppet-fix'
'rubocop'

View File

@ -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)
)

View File

@ -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"
}