add option to specify path for rubocop and usage in relative beautifier

This commit is contained in:
Emanuele Tonello 2015-11-19 17:45:07 +10:00
parent 9d2fbf6902
commit e138cd4dcd
2 changed files with 36 additions and 9 deletions

View File

@ -15,7 +15,6 @@ module.exports = class Rubocop extends Beautifier
beautify: (text, language, options) -> beautify: (text, language, options) ->
path = require 'path'
fs = require 'fs' fs = require 'fs'
configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml") configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml")
@ -33,11 +32,34 @@ module.exports = class Rubocop extends Beautifier
configFile = @tempFile("rubocop-config", yaml.safeDump(config)) configFile = @tempFile("rubocop-config", yaml.safeDump(config))
@debug("rubocop", config, configFile) @debug("rubocop", config, configFile)
@run("rubocop", [ @Promise.all([
"--auto-correct" @which(options.rubocop_path) if options.rubocop_path
"--config", configFile @which('rubocop')
tempFile = @tempFile("temp", text) ]).then((paths) =>
], {ignoreReturnCode: true}) @debug('php-cs-fixer paths', paths)
.then(=> _ = require 'lodash'
@readFile(tempFile) path = require 'path'
) # Get first valid, absolute path
rubocopPath = _.find(paths, (p) -> p and path.isAbsolute(p) )
@verbose('rubocopPath', rubocopPath)
@debug('rubocopPath', rubocopPath, paths)
# Check if PHP-CS-Fixer path was found
if rubocopPath?
@run("rubocop", [
rubocopPath
"--auto-correct"
"--config", configFile
tempFile = @tempFile("temp", text)
], {ignoreReturnCode: true})
.then(=>
@readFile(tempFile)
)
else
@run("rubocop", [
"--auto-correct"
"--config", configFile
tempFile = @tempFile("temp", text)
], {ignoreReturnCode: true})
.then(=>
@readFile(tempFile)
)

View File

@ -32,6 +32,11 @@ module.exports = {
default: defaultIndentSize default: defaultIndentSize
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
rubocop_path:
title: "Rubocop Path"
type: 'string'
default: ""
description: "Path to the `rubocop` CLI executable"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: defaultIndentChar