fixed path retrieval

This commit is contained in:
Emanuele Tonello 2015-11-20 09:24:53 +10:00
parent e138cd4dcd
commit 32df741007
1 changed files with 22 additions and 21 deletions

View File

@ -11,42 +11,42 @@ module.exports = class Rubocop extends Beautifier
options: {
Ruby:
indent_size: true
rubocop_path: true
}
beautify: (text, language, options) ->
fs = require 'fs'
configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml")
if fs.existsSync(configFile)
@debug("rubocop", config, fs.readFileSync(configFile, 'utf8'))
else
yaml = require("yaml-front-matter")
# Generate config file
config = {
"Style/IndentationWidth":
"Width": options.indent_size
}
configFile = @tempFile("rubocop-config", yaml.safeDump(config))
@debug("rubocop", config, configFile)
@Promise.all([
@which(options.rubocop_path) if options.rubocop_path
@which('rubocop')
]).then((paths) =>
@debug('php-cs-fixer paths', paths)
@debug('rubocop paths', paths)
_ = require 'lodash'
path = require 'path'
# Get first valid, absolute path
rubocopPath = _.find(paths, (p) -> p and path.isAbsolute(p) )
@verbose('rubocopPath', rubocopPath)
@debug('rubocopPath', rubocopPath, paths)
configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml")
fs = require 'fs'
if fs.existsSync(configFile)
@debug("rubocop", config, fs.readFileSync(configFile, 'utf8'))
else
yaml = require("yaml-front-matter")
# Generate config file
config = {
"Style/IndentationWidth":
"Width": options.indent_size
}
configFile = @tempFile("rubocop-config", yaml.safeDump(config))
@debug("rubocop", config, configFile)
# Check if PHP-CS-Fixer path was found
if rubocopPath?
@run("rubocop", [
rubocopPath
@run(rubocopPath, [
"--auto-correct"
"--config", configFile
tempFile = @tempFile("temp", text)
@ -63,3 +63,4 @@ module.exports = class Rubocop extends Beautifier
.then(=>
@readFile(tempFile)
)
)