Merge pull request #1010 from sharifzadesina/master
Add .php_cs file support to php-cs-fixer beautifier
This commit is contained in:
commit
66be231b95
|
@ -1,10 +1,11 @@
|
|||
Promise = require("bluebird")
|
||||
Promise = require('bluebird')
|
||||
_ = require('lodash')
|
||||
fs = require("fs")
|
||||
temp = require("temp").track()
|
||||
fs = require('fs')
|
||||
temp = require('temp').track()
|
||||
readFile = Promise.promisify(fs.readFile)
|
||||
which = require('which')
|
||||
spawn = require('child_process').spawn
|
||||
path = require('path')
|
||||
|
||||
module.exports = class Beautifier
|
||||
|
||||
|
@ -27,7 +28,6 @@ module.exports = class Beautifier
|
|||
- <string:language>:<string:option_key>:<string:rename>
|
||||
- <string:language>:<string:option_key>:<function:transform>
|
||||
- <string:language>:<string:option_key>:<array:mapper>
|
||||
|
||||
###
|
||||
options: {}
|
||||
|
||||
|
@ -79,6 +79,24 @@ module.exports = class Beautifier
|
|||
return readFile(filePath, "utf8")
|
||||
)
|
||||
|
||||
###
|
||||
Find file
|
||||
###
|
||||
findFile: (startDir, fileNames) ->
|
||||
throw new Error "Specify file names to find." unless arguments.length
|
||||
unless fileNames instanceof Array
|
||||
fileNames = [fileNames]
|
||||
startDir = startDir.split(path.sep)
|
||||
while startDir.length
|
||||
currentDir = startDir.join(path.sep)
|
||||
for fileName in fileNames
|
||||
filePath = path.join(currentDir, fileName)
|
||||
try
|
||||
fs.accessSync(filePath, fs.R_OK)
|
||||
return filePath
|
||||
startDir.pop()
|
||||
return null
|
||||
|
||||
###
|
||||
If platform is Windows
|
||||
###
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
Beautifier = require('./beautifier')
|
||||
|
||||
module.exports = class MarkoBeautifier extends Beautifier
|
||||
|
||||
name: 'Marko Beautifier'
|
||||
|
||||
options:
|
||||
|
@ -22,7 +23,7 @@ module.exports = class MarkoBeautifier extends Beautifier
|
|||
|
||||
prettyprintOptions =
|
||||
syntax : options.syntax
|
||||
filename: if context.filePath then context.filePath else require.resolve('marko-prettyprint')
|
||||
filename: if context? and context.filePath? then context.filePath else require.resolve('marko-prettyprint')
|
||||
indent: indent
|
||||
|
||||
try
|
||||
|
|
|
@ -4,19 +4,21 @@ Requires https://github.com/FriendsOfPHP/PHP-CS-Fixer
|
|||
|
||||
"use strict"
|
||||
Beautifier = require('./beautifier')
|
||||
path = require('path')
|
||||
|
||||
module.exports = class PHPCSFixer extends Beautifier
|
||||
name: "PHP-CS-Fixer"
|
||||
|
||||
options: {
|
||||
name: 'PHP-CS-Fixer'
|
||||
|
||||
options:
|
||||
PHP: true
|
||||
}
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
beautify: (text, language, options, context) ->
|
||||
@debug('php-cs-fixer', options)
|
||||
|
||||
isWin = @isWindows
|
||||
if isWin
|
||||
configFile = if context? and context.filePath? then @findFile(path.dirname(context.filePath), '.php_cs')
|
||||
|
||||
if @isWindows
|
||||
# Find php-cs-fixer.phar script
|
||||
@Promise.all([
|
||||
@which(options.cs_fixer_path) if options.cs_fixer_path
|
||||
|
@ -24,7 +26,6 @@ module.exports = class PHPCSFixer extends Beautifier
|
|||
]).then((paths) =>
|
||||
@debug('php-cs-fixer paths', paths)
|
||||
_ = require 'lodash'
|
||||
path = require 'path'
|
||||
# Get first valid, absolute path
|
||||
phpCSFixerPath = _.find(paths, (p) -> p and path.isAbsolute(p) )
|
||||
@verbose('phpCSFixerPath', phpCSFixerPath)
|
||||
|
@ -37,6 +38,7 @@ module.exports = class PHPCSFixer extends Beautifier
|
|||
"fix"
|
||||
"--level=#{options.level}" if options.level
|
||||
"--fixers=#{options.fixers}" if options.fixers
|
||||
"--config-file=#{configFile}" if configFile
|
||||
tempFile = @tempFile("temp", text)
|
||||
], {
|
||||
ignoreReturnCode: true
|
||||
|
@ -64,6 +66,7 @@ module.exports = class PHPCSFixer extends Beautifier
|
|||
"fix"
|
||||
"--level=#{options.level}" if options.level
|
||||
"--fixers=#{options.fixers}" if options.fixers
|
||||
"--config-file=#{configFile}" if configFile
|
||||
tempFile = @tempFile("temp", text)
|
||||
], {
|
||||
ignoreReturnCode: true
|
||||
|
|
Loading…
Reference in New Issue