add option to specify path for rubocop and usage in relative beautifier
This commit is contained in:
parent
9d2fbf6902
commit
e138cd4dcd
|
@ -15,7 +15,6 @@ module.exports = class Rubocop extends Beautifier
|
|||
|
||||
beautify: (text, language, options) ->
|
||||
|
||||
path = require 'path'
|
||||
fs = require 'fs'
|
||||
|
||||
configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml")
|
||||
|
@ -33,6 +32,29 @@ module.exports = class Rubocop extends Beautifier
|
|||
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)
|
||||
_ = 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)
|
||||
# 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
|
||||
|
|
|
@ -32,6 +32,11 @@ module.exports = {
|
|||
default: defaultIndentSize
|
||||
minimum: 0
|
||||
description: "Indentation size/length"
|
||||
rubocop_path:
|
||||
title: "Rubocop Path"
|
||||
type: 'string'
|
||||
default: ""
|
||||
description: "Path to the `rubocop` CLI executable"
|
||||
indent_char:
|
||||
type: 'string'
|
||||
default: defaultIndentChar
|
||||
|
|
Loading…
Reference in New Issue