From bc21afd424728591ea45eb8c1153df0a1b719a70 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 28 May 2017 18:21:10 -0300 Subject: [PATCH 01/58] Add Executable class to abstract CLI beautifiers --- docs/index.coffee | 2 + package.json | 2 + spec/atom-beautify-spec.coffee | 7 +- spec/beautifier-php-cs-fixer-spec.coffee | 28 +- src/beautifiers/beautifier.coffee | 276 ++++---------------- src/beautifiers/executable.coffee | 309 +++++++++++++++++++++++ src/beautifiers/gherkin.coffee | 4 +- src/beautifiers/index.coffee | 56 ++-- src/beautifiers/php-cs-fixer.coffee | 38 ++- src/beautifiers/phpcbf.coffee | 11 + 10 files changed, 453 insertions(+), 280 deletions(-) create mode 100644 src/beautifiers/executable.coffee diff --git a/docs/index.coffee b/docs/index.coffee index 90c3e5c..61b4dbe 100755 --- a/docs/index.coffee +++ b/docs/index.coffee @@ -157,6 +157,8 @@ Handlebars.registerHelper('beautifiers-info', (beautifiers, options) -> rows = _.map(beautifiers, (beautifier, k) -> name = beautifier.name isPreInstalled = beautifier.isPreInstalled + if typeof isPreInstalled is "function" + isPreInstalled = beautifier.isPreInstalled() link = beautifier.link installationInstructions = if isPreInstalled then "Nothing!" else "Go to #{link} and follow the instructions." return "| #{name} | #{if isPreInstalled then ':white_check_mark:' else ':x:'} | #{installationInstructions} |" diff --git a/package.json b/package.json index 1f704c7..5234181 100644 --- a/package.json +++ b/package.json @@ -179,6 +179,8 @@ "pug-beautify": "^0.1.1", "remark": "^6.0.1", "season": "^5.3.0", + "semver": "^5.3.0", + "shell-env": "^0.3.0", "space-pen": "^5.1.1", "strip-json-comments": "^2.0.1", "temp": "^0.8.3", diff --git a/spec/atom-beautify-spec.coffee b/spec/atom-beautify-spec.coffee index fcd3db9..d128a7e 100644 --- a/spec/atom-beautify-spec.coffee +++ b/spec/atom-beautify-spec.coffee @@ -1,4 +1,5 @@ Beautifiers = require "../src/beautifiers" +Executable = require "../src/beautifiers/executable" beautifiers = new Beautifiers() Beautifier = require "../src/beautifiers/beautifier" Languages = require('../src/languages/') @@ -124,7 +125,7 @@ describe "Atom-Beautify", -> pathOption: "Lang - Test Program Path" } # Force to be Windows - beautifier.isWindows = true + Executable.isWindows = () ->true terminal = 'CMD prompt' whichCmd = "where.exe" # Process @@ -132,7 +133,7 @@ describe "Atom-Beautify", -> expect(p).not.toBe(null) expect(p instanceof beautifier.Promise).toBe(true) cb = (v) -> - # console.log(v) + console.log("error", v, v.description) expect(v).not.toBe(null) expect(v instanceof Error).toBe(true) expect(v.code).toBe("CommandNotFound") @@ -167,7 +168,7 @@ describe "Atom-Beautify", -> pathOption: "Lang - Test Program Path" } # Force to be Mac/Linux (not Windows) - beautifier.isWindows = false + Executable.isWindows = () ->false terminal = "Terminal" whichCmd = "which" # Process diff --git a/spec/beautifier-php-cs-fixer-spec.coffee b/spec/beautifier-php-cs-fixer-spec.coffee index 1e49e70..391bb15 100644 --- a/spec/beautifier-php-cs-fixer-spec.coffee +++ b/spec/beautifier-php-cs-fixer-spec.coffee @@ -1,5 +1,6 @@ PHPCSFixer = require "../src/beautifiers/php-cs-fixer" Beautifier = require "../src/beautifiers/beautifier" +Executable = require "../src/beautifiers/executable" path = require 'path' # Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. @@ -30,10 +31,15 @@ describe "PHP-CS-Fixer Beautifier", -> describe "Beautifier::beautify", -> beautifier = null + execSpawn = null beforeEach -> beautifier = new PHPCSFixer() # console.log('new beautifier') + execSpawn = Executable.prototype.spawn + + afterEach -> + Executable.prototype.spawn = execSpawn OSSpecificSpecs = -> text = "" @@ -49,13 +55,14 @@ describe "PHP-CS-Fixer Beautifier", -> levels: "" } # Mock spawn - beautifier.spawn = (exe, args, options) -> + # beautifier.spawn + Executable.prototype.spawn = (exe, args, options) -> # console.log('spawn', exe, args, options) er = new Error('ENOENT') er.code = 'ENOENT' return beautifier.Promise.reject(er) # Beautify - p = beautifier.beautify(text, language, options) + p = beautifier.loadExecutables().then(() -> beautifier.beautify(text, language, options)) expect(p).not.toBe(null) expect(p instanceof beautifier.Promise).toBe(true) cb = (v) -> @@ -74,7 +81,7 @@ describe "PHP-CS-Fixer Beautifier", -> expect(beautifier).not.toBe(null) expect(beautifier instanceof Beautifier).toBe(true) - if not beautifier.isWindows and failingProgram is "php" + if not Executable.isWindows and failingProgram is "php" # Only applicable on Windows return @@ -104,8 +111,9 @@ describe "PHP-CS-Fixer Beautifier", -> # console.log('fake exe path', exe) beautifier.Promise.resolve("/#{exe}") - oldSpawn = beautifier.spawn.bind(beautifier) - beautifier.spawn = (exe, args, options) -> + # oldSpawn = beautifier.spawn.bind(beautifier) + # beautifier.spawn + Executable.prototype.spawn = (exe, args, options) -> # console.log('spawn', exe, args, options) if exe is failingProgram er = new Error('ENOENT') @@ -117,21 +125,21 @@ describe "PHP-CS-Fixer Beautifier", -> stdout: 'stdout', stderr: '' }) - p = beautifier.beautify(text, language, options) + p = beautifier.loadExecutables().then(() -> beautifier.beautify(text, language, options)) expect(p).not.toBe(null) expect(p instanceof beautifier.Promise).toBe(true) p.then(cb, cb) return p - # failWhichProgram('php') - failWhichProgram('php-cs-fixer') + failWhichProgram('PHP') + # failWhichProgram('php-cs-fixer') unless isWindows describe "Mac/Linux", -> beforeEach -> # console.log('mac/linx') - beautifier.isWindows = false + Executable.isWindows = () -> false do OSSpecificSpecs @@ -139,6 +147,6 @@ describe "PHP-CS-Fixer Beautifier", -> beforeEach -> # console.log('windows') - beautifier.isWindows = true + Executable.isWindows = () -> true do OSSpecificSpecs diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 5d326a3..3f2549d 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -4,8 +4,9 @@ fs = require('fs') temp = require('temp').track() readFile = Promise.promisify(fs.readFile) which = require('which') -spawn = require('child_process').spawn path = require('path') +shellEnv = require('shell-env') +Executable = require('./executable') module.exports = class Beautifier @@ -31,10 +32,42 @@ module.exports = class Beautifier ### options: {} + executables: [] + ### Is the beautifier a command-line interface beautifier? ### - isPreInstalled: true + isPreInstalled: () -> + @executables.length is 0 + + _exe: {} + loadExecutables: () -> + if Object.keys(@_exe).length is @executables.length + Promise.resolve(@_exe) + else + Promise.resolve(executables = @executables.map((e) -> new Executable(e))) + .then((executables) -> Promise.all(executables.map((e) -> e.init()))) + .then((es) => + exe = {} + missingInstalls = [] + es.forEach((e) -> + exe[e.cmd] = e + if not e.isInstalled + missingInstalls.push(e) + ) + @_exe = exe + @debug("exe", exe) + if missingInstalls.length is 0 + return @_exe + else + throw new Error("Missing required executables: #{missingInstalls.map((e) -> e.cmd).join(' and ')}") + ) + exe: (cmd) -> + console.log('exe', cmd, @_exe) + e = @_exe[cmd] + if !e? + throw new Error("Missing executable \"#{cmd}\". Please report this bug to https://github.com/Glavin001/atom-beautify/issues") + e ### Supported languages by this Beautifier @@ -102,7 +135,7 @@ module.exports = class Beautifier startDir.pop() return null -# Retrieves the default line ending based upon the Atom configuration + # Retrieves the default line ending based upon the Atom configuration # `line-ending-selector.defaultLineEnding`. If the Atom configuration # indicates "OS Default", the `process.platform` is queried, returning # CRLF for Windows systems and LF for all other systems. @@ -124,64 +157,6 @@ module.exports = class Beautifier else return lf - ### - If platform is Windows - ### - isWindows: do -> - return new RegExp('^win').test(process.platform) - - ### - Get Shell Environment variables - - Special thank you to @ioquatix - See https://github.com/ioquatix/script-runner/blob/v1.5.0/lib/script-runner.coffee#L45-L63 - ### - _envCache: null - _envCacheDate: null - _envCacheExpiry: 10000 # 10 seconds - getShellEnvironment: -> - return new Promise((resolve, reject) => - # Check Cache - if @_envCache? and @_envCacheDate? - # Check if Cache is old - if (new Date() - @_envCacheDate) < @_envCacheExpiry - # Still fresh - return resolve(@_envCache) - - # Check if Windows - if @isWindows - # Windows - # Use default - resolve(process.env) - else - # Mac & Linux - # I tried using ChildProcess.execFile but there is no way to set detached and - # this causes the child shell to lock up. - # This command runs an interactive login shell and - # executes the export command to get a list of environment variables. - # We then use these to run the script: - child = spawn process.env.SHELL, ['-ilc', 'env'], - # This is essential for interactive shells, otherwise it never finishes: - detached: true, - # We don't care about stdin, stderr can go out the usual way: - stdio: ['ignore', 'pipe', process.stderr] - # We buffer stdout: - buffer = '' - child.stdout.on 'data', (data) -> buffer += data - # When the process finishes, extract the environment variables and pass them to the callback: - child.on 'close', (code, signal) => - if code isnt 0 - return reject(new Error("Could not get Shell Environment. Exit code: "+code+", Signal: "+signal)) - environment = {} - for definition in buffer.split('\n') - [key, value] = definition.split('=', 2) - environment[key] = value if key != '' - # Cache Environment - @_envCache = environment - @_envCacheDate = new Date() - resolve(environment) - ) - ### Like the unix which utility. @@ -191,182 +166,19 @@ module.exports = class Beautifier See https://github.com/isaacs/node-which ### which: (exe, options = {}) -> - # Get PATH and other environment variables - @getShellEnvironment() - .then((env) => - new Promise((resolve, reject) => - options.path ?= env.PATH - if @isWindows - # Environment variables are case-insensitive in windows - # Check env for a case-insensitive 'path' variable - if !options.path - for i of env - if i.toLowerCase() is "path" - options.path = env[i] - break - - # Trick node-which into including files - # with no extension as executables. - # Put empty extension last to allow for other real extensions first - options.pathExt ?= "#{process.env.PATHEXT ? '.EXE'};" - which(exe, options, (err, path) -> - resolve(exe) if err - resolve(path) - ) - ) - ) - - ### - Add help to error.description - - Note: error.description is not officially used in JavaScript, - however it is used internally for Atom Beautify when displaying errors. - ### - commandNotFoundError: (exe, help) -> - # Create new improved error - # notify user that it may not be - # installed or in path - message = "Could not find '#{exe}'. \ - The program may not be installed." - er = new Error(message) - er.code = 'CommandNotFound' - er.errno = er.code - er.syscall = 'beautifier::run' - er.file = exe - if help? - if typeof help is "object" - # Basic notice - helpStr = "See #{help.link} for program \ - installation instructions.\n" - # Help to configure Atom Beautify for program's path - helpStr += "You can configure Atom Beautify \ - with the absolute path \ - to '#{help.program or exe}' by setting \ - '#{help.pathOption}' in \ - the Atom Beautify package settings.\n" if help.pathOption - # Optional, additional help - helpStr += help.additional if help.additional - # Common Help - issueSearchLink = - "https://github.com/Glavin001/atom-beautify/\ - search?q=#{exe}&type=Issues" - docsLink = "https://github.com/Glavin001/\ - atom-beautify/tree/master/docs" - helpStr += "Your program is properly installed if running \ - '#{if @isWindows then 'where.exe' \ - else 'which'} #{exe}' \ - in your #{if @isWindows then 'CMD prompt' \ - else 'Terminal'} \ - returns an absolute path to the executable. \ - If this does not work then you have not \ - installed the program correctly and so \ - Atom Beautify will not find the program. \ - Atom Beautify requires that the program be \ - found in your PATH environment variable. \n\ - Note that this is not an Atom Beautify issue \ - if beautification does not work and the above \ - command also does not work: this is expected \ - behaviour, since you have not properly installed \ - your program. Please properly setup the program \ - and search through existing Atom Beautify issues \ - before creating a new issue. \ - See #{issueSearchLink} for related Issues and \ - #{docsLink} for documentation. \ - If you are still unable to resolve this issue on \ - your own then please create a new issue and \ - ask for help.\n" - er.description = helpStr - else #if typeof help is "string" - er.description = help - return er + Executable.which(exe, options) ### Run command-line interface command ### run: (executable, args, {cwd, ignoreReturnCode, help, onStdin} = {}) -> - # Flatten args first - args = _.flatten(args) - - # Resolve executable and all args - Promise.all([executable, Promise.all(args)]) - .then(([exeName, args]) => - @debug('exeName, args:', exeName, args) - - # Get PATH and other environment variables - Promise.all([exeName, args, @getShellEnvironment(), @which(exeName)]) - ) - .then(([exeName, args, env, exePath]) => - @debug('exePath, env:', exePath, env) - @debug('args', args) - - exe = exePath ? exeName - options = { - cwd: cwd - env: env - } - - @spawn(exe, args, options, onStdin) - .then(({returnCode, stdout, stderr}) => - @verbose('spawn result', returnCode, stdout, stderr) - - # If return code is not 0 then error occured - if not ignoreReturnCode and returnCode isnt 0 - # operable program or batch file - windowsProgramNotFoundMsg = "is not recognized as an internal or external command" - - @verbose(stderr, windowsProgramNotFoundMsg) - - if @isWindows and returnCode is 1 and stderr.indexOf(windowsProgramNotFoundMsg) isnt -1 - throw @commandNotFoundError(exeName, help) - else - throw new Error(stderr) - else - stdout - ) - .catch((err) => - @debug('error', err) - - # Check if error is ENOENT (command could not be found) - if err.code is 'ENOENT' or err.errno is 'ENOENT' - throw @commandNotFoundError(exeName, help) - else - # continue as normal error - throw err - ) - ) - - ### - Spawn - ### - spawn: (exe, args, options, onStdin) -> - # Remove undefined/null values - args = _.without(args, undefined) - args = _.without(args, null) - - return new Promise((resolve, reject) => - @debug('spawn', exe, args) - - cmd = spawn(exe, args, options) - stdout = "" - stderr = "" - - cmd.stdout.on('data', (data) -> - stdout += data - ) - cmd.stderr.on('data', (data) -> - stderr += data - ) - cmd.on('close', (returnCode) => - @debug('spawn done', returnCode, stderr, stdout) - resolve({returnCode, stdout, stderr}) - ) - cmd.on('error', (err) => - @debug('error', err) - reject(err) - ) - - onStdin cmd.stdin if onStdin - ) + exe = new Executable({ + name: @name + homepage: @link + installation: @link + cmd: executable + }) + exe.run(args, {cwd, ignoreReturnCode, help, onStdin}) ### Logger instance diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee new file mode 100644 index 0000000..ae8ef9b --- /dev/null +++ b/src/beautifiers/executable.coffee @@ -0,0 +1,309 @@ +Promise = require('bluebird') +_ = require('lodash') +which = require('which') +spawn = require('child_process').spawn +path = require('path') +semver = require('semver') +shellEnv = require('shell-env') + +module.exports = class Executable + + name = null + cmd = null + homepage = null + installation = null + versionArgs = ['--version'] + versionParse = (text) -> semver.clean(text) + versionsSupported: '>= 0.0.0' + + constructor: (options) -> + @name = options.name + @cmd = options.cmd + @homepage = options.homepage + @installation = options.installation + if options.version? + versionOptions = options.version + @versionArgs = versionOptions.args + @versionParse = versionOptions.parse + @versionsSupported = versionOptions.supported + @setupLogger() + + init: () -> + Promise.all([ + @loadVersion() + ]) + .then(() => @) + + ### + Logger instance + ### + logger: null + ### + Initialize and configure Logger + ### + setupLogger: -> + @logger = require('../logger')("#{@name} Executable") + for key, method of @logger + @[key] = method + @verbose("#{@name} executable logger has been initialized.") + + isInstalled = null + version = null + loadVersion: (force = false) -> + @verbose("loadVersion", @version, force) + if force or !@version? + @verbose("Loading version without cache") + @runVersion() + .then((text) => @versionParse(text)) + .then((version) -> + valid = Boolean(semver.valid(version)) + if not valid + throw new Error("Version is not valid: "+version) + version + ) + .then((version) => + @isInstalled = true + @version = version + ) + .then((version) => + @verbose("#{@cmd} version: #{version}") + version + ) + .catch((error) => + @isInstalled = false + @error(error) + Promise.reject(@commandNotFoundError()) + ) + else + @verbose("Loading cached version") + Promise.resolve(@version) + + runVersion: () -> + @run(@versionArgs) + + isSupported: () -> + @isVersion(@versionsSupported) + + isVersion: (range) -> + semver.satisfies(@version, range) + + ### + Run command-line interface command + ### + run: (args, options = {}) -> + @debug("Run: ", args, options) + exeName = @cmd + { cwd, ignoreReturnCode, help, onStdin } = options + # Flatten args first + args = _.flatten(args) + + # Resolve executable and all args + Promise.all([@shellEnv(), Promise.all(args)]) + .then(([env, args]) => + @debug('exeName, args:', exeName, args) + + # Get PATH and other environment variables + Promise.all([exeName, args, env, @which(exeName)]) + ) + .then(([exeName, args, env, exePath]) => + @debug('exePath:', exePath) + @debug('env:', env) + @debug('args', args) + + exe = exePath ? exeName + spawnOptions = { + cwd: cwd + env: env + } + + @spawn(exe, args, spawnOptions, onStdin) + .then(({returnCode, stdout, stderr}) => + @verbose('spawn result', returnCode, stdout, stderr) + + # If return code is not 0 then error occured + if not ignoreReturnCode and returnCode isnt 0 + # operable program or batch file + windowsProgramNotFoundMsg = "is not recognized as an internal or external command" + + @verbose(stderr, windowsProgramNotFoundMsg) + + if @isWindows() and returnCode is 1 and stderr.indexOf(windowsProgramNotFoundMsg) isnt -1 + throw @commandNotFoundError(exeName, help) + else + throw new Error(stderr) + else + stdout + ) + .catch((err) => + @debug('error', err) + + # Check if error is ENOENT (command could not be found) + if err.code is 'ENOENT' or err.errno is 'ENOENT' + throw @commandNotFoundError(exeName, help) + else + # continue as normal error + throw err + ) + ) + + ### + Spawn + ### + spawn: (exe, args, options, onStdin) -> + # Remove undefined/null values + args = _.without(args, undefined) + args = _.without(args, null) + + return new Promise((resolve, reject) => + @debug('spawn', exe, args) + + cmd = spawn(exe, args, options) + stdout = "" + stderr = "" + + cmd.stdout.on('data', (data) -> + stdout += data + ) + cmd.stderr.on('data', (data) -> + stderr += data + ) + cmd.on('close', (returnCode) => + @debug('spawn done', returnCode, stderr, stdout) + resolve({returnCode, stdout, stderr}) + ) + cmd.on('error', (err) => + @debug('error', err) + reject(err) + ) + + onStdin cmd.stdin if onStdin + ) + + + ### + Add help to error.description + + Note: error.description is not officially used in JavaScript, + however it is used internally for Atom Beautify when displaying errors. + ### + commandNotFoundError: (exe, help) -> + exe ?= @name or @cmd + # help ?= { + # program: @cmd + # link: @installation or @homepage + # } + # Create new improved error + # notify user that it may not be + # installed or in path + message = "Could not find '#{exe}'. \ + The program may not be installed." + er = new Error(message) + er.code = 'CommandNotFound' + er.errno = er.code + er.syscall = 'beautifier::run' + er.file = exe + if help? + if typeof help is "object" + # Basic notice + helpStr = "See #{help.link} for program \ + installation instructions.\n" + # Help to configure Atom Beautify for program's path + helpStr += "You can configure Atom Beautify \ + with the absolute path \ + to '#{help.program or exe}' by setting \ + '#{help.pathOption}' in \ + the Atom Beautify package settings.\n" if help.pathOption + # Optional, additional help + helpStr += help.additional if help.additional + # Common Help + issueSearchLink = + "https://github.com/Glavin001/atom-beautify/\ + search?q=#{exe}&type=Issues" + docsLink = "https://github.com/Glavin001/\ + atom-beautify/tree/master/docs" + helpStr += "Your program is properly installed if running \ + '#{if @isWindows() then 'where.exe' \ + else 'which'} #{exe}' \ + in your #{if @isWindows() then 'CMD prompt' \ + else 'Terminal'} \ + returns an absolute path to the executable. \ + If this does not work then you have not \ + installed the program correctly and so \ + Atom Beautify will not find the program. \ + Atom Beautify requires that the program be \ + found in your PATH environment variable. \n\ + Note that this is not an Atom Beautify issue \ + if beautification does not work and the above \ + command also does not work: this is expected \ + behaviour, since you have not properly installed \ + your program. Please properly setup the program \ + and search through existing Atom Beautify issues \ + before creating a new issue. \ + See #{issueSearchLink} for related Issues and \ + #{docsLink} for documentation. \ + If you are still unable to resolve this issue on \ + your own then please create a new issue and \ + ask for help.\n" + er.description = helpStr + else #if typeof help is "string" + er.description = help + return er + + + @_envCache = null + shellEnv: () -> + @constructor.shellEnv() + @shellEnv: () -> + if @_envCache + return Promise.resolve(@_envCache) + else + shellEnv() + .then((env) => + @_envCache = env + ) + + ### + Like the unix which utility. + + Finds the first instance of a specified executable in the PATH environment variable. + Does not cache the results, + so hash -r is not needed when the PATH changes. + See https://github.com/isaacs/node-which + ### + which: (exe, options) -> + @.constructor.which(exe, options) + @_whichCache = {} + @which: (exe, options = {}) -> + if @_whichCache[exe] + return Promise.resolve(@_whichCache[exe]) + # Get PATH and other environment variables + @shellEnv() + .then((env) => + new Promise((resolve, reject) => + options.path ?= env.PATH + if @isWindows() + # Environment variables are case-insensitive in windows + # Check env for a case-insensitive 'path' variable + if !options.path + for i of env + if i.toLowerCase() is "path" + options.path = env[i] + break + + # Trick node-which into including files + # with no extension as executables. + # Put empty extension last to allow for other real extensions first + options.pathExt ?= "#{process.env.PATHEXT ? '.EXE'};" + which(exe, options, (err, path) => + return resolve(exe) if err + @_whichCache[exe] = path + resolve(path) + ) + ) + ) + + ### + If platform is Windows + ### + isWindows: () -> @constructor.isWindows() + @isWindows: () -> new RegExp('^win').test(process.platform) diff --git a/src/beautifiers/gherkin.coffee b/src/beautifiers/gherkin.coffee index d17c897..2744818 100644 --- a/src/beautifiers/gherkin.coffee +++ b/src/beautifiers/gherkin.coffee @@ -3,8 +3,6 @@ "use strict" Beautifier = require('./beautifier') -Lexer = require('gherkin').Lexer('en') -logger = require('../logger')(__filename) module.exports = class Gherkin extends Beautifier name: "Gherkin formatter" @@ -15,6 +13,8 @@ module.exports = class Gherkin extends Beautifier } beautify: (text, language, options) -> + Lexer = require('gherkin').Lexer('en') + logger = @logger return new @Promise((resolve, reject) -> recorder = { lines: [] diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index bd22caf..6f212ab 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -345,36 +345,40 @@ module.exports = class Beautifiers extends EventEmitter filePath: filePath startTime = new Date() - beautifier.beautify(text, language.name, options, context) - .then((result) => - resolve(result) - # Track Timing - @trackTiming({ - utc: "Beautify" # Category - utv: language?.name # Variable - utt: (new Date() - startTime) # Value - utl: version # Label - }) - # Track Empty beautification results - if not result + beautifier.loadExecutables() + .then((executables) -> + logger.verbose('executables', executables) + beautifier.beautify(text, language.name, options, context) + ) + .then((result) => + resolve(result) + # Track Timing + @trackTiming({ + utc: "Beautify" # Category + utv: language?.name # Variable + utt: (new Date() - startTime) # Value + utl: version # Label + }) + # Track Empty beautification results + if not result + @trackEvent({ + ec: version, # Category + ea: "Beautify:Empty" # Action + el: language?.name # Label + }) + ) + .catch((error) => + reject(error) + # Track Errors @trackEvent({ ec: version, # Category - ea: "Beautify:Empty" # Action + ea: "Beautify:Error" # Action el: language?.name # Label }) - ) - .catch((error) => - reject(error) - # Track Errors - @trackEvent({ - ec: version, # Category - ea: "Beautify:Error" # Action - el: language?.name # Label - }) - ) - .finally(=> - @emit "beautify::end" - ) + ) + .finally(=> + @emit "beautify::end" + ) # Check if Analytics is enabled @trackEvent({ diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index db46818..d2129df 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -10,7 +10,30 @@ module.exports = class PHPCSFixer extends Beautifier name: 'PHP-CS-Fixer' link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" - isPreInstalled: false + executables: [ + { + name: "PHP" + cmd: "php" + homepage: "http://php.net/" + installation: "http://php.net/manual/en/install.php" + version: { + args: ['--version'] + parse: (text) -> text.match(/PHP (.*) \(cli\)/)[1] + supported: '>= 0.0.0' + } + } + { + name: "PHP-CS-Fixer" + cmd: "php-cs-fixer" + homepage: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" + installation: "https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation" + version: { + args: ['--version'] + parse: (text) -> text.match(/version (.*) by/)[1] + ".0" + supported: '>= 0.0.0' + } + } + ] options: PHP: @@ -24,7 +47,8 @@ module.exports = class PHPCSFixer extends Beautifier beautify: (text, language, options, context) -> @debug('php-cs-fixer', options) - version = options.cs_fixer_version + php = @exe('php') + phpCsFixer = @exe('php-cs-fixer') configFiles = ['.php_cs', '.php_cs.dist'] # Find a config file in the working directory if a custom one was not provided @@ -42,7 +66,7 @@ module.exports = class PHPCSFixer extends Beautifier "--allow-risky=#{options.allow_risky}" if options.allow_risky "--using-cache=no" ] - if version is 1 + if phpCsFixer.isVersion('1.x') phpCsFixerOptions = [ "fix" "--level=#{options.level}" if options.level @@ -60,7 +84,9 @@ module.exports = class PHPCSFixer extends Beautifier @Promise.all([ @which(options.cs_fixer_path) if options.cs_fixer_path @which('php-cs-fixer') - ]).then((paths) => + tempFile = @tempFile("temp", text, '.php') + ]).then(([customPath, phpCsFixerPath]) => + paths = [customPath, phpCsFixerPath] @debug('php-cs-fixer paths', paths) _ = require 'lodash' # Get first valid, absolute path @@ -71,10 +97,8 @@ module.exports = class PHPCSFixer extends Beautifier # Check if PHP-CS-Fixer path was found if phpCSFixerPath? # Found PHP-CS-Fixer path - tempFile = @tempFile("temp", text) - if @isWindows - @run("php", [phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions) + php([phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions) .then(=> @readFile(tempFile) ) diff --git a/src/beautifiers/phpcbf.coffee b/src/beautifiers/phpcbf.coffee index ad347b8..1cf2204 100644 --- a/src/beautifiers/phpcbf.coffee +++ b/src/beautifiers/phpcbf.coffee @@ -8,6 +8,17 @@ Beautifier = require('./beautifier') module.exports = class PHPCBF extends Beautifier name: "PHPCBF" link: "http://php.net/manual/en/install.php" + executables: [ + { + name: "PHPCBF" + cmd: "phpcbf" + homepage: "https://github.com/squizlabs/PHP_CodeSniffer" + installation: "https://github.com/squizlabs/PHP_CodeSniffer#installation" + version: { + args: ['--version'] + } + } + ] isPreInstalled: false options: { From fcc32d3fab19432b28d3d69663729b326529d73f Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 29 May 2017 01:34:12 -0300 Subject: [PATCH 02/58] Generate config options (i.e. path) for Beautifier's Executables --- docs/index.coffee | 39 ++++---- docs/options.md | 132 ++++++++++++++++++++++++++++ package.json | 2 +- script/build-options.js | 53 ++++++++++- src/beautifiers/executable.coffee | 9 +- src/beautifiers/php-cs-fixer.coffee | 4 - src/config.coffee | 2 +- src/options.json | 66 ++++++++++++++ 8 files changed, 276 insertions(+), 31 deletions(-) diff --git a/docs/index.coffee b/docs/index.coffee index 61b4dbe..afbba77 100755 --- a/docs/index.coffee +++ b/docs/index.coffee @@ -82,25 +82,28 @@ Handlebars.registerHelper('example-config', (key, option, options) -> Handlebars.registerHelper('language-beautifiers-support', (languageOptions, options) -> - rows = _.map(languageOptions, (val, k) -> - name = val.title - defaultBeautifier = _.get(val, "properties.default_beautifier.default") - beautifiers = _.map(val.beautifiers, (b) -> - beautifier = beautifiersMap[b] - isDefault = b is defaultBeautifier - if beautifier.link - r = "[`#{b}`](#{beautifier.link})" - else - r = "`#{b}`" - if isDefault - r += " (Default)" - return r - ) - grammars = _.map(val.grammars, (b) -> "`#{b}`") - extensions = _.map(val.extensions, (b) -> "`.#{b}`") + rows = _.chain(languageOptions) + .filter((val, k) -> k isnt "executables") + .map((val, k) -> + name = val.title + defaultBeautifier = _.get(val, "properties.default_beautifier.default") + beautifiers = _.map(val.beautifiers, (b) -> + beautifier = beautifiersMap[b] + isDefault = b is defaultBeautifier + if beautifier.link + r = "[`#{b}`](#{beautifier.link})" + else + r = "`#{b}`" + if isDefault + r += " (Default)" + return r + ) + grammars = _.map(val.grammars, (b) -> "`#{b}`") + extensions = _.map(val.extensions, (b) -> "`.#{b}`") - return "| #{name} | #{grammars.join(', ')} |#{extensions.join(', ')} | #{beautifiers.join(', ')} |" - ) + return "| #{name} | #{grammars.join(', ')} |#{extensions.join(', ')} | #{beautifiers.join(', ')} |" + ) + .value() results = """ | Language | Grammars | File Extensions | Supported Beautifiers | | --- | --- | --- | ---- | diff --git a/docs/options.md b/docs/options.md index 84d5fba..2187766 100644 --- a/docs/options.md +++ b/docs/options.md @@ -131,6 +131,75 @@ Supported options for each language. --- +#### [Executables](#executables) + +**Description**: + +Configure executables used by beautifiers. + +##### [PHP](#php) + +**Namespace**: `` + +**Key**: `php` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP*" and change it to your desired configuration. + +##### [PHP-CS-Fixer](#php-cs-fixer) + +**Namespace**: `` + +**Key**: `php_cs_fixer` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP-CS-Fixer executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP-CS-Fixer*" and change it to your desired configuration. + +##### [PHPCBF](#phpcbf) + +**Namespace**: `` + +**Key**: `phpcbf` + +**Type**: `object` + +**Supported Beautifiers**: [`PHPCBF`](#phpcbf) + +**Description**: + +Options for PHPCBF executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHPCBF*" and change it to your desired configuration. + #### [Apex](#apex) **Supported Beautifiers**: [`Uncrustify`](#uncrustify) @@ -17618,6 +17687,48 @@ Allow risky rules to be applied (PHP-CS-Fixer 2 only) (Supported by PHP-CS-Fixer } ``` +##### [PHP](#php) + +**Namespace**: `` + +**Key**: `php` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP*" and change it to your desired configuration. + +##### [PHP-CS-Fixer](#php-cs-fixer) + +**Namespace**: `` + +**Key**: `php_cs_fixer` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP-CS-Fixer executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP-CS-Fixer*" and change it to your desired configuration. + ### PHPCBF @@ -17699,6 +17810,27 @@ Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS ru } ``` +##### [PHPCBF](#phpcbf) + +**Namespace**: `` + +**Key**: `phpcbf` + +**Type**: `object` + +**Supported Beautifiers**: [`PHPCBF`](#phpcbf) + +**Description**: + +Options for PHPCBF executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHPCBF*" and change it to your desired configuration. + ### Perltidy diff --git a/package.json b/package.json index 5234181..96a69e1 100644 --- a/package.json +++ b/package.json @@ -409,4 +409,4 @@ "lint": "coffeelint src/ spec/", "code-docs": "codo && open docs/code/index.html" } -} +} \ No newline at end of file diff --git a/script/build-options.js b/script/build-options.js index 4d1fabf..40b253b 100644 --- a/script/build-options.js +++ b/script/build-options.js @@ -172,6 +172,54 @@ buildOptionsForBeautifiers = function(beautifiers, allLanguages) { return flatOptions; }; +buildOptionsForExecutables = function(beautifiers) { + executables = _.chain(beautifiers) + .map((beautifier) => { + const executables = beautifier.executables || []; + executables.forEach((executable) => executable.beautifiers = [beautifier.name]); + return executables; + }) + .flatten() + .value(); + + const properties = {} + _.forEach(executables, (executable) => { + const { name, cmd, beautifiers } = executable; + const sanitizedCmd = cmd.split('-').join('_'); + const key = sanitizedCmd; + const option = { + key: key, + title: name, + type: "object", + collapsed: true, + description: `Options for ${name} executable.`, + beautifiers, + properties: { + path: { + key: "path", + title: "Executable Path", + type: "string", + default: "", + description: `Absolute path to the "${cmd}" executable.`, + } + } + } + properties[key] = option; + }); + + const options = { + executables: { + title: 'Executables', + type: 'object', + collapsed: true, + order: -1, + description: 'Configure executables used by beautifiers.', + properties + } + } + return options +}; + buildOptionsForBeautifiers = function(beautifiers, allLanguages) { var beautifier, beautifierName, defaultBeautifier, f, fallback, field, fields, fn, g, group, i, j, k, l, laOp, lang, langName, langOptions, languageName, languages, len, len1, len2, len3, len4, len5, m, n, name, name1, namespace, namespaceDest, namespaceSrc, o, op, optionDef, optionName, options, optionsDest, optionsSrc, p, q, ref, ref1, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, unsupportedOptions; langOptions = {}; @@ -374,10 +422,11 @@ beautifier = new Beautifiers(); console.log('Building options for beautifiers'); beautifierOptions = buildOptionsForBeautifiers(beautifier.beautifiers, beautifier.languages.languages); +executableOptions = buildOptionsForExecutables(beautifier.beautifiers) console.log('Done building options for beautifiers'); - -optionsStr = JSON.stringify(beautifierOptions, null, 2); +combinedOptions = Object.assign({}, beautifierOptions, executableOptions) +optionsStr = JSON.stringify(combinedOptions, null, 2); outputFilename = path.resolve(__dirname, '../src/options.json'); diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index ae8ef9b..cfce18d 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -23,16 +23,15 @@ module.exports = class Executable @installation = options.installation if options.version? versionOptions = options.version - @versionArgs = versionOptions.args - @versionParse = versionOptions.parse - @versionsSupported = versionOptions.supported + @versionArgs = versionOptions.args or @versionArgs + @versionParse = versionOptions.parse or @versionParse + @versionsSupported = versionOptions.supported or @versionsSupported @setupLogger() init: () -> Promise.all([ @loadVersion() - ]) - .then(() => @) + ]).then(() => @) ### Logger instance diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index d2129df..d013edd 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -17,9 +17,7 @@ module.exports = class PHPCSFixer extends Beautifier homepage: "http://php.net/" installation: "http://php.net/manual/en/install.php" version: { - args: ['--version'] parse: (text) -> text.match(/PHP (.*) \(cli\)/)[1] - supported: '>= 0.0.0' } } { @@ -28,9 +26,7 @@ module.exports = class PHPCSFixer extends Beautifier homepage: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" installation: "https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation" version: { - args: ['--version'] parse: (text) -> text.match(/version (.*) by/)[1] + ".0" - supported: '>= 0.0.0' } } ] diff --git a/src/config.coffee b/src/config.coffee index 2b00226..3ab01d3 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -3,7 +3,7 @@ module.exports = { title: 'General' type: 'object' collapsed: true - order: -1 + order: -2 description: 'General options for Atom Beautify' properties: _analyticsUserId : diff --git a/src/options.json b/src/options.json index d207c82..9e667a7 100644 --- a/src/options.json +++ b/src/options.json @@ -9122,5 +9122,71 @@ "description": "Automatically beautify YAML files on save" } } + }, + "executables": { + "title": "Executables", + "type": "object", + "collapsed": true, + "order": -1, + "description": "Configure executables used by beautifiers.", + "properties": { + "php": { + "key": "php", + "title": "PHP", + "type": "object", + "collapsed": true, + "description": "Options for PHP executable.", + "beautifiers": [ + "PHP-CS-Fixer" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"php\" executable." + } + } + }, + "php_cs_fixer": { + "key": "php_cs_fixer", + "title": "PHP-CS-Fixer", + "type": "object", + "collapsed": true, + "description": "Options for PHP-CS-Fixer executable.", + "beautifiers": [ + "PHP-CS-Fixer" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"php-cs-fixer\" executable." + } + } + }, + "phpcbf": { + "key": "phpcbf", + "title": "PHPCBF", + "type": "object", + "collapsed": true, + "description": "Options for PHPCBF executable.", + "beautifiers": [ + "PHPCBF" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"phpcbf\" executable." + } + } + } + } } } \ No newline at end of file From 8b8595ee9cdbdc786e1f0055201eccf652b12034 Mon Sep 17 00:00:00 2001 From: Jason Scragz Date: Mon, 29 May 2017 16:16:37 -0700 Subject: [PATCH 03/58] apply #1649 fix to other platforms besides win fixes #1684 fixes #1487 --- src/beautifiers/phpcbf.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/beautifiers/phpcbf.coffee b/src/beautifiers/phpcbf.coffee index ad347b8..f59179d 100644 --- a/src/beautifiers/phpcbf.coffee +++ b/src/beautifiers/phpcbf.coffee @@ -78,7 +78,7 @@ module.exports = class PHPCBF extends Beautifier @run("phpcbf", [ "--no-patch" unless options.phpcbf_version is 3 "--standard=#{options.standard}" if options.standard - tempFile = @tempFile("temp", text) + tempFile = @tempFile("temp", text, ".php") ], { ignoreReturnCode: true help: { From f05056b940368f05bcbc03ec418dc8f02f5a6bcb Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 01:21:01 -0300 Subject: [PATCH 04/58] Fix executables not parsing version with default config --- src/beautifiers/beautifier.coffee | 2 ++ src/beautifiers/executable.coffee | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 3f2549d..ef19935 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -42,12 +42,14 @@ module.exports = class Beautifier _exe: {} loadExecutables: () -> + @debug("Load executables") if Object.keys(@_exe).length is @executables.length Promise.resolve(@_exe) else Promise.resolve(executables = @executables.map((e) -> new Executable(e))) .then((executables) -> Promise.all(executables.map((e) -> e.init()))) .then((es) => + @debug("Executables loaded", es) exe = {} missingInstalls = [] es.forEach((e) -> diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index cfce18d..eac8fe6 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -8,12 +8,12 @@ shellEnv = require('shell-env') module.exports = class Executable - name = null - cmd = null - homepage = null - installation = null - versionArgs = ['--version'] - versionParse = (text) -> semver.clean(text) + name: null + cmd: null + homepage: null + installation: null + versionArgs: ['--version'] + versionParse: (text) -> semver.clean(text) versionsSupported: '>= 0.0.0' constructor: (options) -> @@ -23,15 +23,17 @@ module.exports = class Executable @installation = options.installation if options.version? versionOptions = options.version - @versionArgs = versionOptions.args or @versionArgs - @versionParse = versionOptions.parse or @versionParse - @versionsSupported = versionOptions.supported or @versionsSupported + @versionArgs = versionOptions.args if versionOptions.args + @versionParse = versionOptions.parse if versionOptions.parse + @versionsSupported = versionOptions.supported if versionOptions.supported @setupLogger() init: () -> Promise.all([ @loadVersion() - ]).then(() => @) + ]) + .then(() => @verbose("Done init of #{@name}")) + .then(() => @) ### Logger instance From dca093cd418dce9fc8a02a7dc485eab641813b7d Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:26:12 -0300 Subject: [PATCH 05/58] Add config support for Executables --- src/beautifiers/beautifier.coffee | 2 ++ src/beautifiers/executable.coffee | 42 ++++++++++++++++++++++++----- src/beautifiers/php-cs-fixer.coffee | 5 +++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index ef19935..9c7a043 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -168,12 +168,14 @@ module.exports = class Beautifier See https://github.com/isaacs/node-which ### which: (exe, options = {}) -> + # @deprecate("Beautifier.which function has been deprecated. Please use Executables.") Executable.which(exe, options) ### Run command-line interface command ### run: (executable, args, {cwd, ignoreReturnCode, help, onStdin} = {}) -> + # @deprecate("Beautifier.run function has been deprecated. Please use Executables.") exe = new Executable({ name: @name homepage: @link diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index eac8fe6..3f1e9cd 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -6,25 +6,36 @@ path = require('path') semver = require('semver') shellEnv = require('shell-env') +parentConfigKey = "atom-beautify.executables" + module.exports = class Executable name: null cmd: null + key: null homepage: null installation: null versionArgs: ['--version'] versionParse: (text) -> semver.clean(text) + versionRunOptions: {} versionsSupported: '>= 0.0.0' constructor: (options) -> + # Validation + if !options.cmd? + throw new Error("Command is required for an Executable.") + if !options.homepage? or !options.homepage? + throw new Error("Either a homepage or installation page is required for an Executable.") @name = options.name @cmd = options.cmd + @key = @cmd.split('-').join('_') @homepage = options.homepage @installation = options.installation if options.version? versionOptions = options.version @versionArgs = versionOptions.args if versionOptions.args @versionParse = versionOptions.parse if versionOptions.parse + @versionRunOptions = versionOptions.runOptions if versionOptions.runOptions @versionsSupported = versionOptions.supported if versionOptions.supported @setupLogger() @@ -80,7 +91,11 @@ module.exports = class Executable Promise.resolve(@version) runVersion: () -> - @run(@versionArgs) + @run(@versionArgs, @versionRunOptions) + .then((version) => + @verbose("Version: " + version) + version + ) isSupported: () -> @isVersion(@versionsSupported) @@ -88,15 +103,19 @@ module.exports = class Executable isVersion: (range) -> semver.satisfies(@version, range) + getConfig: () -> + atom?.config.get("#{parentConfigKey}.#{@key}") or {} + ### Run command-line interface command ### run: (args, options = {}) -> - @debug("Run: ", args, options) - exeName = @cmd - { cwd, ignoreReturnCode, help, onStdin } = options + @debug("Run: ", @cmd, args, options) + { cwd, ignoreReturnCode, help, onStdin, returnStderr } = options # Flatten args first args = _.flatten(args) + exeName = @cmd + config = @getConfig() # Resolve executable and all args Promise.all([@shellEnv(), Promise.all(args)]) @@ -104,7 +123,11 @@ module.exports = class Executable @debug('exeName, args:', exeName, args) # Get PATH and other environment variables - Promise.all([exeName, args, env, @which(exeName)]) + if config and config.path + exePath = config.path + else + exePath = @which(exeName) + Promise.all([exeName, args, env, exePath]) ) .then(([exeName, args, env, exePath]) => @debug('exePath:', exePath) @@ -119,7 +142,9 @@ module.exports = class Executable @spawn(exe, args, spawnOptions, onStdin) .then(({returnCode, stdout, stderr}) => - @verbose('spawn result', returnCode, stdout, stderr) + @verbose('spawn result, returnCode', returnCode) + @verbose('spawn result, stdout', stdout) + @verbose('spawn result, stderr', stderr) # If return code is not 0 then error occured if not ignoreReturnCode and returnCode isnt 0 @@ -133,7 +158,10 @@ module.exports = class Executable else throw new Error(stderr) else - stdout + if returnStderr + stderr + else + stdout ) .catch((err) => @debug('error', err) diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index d013edd..644ce60 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -77,6 +77,9 @@ module.exports = class PHPCSFixer extends Beautifier } # Find php-cs-fixer.phar script + if options.cs_fixer_path + @deprecate("The \"cs_fixer_path\" has been deprecated. Please change to using the config with path \"Executables - PHP - Path\" in Atom-Beautify package settings.") + @Promise.all([ @which(options.cs_fixer_path) if options.cs_fixer_path @which('php-cs-fixer') @@ -94,7 +97,7 @@ module.exports = class PHPCSFixer extends Beautifier if phpCSFixerPath? # Found PHP-CS-Fixer path if @isWindows - php([phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions) + php.run([phpCSFixerPath, phpCsFixerOptions, tempFile], runOptions) .then(=> @readFile(tempFile) ) From 01df888aae57d306202522a2e03eb6ebcb871ba8 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:30:56 -0300 Subject: [PATCH 06/58] Switch formatR to using Executables --- docs/options.md | 42 ++++++++++++++++++++++++++++ src/beautifiers/formatR/index.coffee | 23 +++++++++++++-- src/options.json | 19 +++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/docs/options.md b/docs/options.md index 2187766..450f95d 100644 --- a/docs/options.md +++ b/docs/options.md @@ -137,6 +137,27 @@ Supported options for each language. Configure executables used by beautifiers. +##### [Rscript](#rscript) + +**Namespace**: `` + +**Key**: `Rscript` + +**Type**: `object` + +**Supported Beautifiers**: [`formatR`](#formatr) + +**Description**: + +Options for Rscript executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Rscript*" and change it to your desired configuration. + ##### [PHP](#php) **Namespace**: `` @@ -20123,6 +20144,27 @@ Indentation size/length (Supported by formatR) } ``` +##### [Rscript](#rscript) + +**Namespace**: `` + +**Key**: `Rscript` + +**Type**: `object` + +**Supported Beautifiers**: [`formatR`](#formatr) + +**Description**: + +Options for Rscript executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Rscript*" and change it to your desired configuration. + ### pybeautifier diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index bf0e8f5..fd463bd 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -9,18 +9,35 @@ Beautifier = require('../beautifier') module.exports = class R extends Beautifier name: "formatR" link: "https://github.com/yihui/formatR" - isPreInstalled: false + executables: [ + { + name: "Rscript" + cmd: "Rscript" + homepage: "https://github.com/yihui/formatR" + installation: "https://github.com/yihui/formatR" + version: { + parse: (text) -> + r = /version (\d\.\d\.\d) / + console.log("parse version", text, r, text.match(r)) + text.match(r)[1] + runOptions: { + returnStderr: true + } + } + } + ] options: { R: true } beautify: (text, language, options) -> + rScript = @exe("Rscript") r_beautifier = path.resolve(__dirname, "formatR.r") - @run("Rscript", [ + rScript.run([ r_beautifier, options.indent_size, @tempFile("input", text), '>', @tempFile("input", text) - ]) + ]) diff --git a/src/options.json b/src/options.json index 9e667a7..6675736 100644 --- a/src/options.json +++ b/src/options.json @@ -9186,6 +9186,25 @@ "description": "Absolute path to the \"phpcbf\" executable." } } + }, + "Rscript": { + "key": "Rscript", + "title": "Rscript", + "type": "object", + "collapsed": true, + "description": "Options for Rscript executable.", + "beautifiers": [ + "formatR" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"Rscript\" executable." + } + } } } } From 5648aa34a120552d027fe7562fc21e2e1a14aedd Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:31:18 -0300 Subject: [PATCH 07/58] Remove homepage nad installation link from Executables required properties --- src/beautifiers/executable.coffee | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 3f1e9cd..587a1da 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -23,9 +23,7 @@ module.exports = class Executable constructor: (options) -> # Validation if !options.cmd? - throw new Error("Command is required for an Executable.") - if !options.homepage? or !options.homepage? - throw new Error("Either a homepage or installation page is required for an Executable.") + throw new Error("The command (i.e. cmd property) is required for an Executable.") @name = options.name @cmd = options.cmd @key = @cmd.split('-').join('_') From bee7b2573a5cdf4fdf2c93f76533d00a13336f42 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:47:39 -0300 Subject: [PATCH 08/58] Switch Fortran beautifier (using Emacs) to using Executables, other minor improvements --- docs/options.md | 46 ++++++++++++++++++- script/build-options.js | 3 +- src/beautifiers/executable.coffee | 2 +- src/beautifiers/formatR/index.coffee | 5 +- .../fortran-beautifier/index.coffee | 16 ++++++- src/beautifiers/php-cs-fixer.coffee | 2 +- src/options.json | 23 +++++++++- 7 files changed, 83 insertions(+), 14 deletions(-) diff --git a/docs/options.md b/docs/options.md index 450f95d..aad2819 100644 --- a/docs/options.md +++ b/docs/options.md @@ -158,6 +158,27 @@ Options for Rscript executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Rscript*" and change it to your desired configuration. +##### [Emacs](#emacs) + +**Namespace**: `` + +**Key**: `emacs` + +**Type**: `object` + +**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier) + +**Description**: + +Options for Emacs executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Emacs*" and change it to your desired configuration. + ##### [PHP](#php) **Namespace**: `` @@ -183,7 +204,7 @@ Options for PHP executable. **Namespace**: `` -**Key**: `php_cs_fixer` +**Key**: `php-cs-fixer` **Type**: `object` @@ -15873,6 +15894,27 @@ Path to the emacs script (Supported by Fortran Beautifier) } ``` +##### [Emacs](#emacs) + +**Namespace**: `` + +**Key**: `emacs` + +**Type**: `object` + +**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier) + +**Description**: + +Options for Emacs executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Emacs*" and change it to your desired configuration. + ### Gherkin formatter @@ -17733,7 +17775,7 @@ Options for PHP executable. **Namespace**: `` -**Key**: `php_cs_fixer` +**Key**: `php-cs-fixer` **Type**: `object` diff --git a/script/build-options.js b/script/build-options.js index 40b253b..0bd8e6e 100644 --- a/script/build-options.js +++ b/script/build-options.js @@ -185,8 +185,7 @@ buildOptionsForExecutables = function(beautifiers) { const properties = {} _.forEach(executables, (executable) => { const { name, cmd, beautifiers } = executable; - const sanitizedCmd = cmd.split('-').join('_'); - const key = sanitizedCmd; + const key = cmd; const option = { key: key, title: name, diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 587a1da..15b9c27 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -26,7 +26,7 @@ module.exports = class Executable throw new Error("The command (i.e. cmd property) is required for an Executable.") @name = options.name @cmd = options.cmd - @key = @cmd.split('-').join('_') + @key = @cmd @homepage = options.homepage @installation = options.installation if options.version? diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index fd463bd..40e2d9f 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -16,10 +16,7 @@ module.exports = class R extends Beautifier homepage: "https://github.com/yihui/formatR" installation: "https://github.com/yihui/formatR" version: { - parse: (text) -> - r = /version (\d\.\d\.\d) / - console.log("parse version", text, r, text.match(r)) - text.match(r)[1] + parse: (text) -> text.match(/version (\d+\.\d+\.\d+) /)[1] runOptions: { returnStderr: true } diff --git a/src/beautifiers/fortran-beautifier/index.coffee b/src/beautifiers/fortran-beautifier/index.coffee index 8fcd759..00b7de5 100644 --- a/src/beautifiers/fortran-beautifier/index.coffee +++ b/src/beautifiers/fortran-beautifier/index.coffee @@ -9,7 +9,17 @@ path = require("path") module.exports = class FortranBeautifier extends Beautifier name: "Fortran Beautifier" link: "https://www.gnu.org/software/emacs/" - isPreInstalled: false + executables: [ + { + name: "Emacs" + cmd: "emacs" + homepage: "https://www.gnu.org/software/emacs/" + installation: "https://www.gnu.org/software/emacs/" + version: { + parse: (text) -> text.match(/Emacs (\d+\.\d+\.\d+)/)[1] + } + } + ] options: { Fortran: true @@ -17,6 +27,7 @@ module.exports = class FortranBeautifier extends Beautifier beautify: (text, language, options) -> @debug('fortran-beautifier', options) + emacs = @exe("emacs") emacs_path = options.emacs_path emacs_script_path = options.emacs_script_path @@ -36,12 +47,13 @@ module.exports = class FortranBeautifier extends Beautifier ] if emacs_path + @deprecate("The \"emacs_path\" has been deprecated. Please switch to using the config with path \"Executables - Emacs - Path\" in Atom-Beautify package settings now.") @run(emacs_path, args, {ignoreReturnCode: false}) .then(=> @readFile(tempFile) ) else - @run("emacs", args, {ignoreReturnCode: false}) + emacs.run(args, {ignoreReturnCode: false}) .then(=> @readFile(tempFile) ) diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index 644ce60..47539a5 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -78,7 +78,7 @@ module.exports = class PHPCSFixer extends Beautifier # Find php-cs-fixer.phar script if options.cs_fixer_path - @deprecate("The \"cs_fixer_path\" has been deprecated. Please change to using the config with path \"Executables - PHP - Path\" in Atom-Beautify package settings.") + @deprecate("The \"cs_fixer_path\" has been deprecated. Please switch to using the config with path \"Executables - PHP-CS-Fixer - Path\" in Atom-Beautify package settings now.") @Promise.all([ @which(options.cs_fixer_path) if options.cs_fixer_path diff --git a/src/options.json b/src/options.json index 6675736..eafcadc 100644 --- a/src/options.json +++ b/src/options.json @@ -9130,6 +9130,25 @@ "order": -1, "description": "Configure executables used by beautifiers.", "properties": { + "emacs": { + "key": "emacs", + "title": "Emacs", + "type": "object", + "collapsed": true, + "description": "Options for Emacs executable.", + "beautifiers": [ + "Fortran Beautifier" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"emacs\" executable." + } + } + }, "php": { "key": "php", "title": "PHP", @@ -9149,8 +9168,8 @@ } } }, - "php_cs_fixer": { - "key": "php_cs_fixer", + "php-cs-fixer": { + "key": "php-cs-fixer", "title": "PHP-CS-Fixer", "type": "object", "collapsed": true, From cefa7afa6bcd439c443028b3496fe9a627306c82 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:54:09 -0300 Subject: [PATCH 09/58] See #1569. Change Lua beautifier to be preinstalled --- README.md | 4 ++-- src/beautifiers/lua-beautifier/index.coffee | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bc65293..d644f98 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall | JS Beautify | :white_check_mark: | Nothing! | | JSCS Fixer | :white_check_mark: | Nothing! | | Latex Beautify | :x: | Go to https://github.com/cmhughes/latexindent.pl and follow the instructions. | -| Lua beautifier | :x: | Go to https://www.perl.org/ and follow the instructions. | +| Lua beautifier | :white_check_mark: | Nothing! | | Marko Beautifier | :white_check_mark: | Nothing! | | Nginx Beautify | :white_check_mark: | Nothing! | | ocp-indent | :x: | Go to https://www.typerex.org/ocp-indent.html and follow the instructions. | @@ -153,7 +153,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti | JSX | `JSX`, `JavaScript (JSX)`, `Babel ES6 JavaScript`, `JavaScript with JSX` |`.jsx`, `.js` | [`JS Beautify`](https://github.com/beautify-web/js-beautify), [`Pretty Diff`](https://github.com/prettydiff/prettydiff) (Default) | | LaTeX | `BibTeX`, `LaTeX`, `TeX` |`.bib`, `.tex`, `.sty`, `.cls`, `.dtx`, `.ins`, `.bbx`, `.cbx` | [`Latex Beautify`](https://github.com/cmhughes/latexindent.pl) (Default) | | LESS | `LESS` |`.less` | [`CSScomb`](https://github.com/csscomb/csscomb.js), [`Pretty Diff`](https://github.com/prettydiff/prettydiff) (Default) | -| Lua | `Lua` |`.lua` | [`Lua beautifier`](https://www.perl.org/) (Default) | +| Lua | `Lua` |`.lua` | [`Lua beautifier`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/lua-beautifier/beautifier.coffee) (Default) | | Markdown | `GitHub Markdown` |`.markdown`, `.md` | [`Remark`](https://github.com/wooorm/remark), [`Tidy Markdown`](https://github.com/slang800/tidy-markdown) (Default) | | Marko | `Marko` |`.marko` | [`Marko Beautifier`](https://github.com/marko-js/marko-prettyprint) (Default) | | Mustache | `HTML (Mustache)` |`.mustache` | [`JS Beautify`](https://github.com/beautify-web/js-beautify) (Default), [`Pretty Diff`](https://github.com/prettydiff/prettydiff) | diff --git a/src/beautifiers/lua-beautifier/index.coffee b/src/beautifiers/lua-beautifier/index.coffee index e9d9445..05ea2f1 100644 --- a/src/beautifiers/lua-beautifier/index.coffee +++ b/src/beautifiers/lua-beautifier/index.coffee @@ -8,8 +8,7 @@ format = require './beautifier' module.exports = class Lua extends Beautifier name: "Lua beautifier" - link: "https://www.perl.org/" - isPreInstalled: false + link: "https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/lua-beautifier/beautifier.coffee" options: { Lua: true From 9144df29a194ee2cb24a242818b77341a0051bbf Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:59:55 -0300 Subject: [PATCH 10/58] Switch Uncrustify to using Exectuables --- docs/options.md | 42 +++++++++++++++++++++++++ src/beautifiers/uncrustify/index.coffee | 17 +++++++--- src/options.json | 19 +++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/docs/options.md b/docs/options.md index aad2819..440358c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -242,6 +242,27 @@ Options for PHPCBF executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*PHPCBF*" and change it to your desired configuration. +##### [Uncrustify](#uncrustify) + +**Namespace**: `` + +**Key**: `uncrustify` + +**Type**: `object` + +**Supported Beautifiers**: [`Uncrustify`](#uncrustify) + +**Description**: + +Options for Uncrustify executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Uncrustify*" and change it to your desired configuration. + #### [Apex](#apex) **Supported Beautifiers**: [`Uncrustify`](#uncrustify) @@ -19072,6 +19093,27 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify) } ``` +##### [Uncrustify](#uncrustify) + +**Namespace**: `` + +**Key**: `uncrustify` + +**Type**: `object` + +**Supported Beautifiers**: [`Uncrustify`](#uncrustify) + +**Description**: + +Options for Uncrustify executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Uncrustify*" and change it to your desired configuration. + ### Vue Beautifier diff --git a/src/beautifiers/uncrustify/index.coffee b/src/beautifiers/uncrustify/index.coffee index 2ee1ae7..3d75ae6 100644 --- a/src/beautifiers/uncrustify/index.coffee +++ b/src/beautifiers/uncrustify/index.coffee @@ -11,7 +11,17 @@ _ = require('lodash') module.exports = class Uncrustify extends Beautifier name: "Uncrustify" link: "https://github.com/uncrustify/uncrustify" - isPreInstalled: false + executables: [ + { + name: "Uncrustify" + cmd: "uncrustify" + homepage: "http://uncrustify.sourceforge.net/" + installation: "https://github.com/uncrustify/uncrustify" + version: { + parse: (text) -> text.match(/uncrustify (\d+\.\d+)/)[1] + ".0" + } + } + ] options: { Apex: true @@ -27,6 +37,7 @@ module.exports = class Uncrustify extends Beautifier } beautify: (text, language, options) -> + uncrustify = @exe("uncrustify") # console.log('uncrustify.beautify', language, options) return new @Promise((resolve, reject) -> configPath = options.configPath @@ -50,8 +61,6 @@ module.exports = class Uncrustify extends Beautifier reject(new Error("No Uncrustify Config Path set! Please configure Uncrustify with Atom Beautify.")) ) .then((configPath) => - - # Select Uncrustify language lang = "C" # Default is C switch language @@ -76,7 +85,7 @@ module.exports = class Uncrustify extends Beautifier when "Arduino" lang = "CPP" - @run("uncrustify", [ + uncrustify.run([ "-c" configPath "-f" diff --git a/src/options.json b/src/options.json index eafcadc..d07cd40 100644 --- a/src/options.json +++ b/src/options.json @@ -9130,6 +9130,25 @@ "order": -1, "description": "Configure executables used by beautifiers.", "properties": { + "uncrustify": { + "key": "uncrustify", + "title": "Uncrustify", + "type": "object", + "collapsed": true, + "description": "Options for Uncrustify executable.", + "beautifiers": [ + "Uncrustify" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"uncrustify\" executable." + } + } + }, "emacs": { "key": "emacs", "title": "Emacs", From ddea1a6bb4e3bf54d8aa48ad9850aa8c8838af8e Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 03:15:56 -0300 Subject: [PATCH 11/58] Improve generated documentation for Executables --- docs/index.coffee | 4 + docs/options.md | 176 +++------------------------------------- script/build-options.js | 2 +- src/options.json | 18 ---- 4 files changed, 18 insertions(+), 182 deletions(-) diff --git a/docs/index.coffee b/docs/index.coffee index afbba77..b3218f9 100755 --- a/docs/index.coffee +++ b/docs/index.coffee @@ -1,3 +1,4 @@ + #!/usr/bin/env coffee # Dependencies @@ -11,7 +12,10 @@ pkg = require('../package.json') console.log('Generating options...') beautifier = new Beautifiers() languageOptions = beautifier.options +executableOptions = languageOptions.executables +delete languageOptions.executables packageOptions = require('../src/config.coffee') +packageOptions.executables = executableOptions # Build options by Beautifier beautifiersMap = _.keyBy(beautifier.beautifiers, 'name') languagesMap = _.keyBy(beautifier.languages.languages, 'name') diff --git a/docs/options.md b/docs/options.md index 440358c..a760c8c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -124,13 +124,6 @@ Show loading view when beautifying 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Show Loading View*" and change it to your desired configuration. - -## Language Options - -Supported options for each language. - ---- - #### [Executables](#executables) **Description**: @@ -139,14 +132,10 @@ Configure executables used by beautifiers. ##### [Rscript](#rscript) -**Namespace**: `` - -**Key**: `Rscript` +**Important**: This option is only configurable from within Atom Beautify's setting panel. **Type**: `object` -**Supported Beautifiers**: [`formatR`](#formatr) - **Description**: Options for Rscript executable. @@ -160,14 +149,10 @@ Options for Rscript executable. ##### [Emacs](#emacs) -**Namespace**: `` - -**Key**: `emacs` +**Important**: This option is only configurable from within Atom Beautify's setting panel. **Type**: `object` -**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier) - **Description**: Options for Emacs executable. @@ -181,14 +166,10 @@ Options for Emacs executable. ##### [PHP](#php) -**Namespace**: `` - -**Key**: `php` +**Important**: This option is only configurable from within Atom Beautify's setting panel. **Type**: `object` -**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) - **Description**: Options for PHP executable. @@ -202,14 +183,10 @@ Options for PHP executable. ##### [PHP-CS-Fixer](#php-cs-fixer) -**Namespace**: `` - -**Key**: `php-cs-fixer` +**Important**: This option is only configurable from within Atom Beautify's setting panel. **Type**: `object` -**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) - **Description**: Options for PHP-CS-Fixer executable. @@ -223,14 +200,10 @@ Options for PHP-CS-Fixer executable. ##### [PHPCBF](#phpcbf) -**Namespace**: `` - -**Key**: `phpcbf` +**Important**: This option is only configurable from within Atom Beautify's setting panel. **Type**: `object` -**Supported Beautifiers**: [`PHPCBF`](#phpcbf) - **Description**: Options for PHPCBF executable. @@ -244,14 +217,10 @@ Options for PHPCBF executable. ##### [Uncrustify](#uncrustify) -**Namespace**: `` - -**Key**: `uncrustify` +**Important**: This option is only configurable from within Atom Beautify's setting panel. **Type**: `object` -**Supported Beautifiers**: [`Uncrustify`](#uncrustify) - **Description**: Options for Uncrustify executable. @@ -263,6 +232,13 @@ Options for Uncrustify executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Uncrustify*" and change it to your desired configuration. + +## Language Options + +Supported options for each language. + +--- + #### [Apex](#apex) **Supported Beautifiers**: [`Uncrustify`](#uncrustify) @@ -15915,27 +15891,6 @@ Path to the emacs script (Supported by Fortran Beautifier) } ``` -##### [Emacs](#emacs) - -**Namespace**: `` - -**Key**: `emacs` - -**Type**: `object` - -**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier) - -**Description**: - -Options for Emacs executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*Emacs*" and change it to your desired configuration. - ### Gherkin formatter @@ -17771,48 +17726,6 @@ Allow risky rules to be applied (PHP-CS-Fixer 2 only) (Supported by PHP-CS-Fixer } ``` -##### [PHP](#php) - -**Namespace**: `` - -**Key**: `php` - -**Type**: `object` - -**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) - -**Description**: - -Options for PHP executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*PHP*" and change it to your desired configuration. - -##### [PHP-CS-Fixer](#php-cs-fixer) - -**Namespace**: `` - -**Key**: `php-cs-fixer` - -**Type**: `object` - -**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) - -**Description**: - -Options for PHP-CS-Fixer executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*PHP-CS-Fixer*" and change it to your desired configuration. - ### PHPCBF @@ -17894,27 +17807,6 @@ Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS ru } ``` -##### [PHPCBF](#phpcbf) - -**Namespace**: `` - -**Key**: `phpcbf` - -**Type**: `object` - -**Supported Beautifiers**: [`PHPCBF`](#phpcbf) - -**Description**: - -Options for PHPCBF executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*PHPCBF*" and change it to your desired configuration. - ### Perltidy @@ -19093,27 +18985,6 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify) } ``` -##### [Uncrustify](#uncrustify) - -**Namespace**: `` - -**Key**: `uncrustify` - -**Type**: `object` - -**Supported Beautifiers**: [`Uncrustify`](#uncrustify) - -**Description**: - -Options for Uncrustify executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*Uncrustify*" and change it to your desired configuration. - ### Vue Beautifier @@ -20228,27 +20099,6 @@ Indentation size/length (Supported by formatR) } ``` -##### [Rscript](#rscript) - -**Namespace**: `` - -**Key**: `Rscript` - -**Type**: `object` - -**Supported Beautifiers**: [`formatR`](#formatr) - -**Description**: - -Options for Rscript executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*Rscript*" and change it to your desired configuration. - ### pybeautifier diff --git a/script/build-options.js b/script/build-options.js index 0bd8e6e..77c92b8 100644 --- a/script/build-options.js +++ b/script/build-options.js @@ -192,7 +192,7 @@ buildOptionsForExecutables = function(beautifiers) { type: "object", collapsed: true, description: `Options for ${name} executable.`, - beautifiers, + // beautifiers, properties: { path: { key: "path", diff --git a/src/options.json b/src/options.json index d07cd40..cd66dbc 100644 --- a/src/options.json +++ b/src/options.json @@ -9136,9 +9136,6 @@ "type": "object", "collapsed": true, "description": "Options for Uncrustify executable.", - "beautifiers": [ - "Uncrustify" - ], "properties": { "path": { "key": "path", @@ -9155,9 +9152,6 @@ "type": "object", "collapsed": true, "description": "Options for Emacs executable.", - "beautifiers": [ - "Fortran Beautifier" - ], "properties": { "path": { "key": "path", @@ -9174,9 +9168,6 @@ "type": "object", "collapsed": true, "description": "Options for PHP executable.", - "beautifiers": [ - "PHP-CS-Fixer" - ], "properties": { "path": { "key": "path", @@ -9193,9 +9184,6 @@ "type": "object", "collapsed": true, "description": "Options for PHP-CS-Fixer executable.", - "beautifiers": [ - "PHP-CS-Fixer" - ], "properties": { "path": { "key": "path", @@ -9212,9 +9200,6 @@ "type": "object", "collapsed": true, "description": "Options for PHPCBF executable.", - "beautifiers": [ - "PHPCBF" - ], "properties": { "path": { "key": "path", @@ -9231,9 +9216,6 @@ "type": "object", "collapsed": true, "description": "Options for Rscript executable.", - "beautifiers": [ - "formatR" - ], "properties": { "path": { "key": "path", From a9553fd51e3ca98fa7f314343f635d78af81848a Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 04:29:51 -0300 Subject: [PATCH 12/58] Switch autopep8 to using Executables --- docs/options.md | 34 ++++++++++++++++++ spec/beautify-languages-spec.coffee | 2 +- src/beautifiers/autopep8.coffee | 54 +++++++++++++++++++++-------- src/beautifiers/beautifier.coffee | 13 ++++--- src/beautifiers/executable.coffee | 22 +++++++++--- src/beautifiers/index.coffee | 1 + src/options.json | 32 +++++++++++++++++ 7 files changed, 133 insertions(+), 25 deletions(-) diff --git a/docs/options.md b/docs/options.md index a760c8c..305829d 100644 --- a/docs/options.md +++ b/docs/options.md @@ -147,6 +147,23 @@ Options for Rscript executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Rscript*" and change it to your desired configuration. +##### [autopep8](#autopep8) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for autopep8 executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*autopep8*" and change it to your desired configuration. + ##### [Emacs](#emacs) **Important**: This option is only configurable from within Atom Beautify's setting panel. @@ -164,6 +181,23 @@ Options for Emacs executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Emacs*" and change it to your desired configuration. +##### [isort](#isort) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for isort executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*isort*" and change it to your desired configuration. + ##### [PHP](#php) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 942dafb..1f39a55 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -162,7 +162,7 @@ describe "BeautifyLanguages", -> beautifyCompleted = false completionFun = (text) -> try - expect(text instanceof Error).not.toEqual(true, text) + expect(text instanceof Error).not.toEqual(true, text.toString()) return beautifyCompleted = true if text instanceof Error # logger.verbose(expectedTestPath, text) if ext is ".less" # if text instanceof Error diff --git a/src/beautifiers/autopep8.coffee b/src/beautifiers/autopep8.coffee index e38a648..2010c37 100644 --- a/src/beautifiers/autopep8.coffee +++ b/src/beautifiers/autopep8.coffee @@ -9,19 +9,42 @@ module.exports = class Autopep8 extends Beautifier name: "autopep8" link: "https://github.com/hhatto/autopep8" - isPreInstalled: false + executables: [ + { + name: "autopep8" + cmd: "autopep8" + homepage: "https://github.com/hhatto/autopep8" + installation: "https://github.com/hhatto/autopep8#installation" + version: { + parse: (text) -> text.match(/autopep8 (\d+\.\d+\.\d+)/)[1] + runOptions: { + returnStderr: true + } + } + } + { + name: "isort" + cmd: "isort" + optional: true + homepage: "https://github.com/timothycrosley/isort" + installation: "https://github.com/timothycrosley/isort#installing-isort" + version: { + parse: (text) -> text.match(/VERSION (\d+\.\d+\.\d+)/)[1] + } + } + ] options: { Python: true } beautify: (text, language, options) -> - @run("autopep8", [ - tempFile = @tempFile("input", text) - "-i" - ["--max-line-length", "#{options.max_line_length}"] if options.max_line_length? - ["--indent-size","#{options.indent_size}"] if options.indent_size? - ["--ignore","#{options.ignore.join(',')}"] if options.ignore? + @exe("autopep8").run([ + tempFile = @tempFile("input", text) + "-i" + ["--max-line-length", "#{options.max_line_length}"] if options.max_line_length? + ["--indent-size","#{options.indent_size}"] if options.indent_size? + ["--ignore","#{options.ignore.join(',')}"] if options.ignore? ], help: { link: "https://github.com/hhatto/autopep8" }) @@ -31,14 +54,15 @@ module.exports = class Autopep8 extends Beautifier filePath = editor.getPath() projectPath = atom.project.relativizePath(filePath)[0] - @run("isort", - ["-sp", projectPath, tempFile], - help: { - link: "https://github.com/timothycrosley/isort" - }) - .then(=> - @readFile(tempFile) - ) + @exe("isort") + .run( + ["-sp", projectPath, tempFile], + help: { + link: "https://github.com/timothycrosley/isort" + }) + .then(=> + @readFile(tempFile) + ) else @readFile(tempFile) ) diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 9c7a043..dce486a 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -47,14 +47,14 @@ module.exports = class Beautifier Promise.resolve(@_exe) else Promise.resolve(executables = @executables.map((e) -> new Executable(e))) - .then((executables) -> Promise.all(executables.map((e) -> e.init()))) + .then((executables) -> Promise.all(executables.map((exe) -> exe.init()))) .then((es) => @debug("Executables loaded", es) exe = {} missingInstalls = [] es.forEach((e) -> exe[e.cmd] = e - if not e.isInstalled + if not e.isInstalled and e.required missingInstalls.push(e) ) @_exe = exe @@ -62,13 +62,18 @@ module.exports = class Beautifier if missingInstalls.length is 0 return @_exe else - throw new Error("Missing required executables: #{missingInstalls.map((e) -> e.cmd).join(' and ')}") + @debug("Missing required executables: #{missingInstalls.map((e) -> e.cmd).join(' and ')}.") + throw Executable.commandNotFoundError(missingInstalls[0].cmd) + ) + .catch((error) => + @debug("Error loading executables", error) + Promise.reject(error) ) exe: (cmd) -> console.log('exe', cmd, @_exe) e = @_exe[cmd] if !e? - throw new Error("Missing executable \"#{cmd}\". Please report this bug to https://github.com/Glavin001/atom-beautify/issues") + throw Executable.commandNotFoundError(cmd) e ### diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 15b9c27..d3bbdf4 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -19,6 +19,7 @@ module.exports = class Executable versionParse: (text) -> semver.clean(text) versionRunOptions: {} versionsSupported: '>= 0.0.0' + required: true constructor: (options) -> # Validation @@ -29,6 +30,7 @@ module.exports = class Executable @key = @cmd @homepage = options.homepage @installation = options.installation + @required = not options.optional if options.version? versionOptions = options.version @versionArgs = versionOptions.args if versionOptions.args @@ -43,6 +45,12 @@ module.exports = class Executable ]) .then(() => @verbose("Done init of #{@name}")) .then(() => @) + .catch((error) => + if not @.required + @ + else + Promise.reject(error) + ) ### Logger instance @@ -82,7 +90,12 @@ module.exports = class Executable .catch((error) => @isInstalled = false @error(error) - Promise.reject(@commandNotFoundError()) + help = { + program: @cmd + link: @installation or @homepage + pathOption: "Executable - #{@name or @cmd} - Path" + } + Promise.reject(@commandNotFoundError(@name or @cmd, help)) ) else @verbose("Loading cached version") @@ -215,10 +228,9 @@ module.exports = class Executable ### commandNotFoundError: (exe, help) -> exe ?= @name or @cmd - # help ?= { - # program: @cmd - # link: @installation or @homepage - # } + @constructor.commandNotFoundError(exe, help) + + @commandNotFoundError: (exe, help) -> # Create new improved error # notify user that it may not be # installed or in path diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 6f212ab..9d39fc6 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -368,6 +368,7 @@ module.exports = class Beautifiers extends EventEmitter }) ) .catch((error) => + logger.error(error) reject(error) # Track Errors @trackEvent({ diff --git a/src/options.json b/src/options.json index cd66dbc..d3c8fc5 100644 --- a/src/options.json +++ b/src/options.json @@ -9146,6 +9146,38 @@ } } }, + "autopep8": { + "key": "autopep8", + "title": "autopep8", + "type": "object", + "collapsed": true, + "description": "Options for autopep8 executable.", + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"autopep8\" executable." + } + } + }, + "isort": { + "key": "isort", + "title": "isort", + "type": "object", + "collapsed": true, + "description": "Options for isort executable.", + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"isort\" executable." + } + } + }, "emacs": { "key": "emacs", "title": "Emacs", From a92a48c6d617b68931bdcc5f3a51053922c61546 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 04:37:13 -0300 Subject: [PATCH 13/58] Enable verbose logging for tests --- spec/beautify-languages-spec.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 1f39a55..15ef6d1 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -53,9 +53,9 @@ describe "BeautifyLanguages", -> pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() # Need more debugging on Windows - if isWindows - # Change logger level - atom.config.set('atom-beautify._loggerLevel', 'verbose') + # if isWindows + # Change logger level + atom.config.set('atom-beautify._loggerLevel', 'verbose') # Return promise return activationPromise From d99b43cb16175a39dac05442cd7dcb43836a70a6 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 2 Jun 2017 17:31:36 -0300 Subject: [PATCH 14/58] Fix Uncrustify's Executable version parser, newer Uncrustify is different format --- src/beautifiers/uncrustify/index.coffee | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/beautifiers/uncrustify/index.coffee b/src/beautifiers/uncrustify/index.coffee index 3d75ae6..0a8cac3 100644 --- a/src/beautifiers/uncrustify/index.coffee +++ b/src/beautifiers/uncrustify/index.coffee @@ -18,7 +18,14 @@ module.exports = class Uncrustify extends Beautifier homepage: "http://uncrustify.sourceforge.net/" installation: "https://github.com/uncrustify/uncrustify" version: { - parse: (text) -> text.match(/uncrustify (\d+\.\d+)/)[1] + ".0" + parse: (text) -> + try + v = text.match(/uncrustify (\d+\.\d+)/)[1] + catch error + @error(error) + v = text.match(/Uncrustify-(\d+\.\d+)/)[1] if not v? + if v + return v + ".0" } } ] @@ -94,9 +101,7 @@ module.exports = class Uncrustify extends Beautifier outputFile = @tempFile("output", text) "-l" lang - ], help: { - link: "http://sourceforge.net/projects/uncrustify/" - }) + ]) .then(=> @readFile(outputFile) ) From 02d4c8f4048b9aeb85aec1b64625e3fadd8f31ed Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 2 Jun 2017 17:33:18 -0300 Subject: [PATCH 15/58] Switch beautysh to using Executables --- package.json | 3 ++- src/beautifiers/autopep8.coffee | 8 ++------ src/beautifiers/beautysh.coffee | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 96a69e1..81b8625 100644 --- a/package.json +++ b/package.json @@ -407,6 +407,7 @@ "docs": "npm run build-options && coffee docs/", "prepublish": "npm run docs", "lint": "coffeelint src/ spec/", - "code-docs": "codo && open docs/code/index.html" + "code-docs": "codo && open docs/code/index.html", + "test": "atom --test spec" } } \ No newline at end of file diff --git a/src/beautifiers/autopep8.coffee b/src/beautifiers/autopep8.coffee index 2010c37..31e1bb1 100644 --- a/src/beautifiers/autopep8.coffee +++ b/src/beautifiers/autopep8.coffee @@ -45,9 +45,7 @@ module.exports = class Autopep8 extends Beautifier ["--max-line-length", "#{options.max_line_length}"] if options.max_line_length? ["--indent-size","#{options.indent_size}"] if options.indent_size? ["--ignore","#{options.ignore.join(',')}"] if options.ignore? - ], help: { - link: "https://github.com/hhatto/autopep8" - }) + ]) .then(=> if options.sort_imports editor = atom.workspace.getActiveTextEditor() @@ -57,9 +55,7 @@ module.exports = class Autopep8 extends Beautifier @exe("isort") .run( ["-sp", projectPath, tempFile], - help: { - link: "https://github.com/timothycrosley/isort" - }) + ) .then(=> @readFile(tempFile) ) diff --git a/src/beautifiers/beautysh.coffee b/src/beautifiers/beautysh.coffee index 86626a3..1cc634e 100644 --- a/src/beautifiers/beautysh.coffee +++ b/src/beautifiers/beautysh.coffee @@ -4,7 +4,19 @@ Beautifier = require('./beautifier') module.exports = class BashBeautify extends Beautifier name: "beautysh" link: "https://github.com/bemeurer/beautysh" - isPreInstalled: false + executables: [ + { + name: "beautysh" + cmd: "beautysh" + homepage: "https://github.com/bemeurer/beautysh" + installation: "https://github.com/bemeurer/beautysh#installation" + version: { + # Does not display version + args: ['--help'], + parse: (text) -> text.indexOf("usage: beautysh") isnt -1 and "0.0.0" + } + } + ] options: { Bash: @@ -12,6 +24,7 @@ module.exports = class BashBeautify extends Beautifier } beautify: (text, language, options) -> + beautysh = @exe("beautysh") file = @tempFile("input", text) - @run('beautysh', [ '-i', options.indent_size, '-f', file ], help: { link: "https://github.com/bemeurer/beautysh" }) - .then(=> @readFile file) + beautysh.run([ '-i', options.indent_size, '-f', file ]) + .then(=> @readFile file) From 738847c1564667b969bf613c7e2669461182baea Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 2 Jun 2017 17:48:52 -0300 Subject: [PATCH 16/58] Switch clang-format to using Executables, update docs --- docs/options.md | 34 +++++++++++++++++++++++++++++ src/beautifiers/clang-format.coffee | 18 ++++++++++----- src/options.json | 32 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/docs/options.md b/docs/options.md index 305829d..960b0bc 100644 --- a/docs/options.md +++ b/docs/options.md @@ -164,6 +164,40 @@ Options for autopep8 executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*autopep8*" and change it to your desired configuration. +##### [beautysh](#beautysh) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for beautysh executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*beautysh*" and change it to your desired configuration. + +##### [ClangFormat](#clangformat) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for ClangFormat executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*ClangFormat*" and change it to your desired configuration. + ##### [Emacs](#emacs) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/src/beautifiers/clang-format.coffee b/src/beautifiers/clang-format.coffee index eb4fa32..30f4e31 100644 --- a/src/beautifiers/clang-format.coffee +++ b/src/beautifiers/clang-format.coffee @@ -11,7 +11,17 @@ module.exports = class ClangFormat extends Beautifier name: "clang-format" link: "https://clang.llvm.org/docs/ClangFormat.html" - isPreInstalled: false + executables: [ + { + name: "ClangFormat" + cmd: "clang-format" + homepage: "https://clang.llvm.org/docs/ClangFormat.html" + installation: "https://clang.llvm.org/docs/ClangFormat.html" + version: { + parse: (text) -> text.match(/version (\d+\.\d+\.\d+)/)[1] + } + } + ] options: { "C++": false @@ -64,12 +74,10 @@ module.exports = class ClangFormat extends Beautifier ) .then((dumpFile) => # console.log("clang-format", dumpFile) - return @run("clang-format", [ + return @exe("clang-format").run([ @dumpToFile(dumpFile, text) ["--style=file"] - ], help: { - link: "https://clang.llvm.org/docs/ClangFormat.html" - }).finally( -> + ]).finally( -> fs.unlink(dumpFile) ) ) diff --git a/src/options.json b/src/options.json index d3c8fc5..22061f8 100644 --- a/src/options.json +++ b/src/options.json @@ -9178,6 +9178,22 @@ } } }, + "clang-format": { + "key": "clang-format", + "title": "ClangFormat", + "type": "object", + "collapsed": true, + "description": "Options for ClangFormat executable.", + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"clang-format\" executable." + } + } + }, "emacs": { "key": "emacs", "title": "Emacs", @@ -9257,6 +9273,22 @@ "description": "Absolute path to the \"Rscript\" executable." } } + }, + "beautysh": { + "key": "beautysh", + "title": "beautysh", + "type": "object", + "collapsed": true, + "description": "Options for beautysh executable.", + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"beautysh\" executable." + } + } } } } From 349edae0fd6addbcf42feaf4c86a5037e3bc4ac2 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 2 Jun 2017 18:12:09 -0300 Subject: [PATCH 17/58] Switch Crystal beautifier to using Executables --- src/beautifiers/crystal.coffee | 36 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/beautifiers/crystal.coffee b/src/beautifiers/crystal.coffee index cb1ad22..ecfe57d 100644 --- a/src/beautifiers/crystal.coffee +++ b/src/beautifiers/crystal.coffee @@ -8,28 +8,28 @@ Beautifier = require('./beautifier') module.exports = class Crystal extends Beautifier name: "Crystal" link: "http://crystal-lang.org" - isPreInstalled: false + executables: [ + { + name: "Crystal" + cmd: "crystal" + homepage: "http://crystal-lang.org" + installation: "https://crystal-lang.org/docs/installation/" + version: { + parse: (text) -> text.match(/Crystal (\d+\.\d+\.\d+)/)[1] + } + } + ] options: { Crystal: false } beautify: (text, language, options) -> - # Seems that Crystal dosen't have Windows support yet. - if @isWindows - @Promise.reject(@commandNotFoundError( - 'crystal' - { - link: "http://crystal-lang.org" - program: "crystal" - }) + @exe("crystal").run([ + 'tool', + 'format', + tempFile = @tempFile("temp", text) + ], {ignoreReturnCode: true}) + .then(=> + @readFile(tempFile) ) - else - @run("crystal", [ - 'tool', - 'format', - tempFile = @tempFile("temp", text) - ], {ignoreReturnCode: true}) - .then(=> - @readFile(tempFile) - ) From 3e78dc8701711c30df6c8d77f5aeb7c966d00d32 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 2 Jun 2017 18:22:32 -0300 Subject: [PATCH 18/58] Switch Dfmt beautifier to using Executables --- docs/options.md | 34 ++++++++++++++++++++++++++++++++++ src/beautifiers/dfmt.coffee | 11 +++++++++-- src/options.json | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/docs/options.md b/docs/options.md index 960b0bc..1d96ef2 100644 --- a/docs/options.md +++ b/docs/options.md @@ -198,6 +198,40 @@ Options for ClangFormat executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*ClangFormat*" and change it to your desired configuration. +##### [Crystal](#crystal) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for Crystal executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Crystal*" and change it to your desired configuration. + +##### [Dfmt](#dfmt) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for Dfmt executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Dfmt*" and change it to your desired configuration. + ##### [Emacs](#emacs) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/src/beautifiers/dfmt.coffee b/src/beautifiers/dfmt.coffee index 0accd86..c114e1b 100644 --- a/src/beautifiers/dfmt.coffee +++ b/src/beautifiers/dfmt.coffee @@ -7,13 +7,20 @@ Beautifier = require('./beautifier') module.exports = class Dfmt extends Beautifier name: "dfmt" link: "https://github.com/Hackerpilot/dfmt" - isPreInstalled: false + executables: [ + { + name: "Dfmt" + cmd: "dfmt" + homepage: "https://github.com/Hackerpilot/dfmt" + installation: "https://github.com/dlang-community/dfmt#building" + } + ] options: { D: false } beautify: (text, language, options) -> - @run("dfmt", [ + @exe("dfmt").run([ @tempFile("input", text) ]) diff --git a/src/options.json b/src/options.json index 22061f8..74637a6 100644 --- a/src/options.json +++ b/src/options.json @@ -9194,6 +9194,38 @@ } } }, + "crystal": { + "key": "crystal", + "title": "Crystal", + "type": "object", + "collapsed": true, + "description": "Options for Crystal executable.", + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"crystal\" executable." + } + } + }, + "dfmt": { + "key": "dfmt", + "title": "Dfmt", + "type": "object", + "collapsed": true, + "description": "Options for Dfmt executable.", + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"dfmt\" executable." + } + } + }, "emacs": { "key": "emacs", "title": "Emacs", From f945c3833892c8c281eac83afd75ff471e029a73 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 00:53:16 -0300 Subject: [PATCH 19/58] Add support for Whalebrew installed executables Whalebrew mounts a Docker volume to the host's current working directory (cwd) therefore the cwd needs to be the temp directory and all file paths which are to be beautified need to be given to Whalebrew as relative to cwd. Often this means the temporary directory is simply removed from the prefix of the file paths, and the cwd = the temporary directory. See https://github.com/bfirsh/whalebrew#how-it-works for details. --- src/beautifiers/executable.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index d3bbdf4..e16772c 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -5,6 +5,7 @@ spawn = require('child_process').spawn path = require('path') semver = require('semver') shellEnv = require('shell-env') +os = require('os') parentConfigKey = "atom-beautify.executables" @@ -127,6 +128,7 @@ module.exports = class Executable args = _.flatten(args) exeName = @cmd config = @getConfig() + cwd ?= os.tmpDir() # Resolve executable and all args Promise.all([@shellEnv(), Promise.all(args)]) @@ -143,13 +145,17 @@ module.exports = class Executable .then(([exeName, args, env, exePath]) => @debug('exePath:', exePath) @debug('env:', env) + @debug('PATH:', env.PATH) @debug('args', args) + args = this.relativizePaths(args) + @debug('relativized args', args) exe = exePath ? exeName spawnOptions = { cwd: cwd env: env } + @debug('spawnOptions', spawnOptions) @spawn(exe, args, spawnOptions, onStdin) .then(({returnCode, stdout, stderr}) => @@ -186,6 +192,16 @@ module.exports = class Executable ) ) + relativizePaths: (args) -> + tmpDir = os.tmpDir() + newArgs = args.map((arg) -> + isTmpFile = typeof arg is 'string' and path.isAbsolute(arg) and path.dirname(arg).startsWith(tmpDir) + if isTmpFile + return path.relative(tmpDir, arg) + return arg + ) + newArgs + ### Spawn ### From dc5f4a20dcef83ab457a6c1e76a2a7ba1c5a5b4a Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 02:43:02 -0300 Subject: [PATCH 20/58] Switch elm-format to using Executables --- docs/options.md | 17 +++++ .../nested-jsbeautifyrc/elm/expected/test.elm | 6 +- script/build-options.js | 4 +- src/beautifiers/elm-format.coffee | 28 +++++--- src/options.json | 64 ++++++++++++------- 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/docs/options.md b/docs/options.md index 1d96ef2..35cfbb8 100644 --- a/docs/options.md +++ b/docs/options.md @@ -232,6 +232,23 @@ Options for Dfmt executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Dfmt*" and change it to your desired configuration. +##### [elm-format](#elm-format) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for elm-format executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*elm-format*" and change it to your desired configuration. + ##### [Emacs](#emacs) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/examples/nested-jsbeautifyrc/elm/expected/test.elm b/examples/nested-jsbeautifyrc/elm/expected/test.elm index 3280f99..0d13064 100644 --- a/examples/nested-jsbeautifyrc/elm/expected/test.elm +++ b/examples/nested-jsbeautifyrc/elm/expected/test.elm @@ -1,9 +1,9 @@ -module Main (..) where +module Main exposing (..) addThings x y = - x + y + x + y main = - addThings 4 5 + addThings 4 5 diff --git a/script/build-options.js b/script/build-options.js index 77c92b8..838d603 100644 --- a/script/build-options.js +++ b/script/build-options.js @@ -196,10 +196,10 @@ buildOptionsForExecutables = function(beautifiers) { properties: { path: { key: "path", - title: "Executable Path", + title: "Binary/Script Path", type: "string", default: "", - description: `Absolute path to the "${cmd}" executable.`, + description: `Absolute path to the "${cmd}" executable's binary/script.`, } } } diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee index af91cf5..f6c8d85 100644 --- a/src/beautifiers/elm-format.coffee +++ b/src/beautifiers/elm-format.coffee @@ -7,7 +7,18 @@ Beautifier = require('./beautifier') module.exports = class ElmFormat extends Beautifier name: "elm-format" link: "https://github.com/avh4/elm-format" - isPreInstalled: false + executables: [ + { + name: "elm-format" + cmd: "elm-format" + homepage: "https://github.com/avh4/elm-format" + installation: "https://github.com/avh4/elm-format#installation-" + version: { + args: ['--help'] + parse: (text) -> text.match(/elm-format-\d+.\d+ (\d+\.\d+\.\d+)/)[1] + } + } + ] options: { Elm: true @@ -16,11 +27,10 @@ module.exports = class ElmFormat extends Beautifier beautify: (text, language, options) -> tempfile = @tempFile("input", text, ".elm") .then (name) => - @run("elm-format", [ - '--yes', - name - ], - { help: { link: 'https://github.com/avh4/elm-format#installation-' } } - ) - .then () => - @readFile(name) + @exe("elm-format") + .run([ + '--yes', + name + ]) + .then () => + @readFile(name) diff --git a/src/options.json b/src/options.json index 74637a6..4f4b65f 100644 --- a/src/options.json +++ b/src/options.json @@ -9139,10 +9139,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"uncrustify\" executable." + "description": "Absolute path to the \"uncrustify\" executable's binary/script." } } }, @@ -9155,10 +9155,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"autopep8\" executable." + "description": "Absolute path to the \"autopep8\" executable's binary/script." } } }, @@ -9171,10 +9171,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"isort\" executable." + "description": "Absolute path to the \"isort\" executable's binary/script." } } }, @@ -9187,10 +9187,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"clang-format\" executable." + "description": "Absolute path to the \"clang-format\" executable's binary/script." } } }, @@ -9203,10 +9203,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"crystal\" executable." + "description": "Absolute path to the \"crystal\" executable's binary/script." } } }, @@ -9219,10 +9219,26 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"dfmt\" executable." + "description": "Absolute path to the \"dfmt\" executable's binary/script." + } + } + }, + "elm-format": { + "key": "elm-format", + "title": "elm-format", + "type": "object", + "collapsed": true, + "description": "Options for elm-format executable.", + "properties": { + "path": { + "key": "path", + "title": "Binary/Script Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"elm-format\" executable's binary/script." } } }, @@ -9235,10 +9251,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"emacs\" executable." + "description": "Absolute path to the \"emacs\" executable's binary/script." } } }, @@ -9251,10 +9267,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"php\" executable." + "description": "Absolute path to the \"php\" executable's binary/script." } } }, @@ -9267,10 +9283,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"php-cs-fixer\" executable." + "description": "Absolute path to the \"php-cs-fixer\" executable's binary/script." } } }, @@ -9283,10 +9299,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"phpcbf\" executable." + "description": "Absolute path to the \"phpcbf\" executable's binary/script." } } }, @@ -9299,10 +9315,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"Rscript\" executable." + "description": "Absolute path to the \"Rscript\" executable's binary/script." } } }, @@ -9315,10 +9331,10 @@ "properties": { "path": { "key": "path", - "title": "Executable Path", + "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"beautysh\" executable." + "description": "Absolute path to the \"beautysh\" executable's binary/script." } } } From 1e5751a63a3a4898599612740404cb2f4989fb47 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 15:19:18 -0300 Subject: [PATCH 21/58] Add note in README about Executables+Docker feature. See #1687 --- README-template.md | 4 ++++ README.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README-template.md b/README-template.md index 9366c29..6dc0075 100644 --- a/README-template.md +++ b/README-template.md @@ -63,6 +63,10 @@ Thank you. Atom-Beautify is going to be completely rewritten with [Unibeautify](https://github.com/Unibeautify/unibeautify) at its core! See [`unibeautify` branch](../../tree/unibeautify) for work in progress and [Issue #1174](https://github.com/Glavin001/atom-beautify/issues/1174). +### Want automated installation? + +See [Issue #1678](https://github.com/Glavin001/atom-beautify/issues/1687) for a solution utilizing [Docker](https://www.docker.com/) to achieve automated installation of beautifiers which are not already preinstalled. + ## Beautifiers Some of the supported beautifiers are developed for Node.js and are automatically installed when Atom-Beautify is installed. However, other beautifiers are command-line interface (CLI) applications and require you to manually install them. diff --git a/README.md b/README.md index d644f98..e6e4d32 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ Thank you. Atom-Beautify is going to be completely rewritten with [Unibeautify](https://github.com/Unibeautify/unibeautify) at its core! See [`unibeautify` branch](../../tree/unibeautify) for work in progress and [Issue #1174](https://github.com/Glavin001/atom-beautify/issues/1174). +### Want automated installation? + +See [Issue #1678](https://github.com/Glavin001/atom-beautify/issues/1687) for a solution utilizing [Docker](https://www.docker.com/) to achieve automated installation of beautifiers which are not already preinstalled. + ## Beautifiers Some of the supported beautifiers are developed for Node.js and are automatically installed when Atom-Beautify is installed. However, other beautifiers are command-line interface (CLI) applications and require you to manually install them. From 84361e40112d4f25652dcc5a704faef70db7c680 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 16:03:45 -0300 Subject: [PATCH 22/58] Fix logging during tests. Show info level logs. --- spec/beautify-languages-spec.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 15ef6d1..24adace 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -53,9 +53,8 @@ describe "BeautifyLanguages", -> pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() # Need more debugging on Windows - # if isWindows # Change logger level - atom.config.set('atom-beautify._loggerLevel', 'verbose') + atom.config.set('atom-beautify.general.loggerLevel', 'info') # Return promise return activationPromise From 788cc724dd7095aa5c6af338d439f555579a2d29 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 16:04:06 -0300 Subject: [PATCH 23/58] Change log levels of some log statements --- src/beautifiers/executable.coffee | 4 ++-- src/beautifiers/index.coffee | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index e16772c..ddd382f 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -85,7 +85,7 @@ module.exports = class Executable @version = version ) .then((version) => - @verbose("#{@cmd} version: #{version}") + @info("#{@cmd} version: #{version}") version ) .catch((error) => @@ -105,7 +105,7 @@ module.exports = class Executable runVersion: () -> @run(@versionArgs, @versionRunOptions) .then((version) => - @verbose("Version: " + version) + @info("Version text: " + version) version ) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 9d39fc6..92acc76 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -278,7 +278,7 @@ module.exports = class Beautifiers extends EventEmitter return Promise.all(allOptions) .then((allOptions) => return new Promise((resolve, reject) => - logger.info('beautify', text, allOptions, grammar, filePath, onSave, language) + logger.debug('beautify', text, allOptions, grammar, filePath, onSave, language) logger.verbose(allOptions) language ?= @getLanguage(grammar, filePath) From 26bbef04a682cf748cafc22a88e2f9afcc2440b6 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 17:09:05 -0300 Subject: [PATCH 24/58] Fix elm-format tests, support older version format --- src/beautifiers/elm-format.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee index f6c8d85..4157f78 100644 --- a/src/beautifiers/elm-format.coffee +++ b/src/beautifiers/elm-format.coffee @@ -15,7 +15,11 @@ module.exports = class ElmFormat extends Beautifier installation: "https://github.com/avh4/elm-format#installation-" version: { args: ['--help'] - parse: (text) -> text.match(/elm-format-\d+.\d+ (\d+\.\d+\.\d+)/)[1] + parse: (text) -> + try + return text.match(/elm-format-\d+.\d+ (\d+\.\d+\.\d+)/)[1] + catch + return text.match(/elm-format (\d+\.\d+\.\d+)/)[1] } } ] From e9f9a7bf9782b20ca82c00e295f3748ee7f57e42 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 21:55:45 -0300 Subject: [PATCH 25/58] Update elm-format for Travis CI --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab3de9e..449006f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -122,11 +122,12 @@ before_install: # - stack install stylish-haskell # Elm - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.2.0-alpha/elm-format-0.2.0-alpha-mac-x64.tgz; + curl -L -o /tmp/elm-format.tgz + https://github.com/avh4/elm-format/releases/download/0.7.0-exp/elm-format-0.17-0.7.0-exp-mac-x64.tgz; tar xvzf /tmp/elm-format.tgz -C /usr/local/bin; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.2.0-alpha/elm-format-0.2.0-alpha-linux-x64.tgz; + curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.7.0-exp/elm-format-0.17-0.7.0-exp-linux-x64.tgz; tar xvzf /tmp/elm-format.tgz -C $HOME/.linuxbrew/bin; fi # OCaml From baca098a91c33e1bbc39fe7f78c27db2c36ba3b3 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 5 Jun 2017 01:48:56 -0300 Subject: [PATCH 26/58] Close #1687. Add Docker support to Executables. Setup elm-format, php-cs-fixer, phpcbf, uncrustify with Docker. --- src/beautifiers/elm-format.coffee | 3 + src/beautifiers/executable.coffee | 116 ++++++++++++++++++------ src/beautifiers/php-cs-fixer.coffee | 4 + src/beautifiers/phpcbf.coffee | 3 + src/beautifiers/uncrustify/index.coffee | 3 + 5 files changed, 102 insertions(+), 27 deletions(-) diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee index 4157f78..23f1605 100644 --- a/src/beautifiers/elm-format.coffee +++ b/src/beautifiers/elm-format.coffee @@ -21,6 +21,9 @@ module.exports = class ElmFormat extends Beautifier catch return text.match(/elm-format (\d+\.\d+\.\d+)/)[1] } + docker: { + image: "unibeautify/elm-format" + } } ] diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index ddd382f..e9d382b 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -6,10 +6,12 @@ path = require('path') semver = require('semver') shellEnv = require('shell-env') os = require('os') +fs = require('fs') parentConfigKey = "atom-beautify.executables" -module.exports = class Executable + +class Executable name: null cmd: null @@ -73,31 +75,7 @@ module.exports = class Executable if force or !@version? @verbose("Loading version without cache") @runVersion() - .then((text) => @versionParse(text)) - .then((version) -> - valid = Boolean(semver.valid(version)) - if not valid - throw new Error("Version is not valid: "+version) - version - ) - .then((version) => - @isInstalled = true - @version = version - ) - .then((version) => - @info("#{@cmd} version: #{version}") - version - ) - .catch((error) => - @isInstalled = false - @error(error) - help = { - program: @cmd - link: @installation or @homepage - pathOption: "Executable - #{@name or @cmd} - Path" - } - Promise.reject(@commandNotFoundError(@name or @cmd, help)) - ) + .then((text) => @saveVersion(text)) else @verbose("Loading cached version") Promise.resolve(@version) @@ -109,6 +87,34 @@ module.exports = class Executable version ) + saveVersion: (text) -> + Promise.resolve() + .then( => @versionParse(text)) + .then((version) -> + valid = Boolean(semver.valid(version)) + if not valid + throw new Error("Version is not valid: "+version) + version + ) + .then((version) => + @isInstalled = true + @version = version + ) + .then((version) => + @info("#{@cmd} version: #{version}") + version + ) + .catch((error) => + @isInstalled = false + @error(error) + help = { + program: @cmd + link: @installation or @homepage + pathOption: "Executable - #{@name or @cmd} - Path" + } + Promise.reject(@commandNotFoundError(@name or @cmd, help)) + ) + isSupported: () -> @isVersion(@versionsSupported) @@ -195,7 +201,7 @@ module.exports = class Executable relativizePaths: (args) -> tmpDir = os.tmpDir() newArgs = args.map((arg) -> - isTmpFile = typeof arg is 'string' and path.isAbsolute(arg) and path.dirname(arg).startsWith(tmpDir) + isTmpFile = typeof arg is 'string' and not arg.includes(':') and path.isAbsolute(arg) and path.dirname(arg).startsWith(tmpDir) if isTmpFile return path.relative(tmpDir, arg) return arg @@ -362,3 +368,59 @@ module.exports = class Executable ### isWindows: () -> @constructor.isWindows() @isWindows: () -> new RegExp('^win').test(process.platform) + +class HybridExecutable extends Executable + + dockerOptions: { + image: undefined + workingDir: "/workdir" + } + + constructor: (options) -> + super(options) + if options.docker? + @dockerOptions = Object.assign({}, @dockerOptions, options.docker) + @docker = @constructor.dockerExecutable() + + @docker: undefined + @dockerExecutable: () -> + if not @docker? + @docker = new Executable({ + name: "Docker" + cmd: "docker" + homepage: "https://www.docker.com/" + installation: "https://www.docker.com/get-docker" + version: { + parse: (text) -> text.match(/version [0]*([1-9]\d*).[0]*([1-9]\d*).[0]*([1-9]\d*)/).slice(1).join('.') + } + }) + return @docker + + init: () -> + super() + .catch((error) => + return Promise.reject(error) if not @docker? + @docker.init() + .then(=> @runImage(@versionArgs, @versionRunOptions)) + .then((text) => @saveVersion(text)) + .then(=> @) + .catch((error) => + @debug(error) + Promise.reject(error) + ) + ) + + run: (args, options = {}) -> + if @docker and @docker.isInstalled + return @runImage(args, options) + super(args, options) + + runImage: (args, options) -> + @debug("Run Docker executable: ", args, options) + { cwd } = options + pwd = fs.realpathSync(cwd or os.tmpDir()) + image = @dockerOptions.image + workingDir = @dockerOptions.workingDir + @docker.run(["run", "-v", "#{pwd}:#{workingDir}", "-w", workingDir, image, args], options) + +module.exports = HybridExecutable diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index 47539a5..e72dd6f 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -28,6 +28,10 @@ module.exports = class PHPCSFixer extends Beautifier version: { parse: (text) -> text.match(/version (.*) by/)[1] + ".0" } + docker: { + image: "unibeautify/php-cs-fixer" + workingDir: "/project" + } } ] diff --git a/src/beautifiers/phpcbf.coffee b/src/beautifiers/phpcbf.coffee index 1cf2204..58ffc95 100644 --- a/src/beautifiers/phpcbf.coffee +++ b/src/beautifiers/phpcbf.coffee @@ -17,6 +17,9 @@ module.exports = class PHPCBF extends Beautifier version: { args: ['--version'] } + docker: { + image: "unibeautify/phpcbf" + } } ] isPreInstalled: false diff --git a/src/beautifiers/uncrustify/index.coffee b/src/beautifiers/uncrustify/index.coffee index 0a8cac3..ffaa46a 100644 --- a/src/beautifiers/uncrustify/index.coffee +++ b/src/beautifiers/uncrustify/index.coffee @@ -27,6 +27,9 @@ module.exports = class Uncrustify extends Beautifier if v return v + ".0" } + docker: { + image: "unibeautify/uncrustify" + } } ] From e674fbccd1046b1755b2489d2f8ef91abcfda7ff Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 13:18:26 -0300 Subject: [PATCH 27/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 002bd1f..85ea809 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -123,11 +123,27 @@ install: - where uncrustify # elm-format - - curl -k -L https://github.com/avh4/elm-format/releases/download/0.2.0-alpha/elm-format-0.2.0-alpha-win-x64.zip -o elm-format.zip + - curl -k -L https://github.com/avh4/elm-format/releases/download/0.7.0-exp/elm-format-0.17-0.7.0-exp-win-x64.zip -o elm-format.zip - 7za e elm-format.zip -oelm-format-d - "SET PATH=%cd%\\elm-format-d;%PATH%" - where elm-format + # R + - choco install r.project + - where Rscript + + # Docker + - choco install docker-for-windows --pre + - choco install docker + - where docker + - docker --version + - docker ps + + # Beautysh + - docker pull unibeautify/beautysh + - docker run -it unibeautify/beautysh + + build_script: - cd %APPVEYOR_BUILD_FOLDER% From d5cd70be4d90403edb54d8111058cf0959642123 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 13:28:25 -0300 Subject: [PATCH 28/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 85ea809..d7b29bd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -115,6 +115,13 @@ install: - "SET PATH=%cd%;%PATH%" # Add current working directory to PATH - where php-cs-fixer + # Docker + - choco install docker-for-windows --pre + - choco install docker + - where docker + - docker --version + - docker ps + # Uncrustify - curl -k -L http://sourceforge.net/projects/uncrustify/files/uncrustify/uncrustify-0.61/uncrustify-0.61.3-gf65394e-win32.zip/download -o uncrustify.zip - cinst 7zip.commandline -y @@ -123,22 +130,13 @@ install: - where uncrustify # elm-format - - curl -k -L https://github.com/avh4/elm-format/releases/download/0.7.0-exp/elm-format-0.17-0.7.0-exp-win-x64.zip -o elm-format.zip - - 7za e elm-format.zip -oelm-format-d - - "SET PATH=%cd%\\elm-format-d;%PATH%" - - where elm-format + - docker pull unibeautify/elm-format + - docker run -it unibeautify/elm-format # R - choco install r.project - where Rscript - # Docker - - choco install docker-for-windows --pre - - choco install docker - - where docker - - docker --version - - docker ps - # Beautysh - docker pull unibeautify/beautysh - docker run -it unibeautify/beautysh From 165a9e35949e4525ef5ac03d4ad7e4dc6b805432 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 13:37:36 -0300 Subject: [PATCH 29/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d7b29bd..53303e8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: "{build}" -os: Windows Server 2012 R2 +os: Visual Studio 2017 test: off deploy: off @@ -116,8 +116,6 @@ install: - where php-cs-fixer # Docker - - choco install docker-for-windows --pre - - choco install docker - where docker - docker --version - docker ps @@ -134,8 +132,8 @@ install: - docker run -it unibeautify/elm-format # R - - choco install r.project - - where Rscript + - docker pull unibeautify/rscript + - docker run -it unibeautify/rscript # Beautysh - docker pull unibeautify/beautysh From faa42504be700923763e323359eda900fed2c5ad Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 13:38:12 -0300 Subject: [PATCH 30/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 53303e8..eb699dd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: "{build}" -os: Visual Studio 2017 +image: Visual Studio 2017 test: off deploy: off From c7023a8c2dd7668b0d86d388549df92a6e9c0393 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 13:46:16 -0300 Subject: [PATCH 31/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index eb699dd..f09ea4b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -46,8 +46,8 @@ install: - ECHO "Filesystem root:" - ps: "ls \"C:/\"" - - ECHO "Installed SDKs:" - - ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\"" + # - ECHO "Installed SDKs:" + # - ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\"" - cinst atom -y - cd %APPVEYOR_BUILD_FOLDER% From fca67a5d0836e317e1e5ee72159f3212af5688d4 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 14:05:24 -0300 Subject: [PATCH 32/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index f09ea4b..4d8df57 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -46,9 +46,6 @@ install: - ECHO "Filesystem root:" - ps: "ls \"C:/\"" - # - ECHO "Installed SDKs:" - # - ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\"" - - cinst atom -y - cd %APPVEYOR_BUILD_FOLDER% # Add Atom's bin (apm, etc) to PATH @@ -115,11 +112,6 @@ install: - "SET PATH=%cd%;%PATH%" # Add current working directory to PATH - where php-cs-fixer - # Docker - - where docker - - docker --version - - docker ps - # Uncrustify - curl -k -L http://sourceforge.net/projects/uncrustify/files/uncrustify/uncrustify-0.61/uncrustify-0.61.3-gf65394e-win32.zip/download -o uncrustify.zip - cinst 7zip.commandline -y @@ -128,17 +120,18 @@ install: - where uncrustify # elm-format - - docker pull unibeautify/elm-format - - docker run -it unibeautify/elm-format + - curl -k -L https://github.com/avh4/elm-format/releases/download/0.7.0-exp/elm-format-0.18-0.7.0-exp-win-i386.zip -o elm-format.zip + - 7za e elm-format.zip -oelm-format-d + - "SET PATH=%cd%\\elm-format-d;%PATH%" + - where elm-format # R - - docker pull unibeautify/rscript - - docker run -it unibeautify/rscript + - choco install r.project -y + - where Rscript # Beautysh - - docker pull unibeautify/beautysh - - docker run -it unibeautify/beautysh - + - pip install beautysh + - where beautysh build_script: From 87d390b0fcd5e6d7bb663b24b167c4867268378d Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 14:25:45 -0300 Subject: [PATCH 33/58] Update AppVeyor in attempt to fix failing tests --- appveyor.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4d8df57..e30aee1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -125,14 +125,15 @@ install: - "SET PATH=%cd%\\elm-format-d;%PATH%" - where elm-format - # R - - choco install r.project -y - - where Rscript - # Beautysh - pip install beautysh - where beautysh + # R + - choco install r.project -y + - where R + + build_script: - cd %APPVEYOR_BUILD_FOLDER% From 6a28106bd69659628c2f02f2f381142aad79b379 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 14:52:35 -0300 Subject: [PATCH 34/58] Disable ocaml, r, clojure languages for Windows tests --- spec/beautify-languages-spec.coffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 24adace..2405a9f 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -15,6 +15,14 @@ isWindows = process.platform is 'win32' or process.env.OSTYPE is 'cygwin' or process.env.OSTYPE is 'msys' +unspportedLangs = { + windows: [ + "ocaml" + "r" + "clojure" + ] +} + describe "BeautifyLanguages", -> optionsDir = path.resolve(__dirname, "../examples") @@ -95,7 +103,8 @@ describe "BeautifyLanguages", -> for lang in langNames # FIXME: Skip testing ocaml in Windows - if isWindows && lang == 'ocaml' + if isWindows and unspportedLangs.windows.indexOf(lang) isnt -1 + console.warn("Tests for Windows do not support #{lang}") continue do (lang) -> From 9b840b14c2a9220900e76b5a1a91a16415f05231 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 14:52:51 -0300 Subject: [PATCH 35/58] Remove R from Windows tests in AppVeyor --- appveyor.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e30aee1..830ce5c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -129,11 +129,6 @@ install: - pip install beautysh - where beautysh - # R - - choco install r.project -y - - where R - - build_script: - cd %APPVEYOR_BUILD_FOLDER% From 4203fb72da2c71a9c3c3e0d7af50e38ae7139580 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 15:22:35 -0300 Subject: [PATCH 36/58] See #1687. Add docker images to supported executables --- src/beautifiers/autopep8.coffee | 3 +++ src/beautifiers/beautysh.coffee | 3 +++ src/beautifiers/clang-format.coffee | 3 +++ src/beautifiers/crystal.coffee | 3 +++ src/beautifiers/formatR/index.coffee | 3 +++ 5 files changed, 15 insertions(+) diff --git a/src/beautifiers/autopep8.coffee b/src/beautifiers/autopep8.coffee index 31e1bb1..33ee14d 100644 --- a/src/beautifiers/autopep8.coffee +++ b/src/beautifiers/autopep8.coffee @@ -21,6 +21,9 @@ module.exports = class Autopep8 extends Beautifier returnStderr: true } } + docker: { + image: "unibeautify/autopep8" + } } { name: "isort" diff --git a/src/beautifiers/beautysh.coffee b/src/beautifiers/beautysh.coffee index 1cc634e..74e3c11 100644 --- a/src/beautifiers/beautysh.coffee +++ b/src/beautifiers/beautysh.coffee @@ -15,6 +15,9 @@ module.exports = class BashBeautify extends Beautifier args: ['--help'], parse: (text) -> text.indexOf("usage: beautysh") isnt -1 and "0.0.0" } + docker: { + image: "unibeautify/beautysh" + } } ] diff --git a/src/beautifiers/clang-format.coffee b/src/beautifiers/clang-format.coffee index 30f4e31..bffd6b9 100644 --- a/src/beautifiers/clang-format.coffee +++ b/src/beautifiers/clang-format.coffee @@ -20,6 +20,9 @@ module.exports = class ClangFormat extends Beautifier version: { parse: (text) -> text.match(/version (\d+\.\d+\.\d+)/)[1] } + docker: { + image: "unibeautify/clang-format" + } } ] diff --git a/src/beautifiers/crystal.coffee b/src/beautifiers/crystal.coffee index ecfe57d..756e8c1 100644 --- a/src/beautifiers/crystal.coffee +++ b/src/beautifiers/crystal.coffee @@ -17,6 +17,9 @@ module.exports = class Crystal extends Beautifier version: { parse: (text) -> text.match(/Crystal (\d+\.\d+\.\d+)/)[1] } + docker: { + image: "unibeautify/crystal" + } } ] diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index 40e2d9f..b8e4a9e 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -21,6 +21,9 @@ module.exports = class R extends Beautifier returnStderr: true } } + docker: { + image: "unibeautify/rscript" + } } ] From 200f53ea38ba06d794629ac2a48ae8e5d2538ffb Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 15:37:22 -0300 Subject: [PATCH 37/58] Show verbose logs when testing --- spec/atom-beautify-spec.coffee | 2 +- spec/beautifier-php-cs-fixer-spec.coffee | 2 +- spec/beautify-languages-spec.coffee | 2 +- src/beautifiers/executable.coffee | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/atom-beautify-spec.coffee b/spec/atom-beautify-spec.coffee index d128a7e..9698ac5 100644 --- a/spec/atom-beautify-spec.coffee +++ b/spec/atom-beautify-spec.coffee @@ -31,7 +31,7 @@ describe "Atom-Beautify", -> pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() # Change logger level - # atom.config.set('atom-beautify._loggerLevel', 'verbose') + atom.config.set('atom-beautify.general.loggerLevel', 'verbose') # Return promise return activationPromise diff --git a/spec/beautifier-php-cs-fixer-spec.coffee b/spec/beautifier-php-cs-fixer-spec.coffee index 391bb15..0e39eb5 100644 --- a/spec/beautifier-php-cs-fixer-spec.coffee +++ b/spec/beautifier-php-cs-fixer-spec.coffee @@ -24,7 +24,7 @@ describe "PHP-CS-Fixer Beautifier", -> pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() # Change logger level - # atom.config.set('atom-beautify._loggerLevel', 'verbose') + atom.config.set('atom-beautify.general.loggerLevel', 'verbose') # Return promise return activationPromise diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 2405a9f..bc41649 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -62,7 +62,7 @@ describe "BeautifyLanguages", -> pack.activateNow() # Need more debugging on Windows # Change logger level - atom.config.set('atom-beautify.general.loggerLevel', 'info') + atom.config.set('atom-beautify.general.loggerLevel', 'verbose') # Return promise return activationPromise diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index e9d382b..0a2ebb1 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -404,8 +404,8 @@ class HybridExecutable extends Executable .then(=> @runImage(@versionArgs, @versionRunOptions)) .then((text) => @saveVersion(text)) .then(=> @) - .catch((error) => - @debug(error) + .catch((dockerError) => + @debug(dockerError) Promise.reject(error) ) ) From c7f0f72f01103665cb790324247e8a9711f58fbd Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 16:40:36 -0300 Subject: [PATCH 38/58] Update uncrustify install for AppVeyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 830ce5c..d12d3b4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -113,7 +113,7 @@ install: - where php-cs-fixer # Uncrustify - - curl -k -L http://sourceforge.net/projects/uncrustify/files/uncrustify/uncrustify-0.61/uncrustify-0.61.3-gf65394e-win32.zip/download -o uncrustify.zip + - curl -k -L https://sourceforge.net/projects/uncrustify/files/uncrustify/uncrustify-0.65/uncrustify-0.65-win32.zip/download -o uncrustify.zip - cinst 7zip.commandline -y - 7za e uncrustify.zip -ouncrustify-d - "SET PATH=%cd%\\uncrustify-d;%PATH%" From 43e4d8c37b09ef9d1bf1d8440c0500198e2cf0e2 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 16:40:57 -0300 Subject: [PATCH 39/58] Add Linux+Docker service to Travis CI --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 449006f..b635ae2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,13 @@ go: matrix: include: + - os: linux + dist: trusty + sudo: required + services: + - docker + env: + - ATOM_CHANNEL=stable # - os: linux # dist: trusty # sudo: require From 3023fea29781f626b1e18bf697b8d48fa1c31a26 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 16:45:44 -0300 Subject: [PATCH 40/58] Disable broken Windows tests --- spec/beautify-languages-spec.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index bc41649..9229249 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -20,6 +20,15 @@ unspportedLangs = { "ocaml" "r" "clojure" + # Broken + "apex" + "bash" + "csharp" + "d" + "elm" + "java" + "objectivec" + "opencl" ] } From 2737a546046d462bd01b53d828baec2c1d01d4be Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 21:36:43 -0300 Subject: [PATCH 41/58] Change test loggerLevel from verbose to info --- spec/atom-beautify-spec.coffee | 2 +- spec/beautifier-php-cs-fixer-spec.coffee | 2 +- spec/beautify-languages-spec.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/atom-beautify-spec.coffee b/spec/atom-beautify-spec.coffee index 9698ac5..3ad936f 100644 --- a/spec/atom-beautify-spec.coffee +++ b/spec/atom-beautify-spec.coffee @@ -31,7 +31,7 @@ describe "Atom-Beautify", -> pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() # Change logger level - atom.config.set('atom-beautify.general.loggerLevel', 'verbose') + atom.config.set('atom-beautify.general.loggerLevel', 'info') # Return promise return activationPromise diff --git a/spec/beautifier-php-cs-fixer-spec.coffee b/spec/beautifier-php-cs-fixer-spec.coffee index 0e39eb5..4f4e211 100644 --- a/spec/beautifier-php-cs-fixer-spec.coffee +++ b/spec/beautifier-php-cs-fixer-spec.coffee @@ -24,7 +24,7 @@ describe "PHP-CS-Fixer Beautifier", -> pack = atom.packages.getLoadedPackage("atom-beautify") pack.activateNow() # Change logger level - atom.config.set('atom-beautify.general.loggerLevel', 'verbose') + atom.config.set('atom-beautify.general.loggerLevel', 'info') # Return promise return activationPromise diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index 9229249..feca6af 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -71,7 +71,7 @@ describe "BeautifyLanguages", -> pack.activateNow() # Need more debugging on Windows # Change logger level - atom.config.set('atom-beautify.general.loggerLevel', 'verbose') + atom.config.set('atom-beautify.general.loggerLevel', 'info') # Return promise return activationPromise From 13601a38b3d0a044fb3c904c7a353c138d89793d Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 22:22:56 -0300 Subject: [PATCH 42/58] Attempt to fix rscript for Linux --- .travis.yml | 1 + src/beautifiers/formatR/index.coffee | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b635ae2..35cc548 100644 --- a/.travis.yml +++ b/.travis.yml @@ -107,6 +107,7 @@ before_install: # R - brew tap homebrew/science - brew install r + - rscript --version # PHP - brew tap homebrew/homebrew-php - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index b8e4a9e..b8da15f 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -12,7 +12,7 @@ module.exports = class R extends Beautifier executables: [ { name: "Rscript" - cmd: "Rscript" + cmd: "rscript" homepage: "https://github.com/yihui/formatR" installation: "https://github.com/yihui/formatR" version: { @@ -32,9 +32,9 @@ module.exports = class R extends Beautifier } beautify: (text, language, options) -> - rScript = @exe("Rscript") + rscript = @exe("rscript") r_beautifier = path.resolve(__dirname, "formatR.r") - rScript.run([ + rscript.run([ r_beautifier, options.indent_size, @tempFile("input", text), From a36fc7d1e1717f100ca29ed6e22f2ce9f84a787a Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Jun 2017 23:26:37 -0300 Subject: [PATCH 43/58] Remove rscript install from Linux Travis CI, use Docker instead --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 35cc548..db18f7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,6 +80,8 @@ cache: - $HOME/.stack before_install: + # Docker based beautifiers + - docker pull unibeautify/rscript # Install Homebrew on Linux - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git clone --depth=1 https://github.com/Linuxbrew/brew.git ~/.linuxbrew || true; @@ -106,8 +108,10 @@ before_install: - brew install uncrustify # R - brew tap homebrew/science - - brew install r - - rscript --version + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + brew install r; + rscript --version; + fi # PHP - brew tap homebrew/homebrew-php - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then From 999b256163e0dd4597c00332943cb5e7962aa917 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 12 Jun 2017 00:12:53 -0300 Subject: [PATCH 44/58] Fix Mac Travis CI build, use docker only in Linux build --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index db18f7a..1bf70c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,8 +80,6 @@ cache: - $HOME/.stack before_install: - # Docker based beautifiers - - docker pull unibeautify/rscript # Install Homebrew on Linux - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git clone --depth=1 https://github.com/Linuxbrew/brew.git ~/.linuxbrew || true; @@ -111,6 +109,9 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install r; rscript --version; + else + # Docker based beautifiers + docker pull unibeautify/rscript; fi # PHP - brew tap homebrew/homebrew-php From 59a78207230fc970b9486341ee73b002bd651458 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 12 Jun 2017 00:26:14 -0300 Subject: [PATCH 45/58] Fix formatR, do not pipe stdout to file, unnecessarily --- src/beautifiers/formatR/index.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index b8da15f..f45e862 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -38,6 +38,4 @@ module.exports = class R extends Beautifier r_beautifier, options.indent_size, @tempFile("input", text), - '>', - @tempFile("input", text) ]) From d3d4dccf478d37cd6fba8b5a0c0905ee766c65a9 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 12 Jun 2017 00:28:33 -0300 Subject: [PATCH 46/58] Fix error in Travis CI YAML --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1bf70c1..ea7e125 100644 --- a/.travis.yml +++ b/.travis.yml @@ -110,7 +110,6 @@ before_install: brew install r; rscript --version; else - # Docker based beautifiers docker pull unibeautify/rscript; fi # PHP From 45fa44680fec7a4ff6722b66a71f1ad19cb5b7d4 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 15 Jun 2017 23:35:03 -0300 Subject: [PATCH 47/58] Update dependencies --- package.json | 61 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 81b8625..f395f46 100644 --- a/package.json +++ b/package.json @@ -149,33 +149,33 @@ }, "dependencies": { "align-yaml": "^0.1.8", - "async": "^2.0.1", - "atom-message-panel": "^1.2.4", - "atom-space-pen-views": "^2.0.5", - "bluebird": "^3.4.3", + "async": "^2.4.1", + "atom-message-panel": "^1.3.0", + "atom-space-pen-views": "^2.2.0", + "bluebird": "^3.5.0", "coffee-fmt": "^0.12.0", "coffee-formatter": "^0.1.2", - "coffee-script": "^1.11.0", - "csscomb": "^4.0.1", - "diff": "3.0.0", + "coffee-script": "^1.12.6", + "csscomb": "^4.2.0", + "diff": "^3.2.0", "editorconfig": "^0.13.2", - "eslint": "^3.13.1", - "event-kit": "^2.1.0", + "eslint": "^4.0.0", + "event-kit": "^2.3.0", "expand-home-dir": "0.0.3", - "extend": "^3.0.0", - "gherkin": "2.12.2", - "handlebars": "^4.0.2", - "js-beautify": "^1.6.3", + "extend": "^3.0.1", + "gherkin": "^2.12.2", + "handlebars": "^4.0.10", + "js-beautify": "^1.6.14", "jscs": "^3.0.7", - "lodash": "^4.14.2", - "loophole": "^1.0.0", - "marko-prettyprint": "^1.3.5", - "nginxbeautify": "^2.0.0", - "node-cljfmt": "^0.5.3-1", - "node-dir": "^0.1.16", - "node-uuid": "^1.4.3", + "lodash": "^4.17.4", + "loophole": "^1.1.0", + "marko-prettyprint": "^1.3.6", + "nginxbeautify": "^2.0.1", + "node-cljfmt": "0.5.3", + "node-dir": "0.1.17", + "node-uuid": "1.4.8", "open": "0.0.5", - "prettydiff": "^1.16.27", + "prettydiff": "99.0.1", "pug-beautify": "^0.1.1", "remark": "^6.0.1", "season": "^5.3.0", @@ -399,8 +399,7 @@ "align-yaml" ], "devDependencies": { - "coffeelint": "^1.10.1", - "handlebars": "^4.0.2" + "coffeelint": "^1.10.1" }, "scripts": { "build-options": "node script/build-options.js", @@ -409,5 +408,19 @@ "lint": "coffeelint src/ spec/", "code-docs": "codo && open docs/code/index.html", "test": "atom --test spec" + }, + "config": { + "next-update": { + "skip": [ + "gherkin", + "expand-home-dir" + ] + } + }, + "greenkeeper": { + "ignore": [ + "gherkin", + "expand-home-dir" + ] } -} \ No newline at end of file +} From 3909da31ee3c234a70592c821849b27e35a6dd71 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 15 Jun 2017 23:39:27 -0300 Subject: [PATCH 48/58] Update dependencies --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index f395f46..a9e851e 100644 --- a/package.json +++ b/package.json @@ -177,21 +177,21 @@ "open": "0.0.5", "prettydiff": "99.0.1", "pug-beautify": "^0.1.1", - "remark": "^6.0.1", - "season": "^5.3.0", + "remark": "7.0.1", + "season": "6.0.0", "semver": "^5.3.0", "shell-env": "^0.3.0", - "space-pen": "^5.1.1", + "space-pen": "5.1.2", "strip-json-comments": "^2.0.1", "temp": "^0.8.3", "tidy-markdown": "2.0.3", "typescript": "^1.8.10", "typescript-formatter": "^2.3.0", "underscore-plus": "^1.6.6", - "universal-analytics": "^0.4.2", - "which": "^1.2.11", - "winston": "^2.2.0", - "yaml-front-matter": "^3.2.3" + "universal-analytics": "0.4.13", + "which": "1.2.14", + "winston": "2.3.1", + "yaml-front-matter": "3.4.0" }, "activationCommands": { "atom-workspace": [ @@ -399,7 +399,7 @@ "align-yaml" ], "devDependencies": { - "coffeelint": "^1.10.1" + "coffeelint": "1.16.0" }, "scripts": { "build-options": "node script/build-options.js", @@ -423,4 +423,4 @@ "expand-home-dir" ] } -} +} \ No newline at end of file From 5378b0bb970a2432e6d50a3b538ba5ad7e843394 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 00:12:18 -0300 Subject: [PATCH 49/58] Update docs --- docs/options.md | 34 +++++++++++++++++----------------- src/options.json | 6 +++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/options.md b/docs/options.md index 35cfbb8..da88035 100644 --- a/docs/options.md +++ b/docs/options.md @@ -130,23 +130,6 @@ Show loading view when beautifying Configure executables used by beautifiers. -##### [Rscript](#rscript) - -**Important**: This option is only configurable from within Atom Beautify's setting panel. - -**Type**: `object` - -**Description**: - -Options for Rscript executable. - -**How to Configure** - -1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to -*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. -2. Go into *Packages* and search for "*Atom Beautify*" package. -3. Find the option "*Rscript*" and change it to your desired configuration. - ##### [autopep8](#autopep8) **Important**: This option is only configurable from within Atom Beautify's setting panel. @@ -334,6 +317,23 @@ Options for PHPCBF executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*PHPCBF*" and change it to your desired configuration. +##### [Rscript](#rscript) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for Rscript executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Rscript*" and change it to your desired configuration. + ##### [Uncrustify](#uncrustify) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/src/options.json b/src/options.json index 4f4b65f..8456f22 100644 --- a/src/options.json +++ b/src/options.json @@ -9306,8 +9306,8 @@ } } }, - "Rscript": { - "key": "Rscript", + "rscript": { + "key": "rscript", "title": "Rscript", "type": "object", "collapsed": true, @@ -9318,7 +9318,7 @@ "title": "Binary/Script Path", "type": "string", "default": "", - "description": "Absolute path to the \"Rscript\" executable's binary/script." + "description": "Absolute path to the \"rscript\" executable's binary/script." } } }, From a5a00c893e96a9f90654ea963ab57458bb002bed Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 00:33:33 -0300 Subject: [PATCH 50/58] Show disabled tests as skipped --- spec/beautify-languages-spec.coffee | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index feca6af..c61b654 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -15,7 +15,9 @@ isWindows = process.platform is 'win32' or process.env.OSTYPE is 'cygwin' or process.env.OSTYPE is 'msys' -unspportedLangs = { +unsupportedLangs = { + all: [ + ] windows: [ "ocaml" "r" @@ -111,10 +113,12 @@ describe "BeautifyLanguages", -> langNames = fs.readdirSync(langsDir) for lang in langNames - # FIXME: Skip testing ocaml in Windows - if isWindows and unspportedLangs.windows.indexOf(lang) isnt -1 + shouldSkipLang = false + if unsupportedLangs.all.indexOf(lang) isnt -1 + shouldSkipLang = true + if isWindows and unsupportedLangs.windows.indexOf(lang) isnt -1 console.warn("Tests for Windows do not support #{lang}") - continue + shouldSkipLang = true do (lang) -> # Generate the path to where al of the tests are @@ -136,7 +140,7 @@ describe "BeautifyLanguages", -> fs.mkdirSync(expectedDir) # Language group tests - describe "when beautifying language '#{lang}'", -> + describe "#{if shouldSkipLang then '#' else ''}when beautifying language '#{lang}'", -> # All tests for language testNames = fs.readdirSync(originalDir) @@ -145,11 +149,12 @@ describe "BeautifyLanguages", -> ext = path.extname(testFileName) testName = path.basename(testFileName, ext) # If prefixed with underscore (_) then this is a hidden test + shouldSkip = false if testFileName[0] is '_' # Do not show this test - return + shouldSkip = true # Confirm this is a test - it "#{testName} #{testFileName}", -> + it "#{if shouldSkip then '# ' else ''}#{testName} #{testFileName}", -> # Generate paths to test files originalTestPath = path.resolve(originalDir, testFileName) From 0b2b06a928e0af7d9e32db224264916847167883 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 01:22:19 -0300 Subject: [PATCH 51/58] Improve error handling of beautify and testing --- spec/beautify-languages-spec.coffee | 2 +- src/beautifiers/executable.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index c61b654..1dc988c 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -184,7 +184,7 @@ describe "BeautifyLanguages", -> beautifyCompleted = false completionFun = (text) -> try - expect(text instanceof Error).not.toEqual(true, text.toString()) + expect(text instanceof Error).not.toEqual(true, text.message or text.toString()) return beautifyCompleted = true if text instanceof Error # logger.verbose(expectedTestPath, text) if ext is ".less" # if text instanceof Error diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 0a2ebb1..4701db2 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -179,7 +179,7 @@ class Executable if @isWindows() and returnCode is 1 and stderr.indexOf(windowsProgramNotFoundMsg) isnt -1 throw @commandNotFoundError(exeName, help) else - throw new Error(stderr) + throw new Error(stderr or stdout) else if returnStderr stderr From 7899be966bbc5b23c52710565a6618a26025d01d Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 01:22:59 -0300 Subject: [PATCH 52/58] Fix bug causing Executable to use Docker first, instead of builtin command --- src/beautifiers/executable.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 4701db2..8874186 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -396,6 +396,7 @@ class HybridExecutable extends Executable }) return @docker + installedWithDocker: false init: () -> super() .catch((error) => @@ -403,6 +404,7 @@ class HybridExecutable extends Executable @docker.init() .then(=> @runImage(@versionArgs, @versionRunOptions)) .then((text) => @saveVersion(text)) + .then(() => @installedWithDocker = true) .then(=> @) .catch((dockerError) => @debug(dockerError) @@ -411,7 +413,7 @@ class HybridExecutable extends Executable ) run: (args, options = {}) -> - if @docker and @docker.isInstalled + if @installedWithDocker and @docker and @docker.isInstalled return @runImage(args, options) super(args, options) From 40f1fe3c8dcfad55312a57b41ace3c13f113893d Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 20:33:19 -0300 Subject: [PATCH 53/58] Fixes #1361. Add file extension to temporary files for Uncrustify beautifier --- src/beautifiers/index.coffee | 3 ++- src/beautifiers/uncrustify/index.coffee | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 92acc76..e16d1a7 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -282,6 +282,7 @@ module.exports = class Beautifiers extends EventEmitter logger.verbose(allOptions) language ?= @getLanguage(grammar, filePath) + fileExtension = @getExtension(filePath) # Check if unsupported language if !language @@ -343,6 +344,7 @@ module.exports = class Beautifiers extends EventEmitter context = filePath: filePath + fileExtension: fileExtension startTime = new Date() beautifier.loadExecutables() @@ -405,7 +407,6 @@ module.exports = class Beautifiers extends EventEmitter if atom.config.get("atom-beautify.general.muteUnsupportedLanguageErrors") return resolve( null ) else - fileExtension = @getExtension(filePath) repoBugsUrl = pkg.bugs.url title = "Atom Beautify could not find a supported beautifier for this file" detail = """ diff --git a/src/beautifiers/uncrustify/index.coffee b/src/beautifiers/uncrustify/index.coffee index ffaa46a..e2c878c 100644 --- a/src/beautifiers/uncrustify/index.coffee +++ b/src/beautifiers/uncrustify/index.coffee @@ -46,7 +46,9 @@ module.exports = class Uncrustify extends Beautifier Arduino: true } - beautify: (text, language, options) -> + beautify: (text, language, options, context) -> + fileExtension = context.fileExtension + uncrustify = @exe("uncrustify") # console.log('uncrustify.beautify', language, options) return new @Promise((resolve, reject) -> @@ -99,9 +101,9 @@ module.exports = class Uncrustify extends Beautifier "-c" configPath "-f" - @tempFile("input", text) + @tempFile("input", text, fileExtension and ".#{fileExtension}") "-o" - outputFile = @tempFile("output", text) + outputFile = @tempFile("output", text, fileExtension and ".#{fileExtension}") "-l" lang ]) From cdccc2f36b5d03304927a84c07e182d22ea15952 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 20:33:37 -0300 Subject: [PATCH 54/58] See #1687. Add Docker volume support for all paths in Exectuable run arguments --- src/beautifiers/executable.coffee | 43 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 8874186..4afe944 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -130,14 +130,12 @@ class Executable run: (args, options = {}) -> @debug("Run: ", @cmd, args, options) { cwd, ignoreReturnCode, help, onStdin, returnStderr } = options - # Flatten args first - args = _.flatten(args) exeName = @cmd config = @getConfig() cwd ?= os.tmpDir() # Resolve executable and all args - Promise.all([@shellEnv(), Promise.all(args)]) + Promise.all([@shellEnv(), this.resolveArgs(args)]) .then(([env, args]) => @debug('exeName, args:', exeName, args) @@ -198,10 +196,15 @@ class Executable ) ) + resolveArgs: (args) -> + args = _.flatten(args) + Promise.all(args) + relativizePaths: (args) -> tmpDir = os.tmpDir() newArgs = args.map((arg) -> - isTmpFile = typeof arg is 'string' and not arg.includes(':') and path.isAbsolute(arg) and path.dirname(arg).startsWith(tmpDir) + isTmpFile = (typeof arg is 'string' and not arg.includes(':') and \ + path.isAbsolute(arg) and path.dirname(arg).startsWith(tmpDir)) if isTmpFile return path.relative(tmpDir, arg) return arg @@ -419,10 +422,32 @@ class HybridExecutable extends Executable runImage: (args, options) -> @debug("Run Docker executable: ", args, options) - { cwd } = options - pwd = fs.realpathSync(cwd or os.tmpDir()) - image = @dockerOptions.image - workingDir = @dockerOptions.workingDir - @docker.run(["run", "-v", "#{pwd}:#{workingDir}", "-w", workingDir, image, args], options) + this.resolveArgs(args) + .then((args) => + { cwd } = options + tmpDir = os.tmpDir() + pwd = fs.realpathSync(cwd or tmpDir) + image = @dockerOptions.image + workingDir = @dockerOptions.workingDir + + rootPath = '/mountedRoot' + newArgs = args.map((arg) -> + if (typeof arg is 'string' and not arg.includes(':') \ + and path.isAbsolute(arg) and not path.dirname(arg).startsWith(tmpDir)) + then path.join(rootPath, arg) else arg + ) + + @docker.run([ + "run", + "--volume", "#{pwd}:#{workingDir}", + "--volume", "#{path.resolve('/')}:#{rootPath}", + "--workdir", workingDir, + image, + newArgs + ], + options + ) + ) + module.exports = HybridExecutable From 6aee12ba805abc08624ee755c3314e0f7cde83e0 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 20:54:29 -0300 Subject: [PATCH 55/58] See #1687. Add Docker executable support for Sass-convert beautifier --- docs/options.md | 17 +++++++++++++++++ src/beautifiers/sass-convert.coffee | 18 +++++++++++++++--- src/options.json | 16 ++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/options.md b/docs/options.md index da88035..d49a2fc 100644 --- a/docs/options.md +++ b/docs/options.md @@ -334,6 +334,23 @@ Options for Rscript executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Rscript*" and change it to your desired configuration. +##### [SassConvert](#sassconvert) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for SassConvert executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*SassConvert*" and change it to your desired configuration. + ##### [Uncrustify](#uncrustify) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/src/beautifiers/sass-convert.coffee b/src/beautifiers/sass-convert.coffee index e53fa98..5a8fe68 100644 --- a/src/beautifiers/sass-convert.coffee +++ b/src/beautifiers/sass-convert.coffee @@ -4,7 +4,20 @@ Beautifier = require('./beautifier') module.exports = class SassConvert extends Beautifier name: "SassConvert" link: "http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax" - isPreInstalled: false + executables: [ + { + name: "SassConvert" + cmd: "sass-convert" + homepage: "http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax" + installation: "http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax" + version: { + parse: (text) -> text.match(/Sass (\d+\.\d+\.\d+)/)[1] + } + docker: { + image: "unibeautify/sass-convert" + } + } + ] options: # TODO: Add support for options @@ -14,8 +27,7 @@ module.exports = class SassConvert extends Beautifier beautify: (text, language, options, context) -> lang = language.toLowerCase() - - @run("sass-convert", [ + @exe("sass-convert").run([ @tempFile("input", text), "--from", lang, "--to", lang ]) diff --git a/src/options.json b/src/options.json index 8456f22..f70f67d 100644 --- a/src/options.json +++ b/src/options.json @@ -9306,6 +9306,22 @@ } } }, + "sass-convert": { + "key": "sass-convert", + "title": "SassConvert", + "type": "object", + "collapsed": true, + "description": "Options for SassConvert executable.", + "properties": { + "path": { + "key": "path", + "title": "Binary/Script Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"sass-convert\" executable's binary/script." + } + } + }, "rscript": { "key": "rscript", "title": "Rscript", From a83b1b83ae88b6451cb0d1df5976fb81a1fb6cc5 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 20:54:55 -0300 Subject: [PATCH 56/58] See #1687. Install Sass-convert and Uncrustify beautifiers via Docker for Linux Travis CI build --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea7e125..d86609b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -85,7 +85,7 @@ before_install: git clone --depth=1 https://github.com/Linuxbrew/brew.git ~/.linuxbrew || true; fi # Update Homebrew - - brew update + # - brew update - brew tap homebrew/dupes - brew tap homebrew/versions # Ruby language support @@ -94,7 +94,11 @@ before_install: - gem install htmlbeautifier - gem install puppet-lint # Sass language support - - gem install sass + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + gem install sass; + else + docker pull unibeautify/sass-convert + fi # Python language support - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo chmod 777 -R /opt/python; fi - pip install --upgrade pip @@ -103,7 +107,11 @@ before_install: # SQL language support - pip install --upgrade sqlparse # Java, C, C++, C#, Objective-C, D, Pawn, Vala - - brew install uncrustify + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + brew install uncrustify + else + docker pull unibeautify/uncrustify + fi # R - brew tap homebrew/science - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then From ed9c4580bf195ca4ef3284839103ff295c2ed2b9 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 20:59:43 -0300 Subject: [PATCH 57/58] See #1687. Fix typos in Travis CI config --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d86609b..95ba700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,7 +97,7 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then gem install sass; else - docker pull unibeautify/sass-convert + docker pull unibeautify/sass-convert; fi # Python language support - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo chmod 777 -R /opt/python; fi @@ -108,9 +108,9 @@ before_install: - pip install --upgrade sqlparse # Java, C, C++, C#, Objective-C, D, Pawn, Vala - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - brew install uncrustify + brew install uncrustify; else - docker pull unibeautify/uncrustify + docker pull unibeautify/uncrustify; fi # R - brew tap homebrew/science From a23be4d6d91bec223b644fb96eb3d88a9719a6e1 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 16 Jun 2017 22:34:21 -0300 Subject: [PATCH 58/58] Add more dependencies to next-update and greenkeep ignore list --- package.json | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a9e851e..5c9b1a3 100644 --- a/package.json +++ b/package.json @@ -413,14 +413,22 @@ "next-update": { "skip": [ "gherkin", - "expand-home-dir" + "expand-home-dir", + "typescript", + "typescript-formatter", + "tidy-markdown", + "underscore-plus" ] } }, "greenkeeper": { "ignore": [ "gherkin", - "expand-home-dir" + "expand-home-dir", + "typescript", + "typescript-formatter", + "tidy-markdown", + "underscore-plus" ] } -} \ No newline at end of file +}