diff --git a/coffeelint.json b/coffeelint.json index 6c330d5..43b8c39 100644 --- a/coffeelint.json +++ b/coffeelint.json @@ -1,7 +1,7 @@ { "indentation" : { "level" : "error", - "value" : 4 + "value" : 2 }, "line_endings" : { "value" : "unix", diff --git a/package.json b/package.json index e635e93..9902806 100644 --- a/package.json +++ b/package.json @@ -144,10 +144,12 @@ ], "devDependencies": { "coffee-script": "^1.9.3", + "coffeelint": "^1.10.1", "handlebars": "^3.0.3" }, "scripts": { "prepublish": "npm run docs", - "docs": "coffee docs/" + "docs": "coffee docs/", + "lint": "coffeelint src/" } } diff --git a/spec/atom-beautify-spec.coffee b/spec/atom-beautify-spec.coffee index f623dc5..3720b66 100644 --- a/spec/atom-beautify-spec.coffee +++ b/spec/atom-beautify-spec.coffee @@ -9,171 +9,171 @@ Beautifier = require "../src/beautifiers/beautifier" describe "Atom-Beautify", -> - beforeEach -> + beforeEach -> - # Activate package - waitsForPromise -> - activationPromise = atom.packages.activatePackage('atom-beautify') - # Force activate package - pack = atom.packages.getLoadedPackage("atom-beautify") - pack.activateNow() - # Change logger level - # atom.config.set('atom-beautify._loggerLevel', 'verbose') - # Return promise - return activationPromise + # Activate package + waitsForPromise -> + activationPromise = atom.packages.activatePackage('atom-beautify') + # Force activate package + pack = atom.packages.getLoadedPackage("atom-beautify") + pack.activateNow() + # Change logger level + # atom.config.set('atom-beautify._loggerLevel', 'verbose') + # Return promise + return activationPromise - describe "Beautifiers", -> + describe "Beautifiers", -> - describe "Beautifier::run", -> + describe "Beautifier::run", -> - beautifier = null + beautifier = null - beforeEach -> - beautifier = new Beautifier() + beforeEach -> + beautifier = new Beautifier() - it "should error when beautifier's program not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + it "should error when beautifier's program not found", -> + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - # waitsForRuns = (fn, message, timeout) -> - # isCompleted = false - # completed = -> - # console.log('completed') - # isCompleted = true - # runs -> - # console.log('runs') - # fn(completed) - # waitsFor(-> - # console.log('waitsFor', isCompleted) - # isCompleted - # , message, timeout) - # - # waitsForRuns((cb) -> - # console.log('waitsForRuns', cb) - # setTimeout(cb, 2000) - # , "Waiting for beautification to complete", 5000) + # waitsForRuns = (fn, message, timeout) -> + # isCompleted = false + # completed = -> + # console.log('completed') + # isCompleted = true + # runs -> + # console.log('runs') + # fn(completed) + # waitsFor(-> + # console.log('waitsFor', isCompleted) + # isCompleted + # , message, timeout) + # + # waitsForRuns((cb) -> + # console.log('waitsForRuns', cb) + # setTimeout(cb, 2000) + # , "Waiting for beautification to complete", 5000) - waitsForPromise shouldReject: true, -> - p = beautifier.run("program", []) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - cb = (v) -> - # console.log(v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true) - expect(v.code).toBe("CommandNotFound") - expect(v.description).toBe(undefined, \ - 'Error should not have a description.') - return v - p.then(cb, cb) - return p + waitsForPromise shouldReject: true, -> + p = beautifier.run("program", []) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + cb = (v) -> + # console.log(v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true) + expect(v.code).toBe("CommandNotFound") + expect(v.description).toBe(undefined, \ + 'Error should not have a description.') + return v + p.then(cb, cb) + return p - it "should error with help description \ + it "should error with help description \ when beautifier's program not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - waitsForPromise shouldReject: true, -> - help = { - link: "http://test.com" - program: "test-program" - pathOption: "Lang - Test Program Path" - } - p = beautifier.run("program", [], help: help) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - cb = (v) -> - # console.log(v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true) - expect(v.code).toBe("CommandNotFound") - expect(v.description).not.toBe(null) - expect(v.description.indexOf(help.link)).not.toBe(-1) - expect(v.description.indexOf(help.program)).not.toBe(-1) - expect(v.description - .indexOf(help.pathOption)).not.toBe(-1, \ - "Error should have a description.") - return v - p.then(cb, cb) - return p + waitsForPromise shouldReject: true, -> + help = { + link: "http://test.com" + program: "test-program" + pathOption: "Lang - Test Program Path" + } + p = beautifier.run("program", [], help: help) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + cb = (v) -> + # console.log(v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true) + expect(v.code).toBe("CommandNotFound") + expect(v.description).not.toBe(null) + expect(v.description.indexOf(help.link)).not.toBe(-1) + expect(v.description.indexOf(help.program)).not.toBe(-1) + expect(v.description + .indexOf(help.pathOption)).not.toBe(-1, \ + "Error should have a description.") + return v + p.then(cb, cb) + return p - it "should error with Windows-specific help description \ + it "should error with Windows-specific help description \ when beautifier's program not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - waitsForPromise shouldReject: true, -> - help = { - link: "http://test.com" - program: "test-program" - pathOption: "Lang - Test Program Path" - } - # Force to be Windows - beautifier.isWindows = true - terminal = 'CMD prompt' - whichCmd = "where.exe" - # Process - p = beautifier.run("program", [], help: help) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - cb = (v) -> - # console.log(v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true) - expect(v.code).toBe("CommandNotFound") - expect(v.description).not.toBe(null) - expect(v.description.indexOf(help.link)).not.toBe(-1) - expect(v.description.indexOf(help.program)).not.toBe(-1) - expect(v.description - .indexOf(help.pathOption)).not.toBe(-1, \ - "Error should have a description.") - expect(v.description - .indexOf(terminal)).not.toBe(-1, \ - "Error should have a description including \ + waitsForPromise shouldReject: true, -> + help = { + link: "http://test.com" + program: "test-program" + pathOption: "Lang - Test Program Path" + } + # Force to be Windows + beautifier.isWindows = true + terminal = 'CMD prompt' + whichCmd = "where.exe" + # Process + p = beautifier.run("program", [], help: help) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + cb = (v) -> + # console.log(v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true) + expect(v.code).toBe("CommandNotFound") + expect(v.description).not.toBe(null) + expect(v.description.indexOf(help.link)).not.toBe(-1) + expect(v.description.indexOf(help.program)).not.toBe(-1) + expect(v.description + .indexOf(help.pathOption)).not.toBe(-1, \ + "Error should have a description.") + expect(v.description + .indexOf(terminal)).not.toBe(-1, \ + "Error should have a description including \ '#{terminal}' in message.") - expect(v.description - .indexOf(whichCmd)).not.toBe(-1, \ - "Error should have a description including \ + expect(v.description + .indexOf(whichCmd)).not.toBe(-1, \ + "Error should have a description including \ '#{whichCmd}' in message.") - return v - p.then(cb, cb) - return p + return v + p.then(cb, cb) + return p - it "should error with Mac/Linux-specific help description \ + it "should error with Mac/Linux-specific help description \ when beautifier's program not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - waitsForPromise shouldReject: true, -> - help = { - link: "http://test.com" - program: "test-program" - pathOption: "Lang - Test Program Path" - } - # Force to be Mac/Linux (not Windows) - beautifier.isWindows = false - terminal = "Terminal" - whichCmd = "which" - # Process - p = beautifier.run("program", [], help: help) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - cb = (v) -> - # console.log(v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true) - expect(v.code).toBe("CommandNotFound") - expect(v.description).not.toBe(null) - expect(v.description.indexOf(help.link)).not.toBe(-1) - expect(v.description.indexOf(help.program)).not.toBe(-1) - expect(v.description - .indexOf(terminal)).not.toBe(-1, \ - "Error should have a description including \ + waitsForPromise shouldReject: true, -> + help = { + link: "http://test.com" + program: "test-program" + pathOption: "Lang - Test Program Path" + } + # Force to be Mac/Linux (not Windows) + beautifier.isWindows = false + terminal = "Terminal" + whichCmd = "which" + # Process + p = beautifier.run("program", [], help: help) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + cb = (v) -> + # console.log(v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true) + expect(v.code).toBe("CommandNotFound") + expect(v.description).not.toBe(null) + expect(v.description.indexOf(help.link)).not.toBe(-1) + expect(v.description.indexOf(help.program)).not.toBe(-1) + expect(v.description + .indexOf(terminal)).not.toBe(-1, \ + "Error should have a description including \ '#{terminal}' in message.") - expect(v.description - .indexOf(whichCmd)).not.toBe(-1, \ - "Error should have a description including \ + expect(v.description + .indexOf(whichCmd)).not.toBe(-1, \ + "Error should have a description including \ '#{whichCmd}' in message.") - return v - p.then(cb, cb) - return p \ No newline at end of file + return v + p.then(cb, cb) + return p diff --git a/spec/beautifier-php-cs-fixer-spec.coffee b/spec/beautifier-php-cs-fixer-spec.coffee index c512bee..42c58f0 100644 --- a/spec/beautifier-php-cs-fixer-spec.coffee +++ b/spec/beautifier-php-cs-fixer-spec.coffee @@ -9,128 +9,128 @@ path = require 'path' describe "PHP-CS-Fixer Beautifier", -> + beforeEach -> + + # Activate package + waitsForPromise -> + activationPromise = atom.packages.activatePackage('atom-beautify') + # Force activate package + pack = atom.packages.getLoadedPackage("atom-beautify") + pack.activateNow() + # Change logger level + # atom.config.set('atom-beautify._loggerLevel', 'verbose') + # Return promise + return activationPromise + + describe "Beautifier::beautify", -> + + beautifier = null + beforeEach -> + beautifier = new PHPCSFixer() + # console.log('new beautifier') - # Activate package - waitsForPromise -> - activationPromise = atom.packages.activatePackage('atom-beautify') - # Force activate package - pack = atom.packages.getLoadedPackage("atom-beautify") - pack.activateNow() - # Change logger level - # atom.config.set('atom-beautify._loggerLevel', 'verbose') - # Return promise - return activationPromise + OSSpecificSpecs = -> + text = "" - describe "Beautifier::beautify", -> + it "should error when beautifier's program not found", -> + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - beautifier = null + waitsForPromise shouldReject: true, -> + language = "PHP" + options = { + fixers: "" + levels: "" + } + # Mock PATH + beautifier.getShellEnvironment = -> Promise.resolve({ + PATH: '' + }) + # + p = beautifier.beautify(text, language, options) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + cb = (v) -> + # console.log(v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true, \ + "Expected '#{v}' to be instance of Error") + expect(v.code).toBe("CommandNotFound", \ + "Expected to be CommandNotFound") + return v + p.then(cb, cb) + return p - beforeEach -> - beautifier = new PHPCSFixer() - # console.log('new beautifier') + failWhichProgram = (failingProgram) -> + it "should error when '#{failingProgram}' not found", -> + expect(beautifier).not.toBe(null) + expect(beautifier instanceof Beautifier).toBe(true) - OSSpecificSpecs = -> - text = "" + if not beautifier.isWindows and failingProgram is "php" + # Only applicable on Windows + return - it "should error when beautifier's program not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + waitsForPromise shouldReject: true, -> + language = "PHP" + options = { + fixers: "" + levels: "" + } + cb = (v) -> + # console.log('cb value', v) + expect(v).not.toBe(null) + expect(v instanceof Error).toBe(true, \ + "Expected '#{v}' to be instance of Error") + expect(v.code).toBe("CommandNotFound", \ + "Expected to be CommandNotFound") + expect(v.file).toBe(failingProgram) + return v + # which = beautifier.which.bind(beautifier) + beautifier.which = (exe, options) -> + return beautifier.Promise.resolve(null) \ + if not exe? + if exe is failingProgram + beautifier.Promise.resolve(failingProgram) + else + # which(exe, options) + # console.log('fake exe path', exe) + beautifier.Promise.resolve("/#{exe}") - waitsForPromise shouldReject: true, -> - language = "PHP" - options = { - fixers: "" - levels: "" - } - # Mock PATH - beautifier.getShellEnvironment = -> Promise.resolve({ - PATH: '' - }) - # - p = beautifier.beautify(text, language, options) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - cb = (v) -> - # console.log(v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true, \ - "Expected '#{v}' to be instance of Error") - expect(v.code).toBe("CommandNotFound", \ - "Expected to be CommandNotFound") - return v - p.then(cb, cb) - return p + oldSpawn = beautifier.spawn.bind(beautifier) + beautifier.spawn = (exe, args, options) -> + # console.log('spawn', exe, args, options) + if exe is failingProgram + er = new Error('ENOENT') + er.code = 'ENOENT' + return beautifier.Promise.reject(er) + else + return beautifier.Promise.resolve({ + returnCode: 0, + stdout: 'stdout', + stderr: '' + }) + p = beautifier.beautify(text, language, options) + expect(p).not.toBe(null) + expect(p instanceof beautifier.Promise).toBe(true) + p.then(cb, cb) + return p - failWhichProgram = (failingProgram) -> - it "should error when '#{failingProgram}' not found", -> - expect(beautifier).not.toBe(null) - expect(beautifier instanceof Beautifier).toBe(true) + failWhichProgram('php') + failWhichProgram('php-cs-fixer') - if not beautifier.isWindows and failingProgram is "php" - # Only applicable on Windows - return + describe "Mac/Linux", -> - waitsForPromise shouldReject: true, -> - language = "PHP" - options = { - fixers: "" - levels: "" - } - cb = (v) -> - # console.log('cb value', v) - expect(v).not.toBe(null) - expect(v instanceof Error).toBe(true, \ - "Expected '#{v}' to be instance of Error") - expect(v.code).toBe("CommandNotFound", \ - "Expected to be CommandNotFound") - expect(v.file).toBe(failingProgram) - return v - # which = beautifier.which.bind(beautifier) - beautifier.which = (exe, options) -> - return beautifier.Promise.resolve(null) \ - if not exe? - if exe is failingProgram - beautifier.Promise.resolve(failingProgram) - else - # which(exe, options) - # console.log('fake exe path', exe) - beautifier.Promise.resolve("/#{exe}") + beforeEach -> + # console.log('mac/linx') + beautifier.isWindows = false - oldSpawn = beautifier.spawn.bind(beautifier) - beautifier.spawn = (exe, args, options) -> - # console.log('spawn', exe, args, options) - if exe is failingProgram - er = new Error('ENOENT') - er.code = 'ENOENT' - return beautifier.Promise.reject(er) - else - return beautifier.Promise.resolve({ - returnCode: 0, - stdout: 'stdout', - stderr: '' - }) - p = beautifier.beautify(text, language, options) - expect(p).not.toBe(null) - expect(p instanceof beautifier.Promise).toBe(true) - p.then(cb, cb) - return p + do OSSpecificSpecs - failWhichProgram('php') - failWhichProgram('php-cs-fixer') + describe "Windows", -> - describe "Mac/Linux", -> + beforeEach -> + # console.log('windows') + beautifier.isWindows = true - beforeEach -> - # console.log('mac/linx') - beautifier.isWindows = false - - do OSSpecificSpecs - - describe "Windows", -> - - beforeEach -> - # console.log('windows') - beautifier.isWindows = true - - do OSSpecificSpecs + do OSSpecificSpecs diff --git a/spec/beautify-languages-spec.coffee b/spec/beautify-languages-spec.coffee index c23f51a..88bcfb6 100644 --- a/spec/beautify-languages-spec.coffee +++ b/spec/beautify-languages-spec.coffee @@ -25,8 +25,8 @@ describe "BeautifyLanguages", -> ] # All Atom packages that Atom Beautify is dependent on dependentPackages = [ - 'autocomplete-plus' - 'linter' + 'autocomplete-plus' + # 'linter' # 'atom-typescript' # it logs too much... ] # Add language packages to dependentPackages @@ -43,28 +43,28 @@ describe "BeautifyLanguages", -> # Activate package waitsForPromise -> - activationPromise = atom.packages.activatePackage('atom-beautify') - # Force activate package - pack = atom.packages.getLoadedPackage("atom-beautify") - pack.activateNow() - # Check if Windows - isWindows = process.platform is 'win32' or - process.env.OSTYPE is 'cygwin' or - process.env.OSTYPE is 'msys' - # Need more debugging on Windows - if isWindows - # Change logger level - atom.config.set('atom-beautify._loggerLevel', 'verbose') - # Return promise - return activationPromise + activationPromise = atom.packages.activatePackage('atom-beautify') + # Force activate package + pack = atom.packages.getLoadedPackage("atom-beautify") + pack.activateNow() + # Check if Windows + isWindows = process.platform is 'win32' or + process.env.OSTYPE is 'cygwin' or + process.env.OSTYPE is 'msys' + # Need more debugging on Windows + if isWindows + # Change logger level + atom.config.set('atom-beautify._loggerLevel', 'verbose') + # Return promise + return activationPromise # Set Uncrustify config path # uncrustifyConfigPath = path.resolve(__dirname, "../examples/nested-jsbeautifyrc/uncrustify.cfg") # uncrustifyLangs = ["c", "cpp", "objectivec", "cs", "d", "java", "pawn", "vala"] # for lang in uncrustifyLangs # do (lang) -> - # atom.config.set("atom-beautify.#{lang}_configPath", uncrustifyConfigPath) - # expect(atom.config.get("atom-beautify.#{lang}_configPath")).toEqual("TEST") + # atom.config.set("atom-beautify.#{lang}_configPath", uncrustifyConfigPath) + # expect(atom.config.get("atom-beautify.#{lang}_configPath")).toEqual("TEST") ### Directory structure: @@ -103,13 +103,13 @@ describe "BeautifyLanguages", -> originalDir = path.resolve(testsDir, "original") if not fs.existsSync(originalDir) console.warn("Directory for test originals/inputs not found." + - " Making it at #{originalDir}.") + " Making it at #{originalDir}.") fs.mkdirSync(originalDir) # Expected expectedDir = path.resolve(testsDir, "expected") if not fs.existsSync(expectedDir) console.warn("Directory for test expected/results not found." + - "Making it at #{expectedDir}.") + "Making it at #{expectedDir}.") fs.mkdirSync(expectedDir) # Language group tests @@ -136,7 +136,7 @@ describe "BeautifyLanguages", -> # Check if there is a matching expected test resut if not fs.existsSync(expectedTestPath) throw new Error("No matching expected test result found for '#{testName}' " + - "at '#{expectedTestPath}'.") + "at '#{expectedTestPath}'.") # err = fs.writeFileSync(expectedTestPath, originalContents) # throw err if err # Get contents of expected test file diff --git a/src/.jsbeautifyrc b/src/.jsbeautifyrc index 9a59841..507cb2a 100644 --- a/src/.jsbeautifyrc +++ b/src/.jsbeautifyrc @@ -1,5 +1,5 @@ { - "indent_size": 4, + "indent_size": 2, "indent_char": " ", "indent_level": 0, "indent_with_tabs": false, diff --git a/src/beautifiers/autopep8.coffee b/src/beautifiers/autopep8.coffee index 352def3..37310d8 100644 --- a/src/beautifiers/autopep8.coffee +++ b/src/beautifiers/autopep8.coffee @@ -7,19 +7,19 @@ Beautifier = require('./beautifier') module.exports = class autopep8 extends Beautifier - name: "autopep8" + name: "autopep8" - options: { - Python: true - } + options: { + Python: true + } - beautify: (text, language, options) -> - # console.log('autopep8', options, text, language) - @run("autopep8", [ - @tempFile("input", text) - ["--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" - }) + beautify: (text, language, options) -> + # console.log('autopep8', options, text, language) + @run("autopep8", [ + @tempFile("input", text) + ["--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" + }) diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 105be75..d9bfaaf 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -9,193 +9,193 @@ which = require('which') module.exports = class Beautifier - ### - Promise - ### - Promise: Promise + ### + Promise + ### + Promise: Promise - ### - Name of Beautifier - ### - name: 'Beautifier' + ### + Name of Beautifier + ### + name: 'Beautifier' - ### - Supported Options + ### + Supported Options + + Enable options for supported languages. + - : + - :: + - :: + - :: + - :: + + ### + options: {} - Enable options for supported languages. - - : - - :: - - :: - - :: - - :: + ### + Supported languages by this Beautifier + + Extracted from the keys of the `options` field. + ### + languages: null - ### - options: {} + ### + Beautify text + + Override this method in subclasses + ### + beautify: null - ### - Supported languages by this Beautifier + ### + Show deprecation warning to user. + ### + deprecate: (warning) -> + atom.notifications?.addWarning(warning) - Extracted from the keys of the `options` field. - ### - languages: null - - ### - Beautify text - - Override this method in subclasses - ### - beautify: null - - ### - Show deprecation warning to user. - ### - deprecate: (warning) -> - atom.notifications?.addWarning(warning) - - ### - Create temporary file - ### - tempFile: (name = "atom-beautify-temp", contents = "") -> - return new Promise((resolve, reject) => - # create temp file - temp.open(name, (err, info) => - @debug('tempFile', name, err, info) - return reject(err) if err - fs.write(info.fd, contents, (err) => - return reject(err) if err - fs.close(info.fd, (err) => - return reject(err) if err - resolve(info.path) - ) - ) - ) + ### + Create temporary file + ### + tempFile: (name = "atom-beautify-temp", contents = "") -> + return new Promise((resolve, reject) => + # create temp file + temp.open(name, (err, info) => + @debug('tempFile', name, err, info) + return reject(err) if err + fs.write(info.fd, contents, (err) => + return reject(err) if err + fs.close(info.fd, (err) => + return reject(err) if err + resolve(info.path) + ) ) + ) + ) - ### - Read file - ### - readFile: (filePath) -> - Promise.resolve(filePath) - .then((filePath) -> - return readFile(filePath, "utf8") + ### + Read file + ### + readFile: (filePath) -> + Promise.resolve(filePath) + .then((filePath) -> + return readFile(filePath, "utf8") + ) + + ### + 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. + + 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 = {}) -> + # Get PATH and other environment variables + @getShellEnvironment() + .then((env) -> + new Promise((resolve, reject) -> + options.path ?= env.PATH + which(exe, options, (err, path) -> + resolve(exe) if err + resolve(path) ) + ) + ) - ### - If platform is Windows - ### - isWindows: do -> - return /^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. - - 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 = {}) -> - # Get PATH and other environment variables - @getShellEnvironment() - .then((env) -> - new Promise((resolve, reject) -> - options.path ?= env.PATH - 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}'. \ + ### + 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 \ + 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 \ + # 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/\ + # 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/\ + docsLink = "https://github.com/Glavin001/\ atom-beautify/tree/master/docs" - helpStr += "Your program is properly installed if running \ + helpStr += "Your program is properly installed if running \ '#{if @isWindows then 'where.exe' \ else 'which'} #{exe}' \ in your #{if @isWindows then 'CMD prompt' \ @@ -218,121 +218,121 @@ module.exports = class Beautifier 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 + er.description = helpStr + else #if typeof help is "string" + er.description = help + return er - ### - Run command-line interface command - ### - run: (executable, args, {ignoreReturnCode, help} = {}) -> - # 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) - return new Promise((resolve, reject) => - # Remove undefined/null values - args = _.without(args, undefined) - args = _.without(args, null) - # Get PATH and other environment variables - Promise.all([@getShellEnvironment(), @which(exeName)]) - .then(([env, exePath]) => - @debug('exePath, env:', exePath, env) - exe = exePath ? exeName - # Spawn command - options = { - env: env - } - cmd = @spawn(exe, args, options) - .then(({returnCode, stdout, stderr}) -> - # If return code is not 0 then error occured - if not ignoreReturnCode and returnCode isnt 0 - reject(stderr) - else - resolve(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' - reject(@commandNotFoundError(exeName, help)) - else - # continue as normal error - reject(err) - ) - ) + ### + Run command-line interface command + ### + run: (executable, args, {ignoreReturnCode, help} = {}) -> + # 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) + return new Promise((resolve, reject) => + # Remove undefined/null values + args = _.without(args, undefined) + args = _.without(args, null) + # Get PATH and other environment variables + Promise.all([@getShellEnvironment(), @which(exeName)]) + .then(([env, exePath]) => + @debug('exePath, env:', exePath, env) + exe = exePath ? exeName + # Spawn command + options = { + env: env + } + cmd = @spawn(exe, args, options) + .then(({returnCode, stdout, stderr}) -> + # If return code is not 0 then error occured + if not ignoreReturnCode and returnCode isnt 0 + reject(stderr) + else + resolve(stdout) ) - ) - - ### - Spawn - ### - spawn: (exe, args, options) -> - return new Promise((resolve, reject) => - @debug('spawn', exe, args) - cmd = spawn(exe, args, options) - # add a 'data' event listener for the spawn instance - stdout = "" - stderr = "" - cmd.stdout.on('data', (data) -> stdout += data ) - cmd.stderr.on('data', (data) -> stderr += data ) - # when the spawn child process exits, - # check if there were any errors and - # close the writeable stream - cmd.on('exit', (returnCode) => - @debug('spawn done', returnCode, stderr, stdout) - resolve({returnCode, stdout, stderr}) - ) - cmd.on('error', (err) => - @debug('error', err) + .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' + reject(@commandNotFoundError(exeName, help)) + else + # continue as normal error reject(err) ) ) + ) + ) - ### - Logger instance - ### - logger: null - ### - Initialize and configure Logger - ### - setupLogger: -> - @logger = require('../logger')(__filename) - # @verbose(@logger) - # Merge logger methods into beautifier class - for key, method of @logger - # @verbose(key, method) - @[key] = method - @verbose("Beautifier logger has been initialized.") + ### + Spawn + ### + spawn: (exe, args, options) -> + return new Promise((resolve, reject) => + @debug('spawn', exe, args) + cmd = spawn(exe, args, options) + # add a 'data' event listener for the spawn instance + stdout = "" + stderr = "" + cmd.stdout.on('data', (data) -> stdout += data ) + cmd.stderr.on('data', (data) -> stderr += data ) + # when the spawn child process exits, + # check if there were any errors and + # close the writeable stream + cmd.on('exit', (returnCode) => + @debug('spawn done', returnCode, stderr, stdout) + resolve({returnCode, stdout, stderr}) + ) + cmd.on('error', (err) => + @debug('error', err) + reject(err) + ) + ) - ### - Constructor to setup beautifer - ### - constructor: () -> - # Setup logger - @setupLogger() - # Handle global options - if @options._? - globalOptions = @options._ - delete @options._ - # Only merge if globalOptions is an object - if typeof globalOptions is "object" - # Iterate over all supported languages - for lang, options of @options - # - if typeof options is "boolean" - if options is true - @options[lang] = globalOptions - else if typeof options is "object" - @options[lang] = _.merge(globalOptions, options) - else - @warn("Unsupported options type #{typeof options} for language #{lang}: "+ options) - @verbose("Options for #{@name}:", @options) - # Set supported languages - @languages = _.keys(@options) + ### + Logger instance + ### + logger: null + ### + Initialize and configure Logger + ### + setupLogger: -> + @logger = require('../logger')(__filename) + # @verbose(@logger) + # Merge logger methods into beautifier class + for key, method of @logger + # @verbose(key, method) + @[key] = method + @verbose("Beautifier logger has been initialized.") + + ### + Constructor to setup beautifer + ### + constructor: () -> + # Setup logger + @setupLogger() + # Handle global options + if @options._? + globalOptions = @options._ + delete @options._ + # Only merge if globalOptions is an object + if typeof globalOptions is "object" + # Iterate over all supported languages + for lang, options of @options + # + if typeof options is "boolean" + if options is true + @options[lang] = globalOptions + else if typeof options is "object" + @options[lang] = _.merge(globalOptions, options) + else + @warn("Unsupported options type #{typeof options} for language #{lang}: "+ options) + @verbose("Options for #{@name}:", @options) + # Set supported languages + @languages = _.keys(@options) diff --git a/src/beautifiers/coffee-fmt.coffee b/src/beautifiers/coffee-fmt.coffee index 21129b8..094d4ae 100644 --- a/src/beautifiers/coffee-fmt.coffee +++ b/src/beautifiers/coffee-fmt.coffee @@ -2,29 +2,31 @@ Beautifier = require('./beautifier') module.exports = class CoffeeFmt extends Beautifier - name: "coffee-fmt" + name: "coffee-fmt" - options: { - # Apply language-specific options - CoffeeScript: - tab: ["indent_size", "indent_char", "indent_with_tabs", (indentSize, indentChar, indentWithTabs) -> - return "\t" if indentWithTabs - Array(indentSize+1).join(indentChar) - ] - } + options: { + # Apply language-specific options + CoffeeScript: + tab: ["indent_size", \ + "indent_char", "indent_with_tabs", \ + (indentSize, indentChar, indentWithTabs) -> + return "\t" if indentWithTabs + Array(indentSize+1).join(indentChar) + ] + } - beautify: (text, language, options) -> - @verbose('beautify', language, options) - return new @Promise((resolve, reject) -> - # Add newLine option - options.newLine = "\n" - # Require - fmt = require('coffee-fmt') - # Format! - try - results = fmt.format(text, options) - # Return beautified CoffeeScript code - resolve(results) - catch e - reject(e) - ) + beautify: (text, language, options) -> + @verbose('beautify', language, options) + return new @Promise((resolve, reject) -> + # Add newLine option + options.newLine = "\n" + # Require + fmt = require('coffee-fmt') + # Format! + try + results = fmt.format(text, options) + # Return beautified CoffeeScript code + resolve(results) + catch e + reject(e) + ) diff --git a/src/beautifiers/coffee-formatter.coffee b/src/beautifiers/coffee-formatter.coffee index aec4048..77d15d2 100644 --- a/src/beautifiers/coffee-formatter.coffee +++ b/src/beautifiers/coffee-formatter.coffee @@ -3,30 +3,30 @@ Beautifier = require('./beautifier') module.exports = class CoffeeFormatter extends Beautifier - name: "Coffee Formatter" + name: "Coffee Formatter" - options: { - CoffeeScript: true - } + options: { + CoffeeScript: true + } - beautify: (text, language, options) -> + beautify: (text, language, options) -> - return new @Promise((resolve, reject) -> + return new @Promise((resolve, reject) -> - CF = require("coffee-formatter") - lines = text.split("\n") - resultArr = [] - i = 0 - len = lines.length + CF = require("coffee-formatter") + lines = text.split("\n") + resultArr = [] + i = 0 + len = lines.length - while i < len - curr = lines[i] - p = CF.formatTwoSpaceOperator(curr) - p = CF.formatOneSpaceOperator(p) - p = CF.shortenSpaces(p) - resultArr.push p - i++ - result = resultArr.join("\n") - resolve result + while i < len + curr = lines[i] + p = CF.formatTwoSpaceOperator(curr) + p = CF.formatOneSpaceOperator(p) + p = CF.shortenSpaces(p) + resultArr.push p + i++ + result = resultArr.join("\n") + resolve result - ) + ) diff --git a/src/beautifiers/csscomb.coffee b/src/beautifiers/csscomb.coffee index 560e873..7519fe0 100644 --- a/src/beautifiers/csscomb.coffee +++ b/src/beautifiers/csscomb.coffee @@ -2,50 +2,50 @@ Beautifier = require('./beautifier') module.exports = class JSBeautify extends Beautifier - name: "CSScomb" + name: "CSScomb" - options: { - # TODO: Add support for options - CSS: false - LESS: false - Sass: false - SCSS: false - } + options: { + # TODO: Add support for options + CSS: false + LESS: false + Sass: false + SCSS: false + } - beautify: (text, language, options) -> - return new @Promise((resolve, reject) -> - # console.log('CSSComb', text, language, options) + beautify: (text, language, options) -> + return new @Promise((resolve, reject) -> + # console.log('CSSComb', text, language, options) - # Require - Comb = require('csscomb') + # Require + Comb = require('csscomb') - config = null - try - # Load from Project's .csscomb.json - projectConfigPath = atom.project.getDirectories()?[0]?.resolve('.csscomb.json') - config = require(projectConfigPath) # Will throw error if does not exist - catch e - # Fallback to csscomb - config = Comb.getConfig('csscomb') - # TODO: Add support to select CSSComb predefined config's name - # console.log('config', config, options) - # Configure - comb = new Comb(config) + config = null + try + # Load from Project's .csscomb.json + projectConfigPath = atom.project.getDirectories()?[0]?.resolve('.csscomb.json') + config = require(projectConfigPath) # Will throw error if does not exist + catch e + # Fallback to csscomb + config = Comb.getConfig('csscomb') + # TODO: Add support to select CSSComb predefined config's name + # console.log('config', config, options) + # Configure + comb = new Comb(config) - # Determine syntax from Language - syntax = "css" # Default - switch language - when "LESS" - syntax = "less" - when "SCSS" - syntax = "scss" - when "Sass" - syntax = "sass" - # Use - processedCSS = comb.processString(text, { - syntax: syntax - }) - # console.log('processedCSS', processedCSS, syntax) + # Determine syntax from Language + syntax = "css" # Default + switch language + when "LESS" + syntax = "less" + when "SCSS" + syntax = "scss" + when "Sass" + syntax = "sass" + # Use + processedCSS = comb.processString(text, { + syntax: syntax + }) + # console.log('processedCSS', processedCSS, syntax) - resolve(processedCSS) - ) + resolve(processedCSS) + ) diff --git a/src/beautifiers/fortran-beautifier/index.coffee b/src/beautifiers/fortran-beautifier/index.coffee index fcada97..1fa9f25 100644 --- a/src/beautifiers/fortran-beautifier/index.coffee +++ b/src/beautifiers/fortran-beautifier/index.coffee @@ -7,41 +7,41 @@ Beautifier = require('../beautifier') path = require("path") module.exports = class FortranBeautifier extends Beautifier - name: "Fortran Beautifier" + name: "Fortran Beautifier" - options: { - Fortran: true - } + options: { + Fortran: true + } - beautify: (text, language, options) -> - @debug('fortran-beautifier', options) + beautify: (text, language, options) -> + @debug('fortran-beautifier', options) - emacs_path = options.emacs_path - emacs_script_path = options.emacs_script_path + emacs_path = options.emacs_path + emacs_script_path = options.emacs_script_path - if not emacs_script_path - emacs_script_path = path.resolve(__dirname, "emacs-fortran-formating-script.lisp") + if not emacs_script_path + emacs_script_path = path.resolve(__dirname, "emacs-fortran-formating-script.lisp") - @debug('fortran-beautifier', 'emacs script path: ' + emacs_script_path) + @debug('fortran-beautifier', 'emacs script path: ' + emacs_script_path) - args = [ - '--batch' - '-l' - emacs_script_path - '-f' - 'f90-batch-indent-region' - tempFile = @tempFile("temp", text) - ] + args = [ + '--batch' + '-l' + emacs_script_path + '-f' + 'f90-batch-indent-region' + tempFile = @tempFile("temp", text) + ] - if emacs_path - args.unshift("#{emacs_path}") + if emacs_path + args.unshift("#{emacs_path}") - @run("python", args, {ignoreReturnCode: true}) - .then(=> - @readFile(tempFile) - ) - else - @run("emacs", args, {ignoreReturnCode: true}) - .then(=> - @readFile(tempFile) - ) + @run("python", args, {ignoreReturnCode: true}) + .then(=> + @readFile(tempFile) + ) + else + @run("emacs", args, {ignoreReturnCode: true}) + .then(=> + @readFile(tempFile) + ) diff --git a/src/beautifiers/gofmt.coffee b/src/beautifiers/gofmt.coffee index 41716f7..b74240f 100644 --- a/src/beautifiers/gofmt.coffee +++ b/src/beautifiers/gofmt.coffee @@ -6,13 +6,13 @@ Requires http://golang.org/cmd/gofmt/ Beautifier = require('./beautifier') module.exports = class gofmt extends Beautifier - name: "gofmt" + name: "gofmt" - options: { - Go: true - } + options: { + Go: true + } - beautify: (text, language, options) -> - @run("gofmt", [ - @tempFile("input", text) - ]) + beautify: (text, language, options) -> + @run("gofmt", [ + @tempFile("input", text) + ]) diff --git a/src/beautifiers/htmlbeautifier.coffee b/src/beautifiers/htmlbeautifier.coffee index 3ccfa9a..95512e7 100644 --- a/src/beautifiers/htmlbeautifier.coffee +++ b/src/beautifiers/htmlbeautifier.coffee @@ -6,18 +6,18 @@ Requires https://github.com/threedaymonk/htmlbeautifier Beautifier = require('./beautifier') module.exports = class HTMLBeautifier extends Beautifier - name: "HTML Beautifier" - options: { - ERB: - indent_size: true - } + name: "HTML Beautifier" + options: { + ERB: + indent_size: true + } - beautify: (text, language, options) -> - console.log('erb', options) - @run("htmlbeautifier", [ - "--tab-stops", options.indent_size - tempFile = @tempFile("temp", text) - ]) - .then(=> - @readFile(tempFile) - ) + beautify: (text, language, options) -> + console.log('erb', options) + @run("htmlbeautifier", [ + "--tab-stops", options.indent_size + tempFile = @tempFile("temp", text) + ]) + .then(=> + @readFile(tempFile) + ) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index e5a3fab..49e02b5 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -17,7 +17,7 @@ editorconfig = null # Misc {allowUnsafeEval} = require 'loophole' allowUnsafeEval -> - Analytics = require("analytics-node") + Analytics = require("analytics-node") pkg = require("../../package.json") # Analytics @@ -27,779 +27,779 @@ analyticsWriteKey = "u3c26xkae8" Register all supported beautifiers ### module.exports = class Beautifiers extends EventEmitter - ### - List of beautifier names + ### + List of beautifier names + + To register a beautifier add its name here + ### + beautifierNames : [ + 'uncrustify' + 'autopep8' + 'coffee-formatter' + 'coffee-fmt' + 'htmlbeautifier' + 'csscomb' + 'gofmt' + 'fortran-beautifier' + 'js-beautify' + 'perltidy' + 'php-cs-fixer' + 'prettydiff' + 'rubocop' + 'ruby-beautify' + 'rustfmt' + 'sqlformat' + 'tidy-markdown' + 'typescript-formatter' + ] + + ### + List of loaded beautifiers + + Autogenerated in `constructor` from `beautifierNames` + ### + beautifiers : null + + ### + All beautifier options + + Autogenerated in `constructor` + ### + options : null + + ### + Languages + ### + languages : new Languages() + + ### + Constructor + ### + constructor : -> + + # Load beautifiers + @beautifiers = _.map( @beautifierNames, (name) -> + Beautifier = require("./#{name}") + new Beautifier() + ) + + + # Build options from @beautifiers and @languages + @options = @buildOptionsForBeautifiers( @beautifiers) + + + buildOptionsForBeautifiers : (beautifiers) -> - To register a beautifier add its name here - ### - beautifierNames : [ - 'uncrustify' - 'autopep8' - 'coffee-formatter' - 'coffee-fmt' - 'htmlbeautifier' - 'csscomb' - 'gofmt' - 'fortran-beautifier' - 'js-beautify' - 'perltidy' - 'php-cs-fixer' - 'prettydiff' - 'rubocop' - 'ruby-beautify' - 'rustfmt' - 'sqlformat' - 'tidy-markdown' - 'typescript-formatter' - ] + # Get all Options for Languages + langOptions = {} + languages = {} # Hash map of languages with their names + for lang in @languages.languages + langOptions[lang.name] ?= {} + languages[lang.name] ?= lang + options = langOptions[lang.name] - ### - List of loaded beautifiers - Autogenerated in `constructor` from `beautifierNames` - ### - beautifiers : null + # Init field for supported beautifiers + lang.beautifiers = [] - ### - All beautifier options - Autogenerated in `constructor` - ### - options : null + # Process all language options + for field, op of lang.options + if not op.title? + op.title = _plus.uncamelcase(field).split('.') + .map(_plus.capitalize).join(' ') + op.title = "#{lang.name} - #{op.title}" - ### - Languages - ### - languages : new Languages() - ### - Constructor - ### - constructor : -> + # Init field for supported beautifiers + op.beautifiers = [] - # Load beautifiers - @beautifiers = _.map( @beautifierNames, (name) -> - Beautifier = require("./#{name}") - new Beautifier() - ) + # Add option + options[field] = op - # Build options from @beautifiers and @languages - @options = @buildOptionsForBeautifiers( @beautifiers) + # Find supported beautifiers for each language + for beautifier in beautifiers + beautifierName = beautifier.name - buildOptionsForBeautifiers : (beautifiers) -> + # Iterate over supported languages + for languageName, options of beautifier.options + laOp = langOptions[languageName] - # Get all Options for Languages - langOptions = {} - languages = {} # Hash map of languages with their names - for lang in @languages.languages - langOptions[lang.name] ?= {} - languages[lang.name] ?= lang - options = langOptions[lang.name] + # Is a valid Language name + if typeof options is "boolean" - # Init field for supported beautifiers - lang.beautifiers = [] + # Enable / disable all options + # Add Beautifier support to Language + languages[languageName]?.beautifiers.push(beautifierName) - # Process all language options - for field, op of lang.options - if not op.title? - op.title = _plus.uncamelcase(field).split('.') - .map(_plus.capitalize).join(' ') - op.title = "#{lang.name} - #{op.title}" + # Check for beautifier's options support + if options is true + # Beautifier supports all options for this language + if laOp - # Init field for supported beautifiers - op.beautifiers = [] + # logger.verbose('add supported beautifier', languageName, beautifierName) + for field, op of laOp + op.beautifiers.push(beautifierName) + else + # Supports language but no options specifically + logger.warn("Could not find options for language: #{languageName}") + else if typeof options is "object" - # Add option - options[field] = op + # Iterate over beautifier's options for this language + for field, op of options + if typeof op is "boolean" - # Find supported beautifiers for each language - for beautifier in beautifiers - beautifierName = beautifier.name + # Transformation + if op is true + languages[languageName]?.beautifiers.push(beautifierName) + laOp?[field]?.beautifiers.push(beautifierName) + else if typeof op is "string" + # Rename + # logger.verbose('support option with rename:', field, op, languageName, beautifierName, langOptions) + languages[languageName]?.beautifiers.push(beautifierName) + laOp?[op]?.beautifiers.push(beautifierName) + else if typeof op is "function" - # Iterate over supported languages - for languageName, options of beautifier.options - laOp = langOptions[languageName] + # Transformation + languages[languageName]?.beautifiers.push(beautifierName) + laOp?[field]?.beautifiers.push(beautifierName) + else if _.isArray(op) + # Complex Function + [fields..., fn] = op - # Is a valid Language name - if typeof options is "boolean" - # Enable / disable all options - # Add Beautifier support to Language - languages[languageName]?.beautifiers.push(beautifierName) + # Add beautifier support to all required fields + languages[languageName]?.beautifiers.push(beautifierName) + for f in fields + # Add beautifier to required field + laOp?[f]?.beautifiers.push(beautifierName) + else - # Check for beautifier's options support - if options is true + # Unsupported + logger.warn("Unsupported option:", beautifierName, languageName, field, op, langOptions) - # Beautifier supports all options for this language - if laOp + # Prefix language's options with namespace + for langName, ops of langOptions - # logger.verbose('add supported beautifier', languageName, beautifierName) - for field, op of laOp - op.beautifiers.push(beautifierName) - else + # Get language with name + lang = languages[langName] - # Supports language but no options specifically - logger.warn("Could not find options for language: #{languageName}") - else if typeof options is "object" - # Iterate over beautifier's options for this language - for field, op of options - if typeof op is "boolean" + # Use the namespace from language as key prefix + prefix = lang.namespace - # Transformation - if op is true - languages[languageName]?.beautifiers.push(beautifierName) - laOp?[field]?.beautifiers.push(beautifierName) - else if typeof op is "string" - # Rename - # logger.verbose('support option with rename:', field, op, languageName, beautifierName, langOptions) - languages[languageName]?.beautifiers.push(beautifierName) - laOp?[op]?.beautifiers.push(beautifierName) - else if typeof op is "function" + # logger.verbose(langName, lang, prefix, ops) + # Iterate over all language options and rename fields + for field, op of ops - # Transformation - languages[languageName]?.beautifiers.push(beautifierName) - laOp?[field]?.beautifiers.push(beautifierName) - else if _.isArray(op) + # Rename field + delete ops[field] + ops["#{prefix}_#{field}"] = op - # Complex Function - [fields..., fn] = op + # Flatten Options per language to array of all options + allOptions = _.values(langOptions) - # Add beautifier support to all required fields - languages[languageName]?.beautifiers.push(beautifierName) - for f in fields + # logger.verbose('allOptions', allOptions) + # Flatten array of objects to single object for options + flatOptions = _.reduce(allOptions, ((result, languageOptions, language) -> - # Add beautifier to required field - laOp?[f]?.beautifiers.push(beautifierName) - else + # Iterate over fields (keys) in Language's Options + # and merge them into single result + # logger.verbose('language options', language, languageOptions, result) + return _.reduce(languageOptions, ((result, optionDef, optionName) -> - # Unsupported - logger.warn("Unsupported option:", beautifierName, languageName, field, op, langOptions) + # TODO: Add supported beautifiers to option description + # logger.verbose('optionDef', optionDef, optionName) + if optionDef.beautifiers.length > 0 - # Prefix language's options with namespace - for langName, ops of langOptions + # optionDef.title = " + optionDef.description = "#{optionDef.description} (Supported by #{optionDef.beautifiers.join(', ')})" + else - # Get language with name - lang = languages[langName] + # optionDef.title = "(DEPRECATED) + optionDef.description = "#{optionDef.description} (Not supported by any beautifiers)" + if result[optionName]? + logger.warn("Duplicate option detected: ", optionName, optionDef) + result[optionName] = optionDef + return result + ), result) + ), {}) + + + # Generate Language configurations + # logger.verbose('languages', languages) + for langName, lang of languages + + # logger.verbose(langName, lang) + name = lang.name + beautifiers = lang.beautifiers + optionName = "language_#{lang.namespace}" + + + # Add Language configurations + flatOptions["#{optionName}_disabled"] = { + title : "Language Config - #{name} - Disable Beautifying Language" + type : 'boolean' + default : false + description : "Disable #{name} Beautification" + } + flatOptions["#{optionName}_default_beautifier"] = { + title : "Language Config - #{name} - Default Beautifier" + type : 'string' + default : lang.defaultBeautifier ? beautifiers[0] + description : "Default Beautifier to be used for #{name}" + enum : _.uniq(beautifiers) + } + flatOptions["#{optionName}_beautify_on_save"] = { + title : "Language Config - #{name} - Beautify On Save" + type : 'boolean' + default : false + description : "Automatically beautify #{name} files on save" + } + + # logger.verbose('flatOptions', flatOptions) + return flatOptions + + + ### + From https://github.com/atom/notifications/blob/01779ade79e7196f1603b8c1fa31716aa4a33911/lib/notification-issue.coffee#L130 + ### + encodeURI : (str) -> + str = encodeURI(str) + str.replace(/#/g, '%23').replace(/;/g, '%3B') + + + getBeautifiers : (language, options) -> + + # logger.verbose(@beautifiers) + _.filter( @beautifiers, (beautifier) -> + + # logger.verbose('beautifier',beautifier, language) + _.contains(beautifier.languages, language) + ) + + getLanguage : (grammar, filePath) -> + # Get language + fileExtension = path.extname(filePath) + # Remove prefix "." (period) in fileExtension + fileExtension = fileExtension.substr(1) + languages = @languages.getLanguages({grammar, extension: fileExtension}) + logger.verbose(languages, grammar, fileExtension) + # Check if unsupported language + if languages.length < 1 + return null + else + # TODO: select appropriate language + language = languages[0] + + getOptionsForLanguage : (allOptions, language) -> + # Options for Language + selections = (language.fallback or []).concat([language.namespace]) + options = @getOptions(selections, allOptions) or {} + + beautify : (text, allOptions, grammar, filePath, {onSave} = {}) -> + return Promise.all(allOptions) + .then((allOptions) => + return new Promise((resolve, reject) => + logger.info('beautify', text, allOptions, grammar, filePath) + logger.verbose(allOptions) - - # Use the namespace from language as key prefix - prefix = lang.namespace - - - # logger.verbose(langName, lang, prefix, ops) - # Iterate over all language options and rename fields - for field, op of ops - - # Rename field - delete ops[field] - ops["#{prefix}_#{field}"] = op - - # Flatten Options per language to array of all options - allOptions = _.values(langOptions) - - - # logger.verbose('allOptions', allOptions) - # Flatten array of objects to single object for options - flatOptions = _.reduce(allOptions, ((result, languageOptions, language) -> - - # Iterate over fields (keys) in Language's Options - # and merge them into single result - # logger.verbose('language options', language, languageOptions, result) - return _.reduce(languageOptions, ((result, optionDef, optionName) -> - - # TODO: Add supported beautifiers to option description - # logger.verbose('optionDef', optionDef, optionName) - if optionDef.beautifiers.length > 0 - - # optionDef.title = " - optionDef.description = "#{optionDef.description} (Supported by #{optionDef.beautifiers.join(', ')})" - else - - # optionDef.title = "(DEPRECATED) - optionDef.description = "#{optionDef.description} (Not supported by any beautifiers)" - if result[optionName]? - logger.warn("Duplicate option detected: ", optionName, optionDef) - result[optionName] = optionDef - return result - ), result) - ), {}) - - - # Generate Language configurations - # logger.verbose('languages', languages) - for langName, lang of languages - - # logger.verbose(langName, lang) - name = lang.name - beautifiers = lang.beautifiers - optionName = "language_#{lang.namespace}" - - - # Add Language configurations - flatOptions["#{optionName}_disabled"] = { - title : "Language Config - #{name} - Disable Beautifying Language" - type : 'boolean' - default : false - description : "Disable #{name} Beautification" - } - flatOptions["#{optionName}_default_beautifier"] = { - title : "Language Config - #{name} - Default Beautifier" - type : 'string' - default : lang.defaultBeautifier ? beautifiers[0] - description : "Default Beautifier to be used for #{name}" - enum : _.uniq(beautifiers) - } - flatOptions["#{optionName}_beautify_on_save"] = { - title : "Language Config - #{name} - Beautify On Save" - type : 'boolean' - default : false - description : "Automatically beautify #{name} files on save" - } - - # logger.verbose('flatOptions', flatOptions) - return flatOptions - - - ### - From https://github.com/atom/notifications/blob/01779ade79e7196f1603b8c1fa31716aa4a33911/lib/notification-issue.coffee#L130 - ### - encodeURI : (str) -> - str = encodeURI(str) - str.replace(/#/g, '%23').replace(/;/g, '%3B') - - - getBeautifiers : (language, options) -> - - # logger.verbose(@beautifiers) - _.filter( @beautifiers, (beautifier) -> - - # logger.verbose('beautifier',beautifier, language) - _.contains(beautifier.languages, language) - ) - - getLanguage : (grammar, filePath) -> # Get language fileExtension = path.extname(filePath) # Remove prefix "." (period) in fileExtension fileExtension = fileExtension.substr(1) languages = @languages.getLanguages({grammar, extension: fileExtension}) logger.verbose(languages, grammar, fileExtension) + # Check if unsupported language if languages.length < 1 - return null + unsupportedGrammar = true + + + # Check if on save + if onSave + + # Ignore this, as it was just a general file save, and + # not intended to be beautified + return resolve( null ) else - # TODO: select appropriate language - language = languages[0] - getOptionsForLanguage : (allOptions, language) -> - # Options for Language - selections = (language.fallback or []).concat([language.namespace]) - options = @getOptions(selections, allOptions) or {} - - beautify : (text, allOptions, grammar, filePath, {onSave} = {}) -> - return Promise.all(allOptions) - .then((allOptions) => - return new Promise((resolve, reject) => - logger.info('beautify', text, allOptions, grammar, filePath) - logger.verbose(allOptions) - - # Get language - fileExtension = path.extname(filePath) - # Remove prefix "." (period) in fileExtension - fileExtension = fileExtension.substr(1) - languages = @languages.getLanguages({grammar, extension: fileExtension}) - logger.verbose(languages, grammar, fileExtension) - - # Check if unsupported language - if languages.length < 1 - unsupportedGrammar = true + # TODO: select appropriate language + language = languages[0] - # Check if on save - if onSave - - # Ignore this, as it was just a general file save, and - # not intended to be beautified - return resolve( null ) - else - - # TODO: select appropriate language - language = languages[0] + # Get language config + langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled") - # Get language config - langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled") + # Beautify! + unsupportedGrammar = false - # Beautify! - unsupportedGrammar = false + # Check if Language is disabled + if langDisabled + return resolve( null ) + + # Get more language config + preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier") + beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save") + legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave") - # Check if Language is disabled - if langDisabled - return resolve( null ) + # Verify if beautifying on save + if onSave and not (beautifyOnSave or legacyBeautifyOnSave) - # Get more language config - preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier") - beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save") - legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave") + # Saving, and beautify on save is disabled + return resolve( null ) + + # Options for Language + options = @getOptionsForLanguage(allOptions, language) + + # Get Beautifier + logger.verbose(grammar, language) + beautifiers = @getBeautifiers(language.name, options) + + logger.verbose('options', options) + logger.verbose('beautifiers', beautifiers) + + logger.verbose(language.name, filePath, options, allOptions) + + # Check if unsupported language + if beautifiers.length < 1 + unsupportedGrammar = true + else + # Select beautifier from language config preferences + beautifier = _.find(beautifiers, (beautifier) -> + beautifier.name is preferredBeautifierName + ) or beautifiers[0] + logger.verbose('beautifier', beautifier.name, beautifiers) + transformOptions = (beautifier, languageName, options) -> + + # Transform options, if applicable + beautifierOptions = beautifier.options[languageName] + if typeof beautifierOptions is "boolean" + + # Language is supported by beautifier + # If true then all options are directly supported + # If falsy then pass all options to beautifier, + # although no options are directly supported. + return options + else if typeof beautifierOptions is "object" + + # Transform the options + transformedOptions = {} - # Verify if beautifying on save - if onSave and not (beautifyOnSave or legacyBeautifyOnSave) + # Transform for fields + for field, op of beautifierOptions + if typeof op is "string" - # Saving, and beautify on save is disabled - return resolve( null ) + # Rename + transformedOptions[field] = options[op] + else if typeof op is "function" - # Options for Language - options = @getOptionsForLanguage(allOptions, language) + # Transform + transformedOptions[field] = op(options[field]) + else if typeof op is "boolean" - # Get Beautifier - logger.verbose(grammar, language) - beautifiers = @getBeautifiers(language.name, options) + # Enable/Disable + if op is true + transformedOptions[field] = options[field] + else if _.isArray(op) - logger.verbose('options', options) - logger.verbose('beautifiers', beautifiers) - - logger.verbose(language.name, filePath, options, allOptions) - - # Check if unsupported language - if beautifiers.length < 1 - unsupportedGrammar = true - else - # Select beautifier from language config preferences - beautifier = _.find(beautifiers, (beautifier) -> - beautifier.name is preferredBeautifierName - ) or beautifiers[0] - logger.verbose('beautifier', beautifier.name, beautifiers) - transformOptions = (beautifier, languageName, options) -> - - # Transform options, if applicable - beautifierOptions = beautifier.options[languageName] - if typeof beautifierOptions is "boolean" - - # Language is supported by beautifier - # If true then all options are directly supported - # If falsy then pass all options to beautifier, - # although no options are directly supported. - return options - else if typeof beautifierOptions is "object" - - # Transform the options - transformedOptions = {} + # Complex function + [fields..., fn] = op + vals = _.map(fields, (f) -> + return options[f] + ) - # Transform for fields - for field, op of beautifierOptions - if typeof op is "string" + # Apply function + transformedOptions[field] = fn.apply( null , vals) - # Rename - transformedOptions[field] = options[op] - else if typeof op is "function" + # Replace old options with new transformed options + return transformedOptions + else + logger.warn("Unsupported Language options: ", beautifierOptions) + return options - # Transform - transformedOptions[field] = op(options[field]) - else if typeof op is "boolean" - - # Enable/Disable - if op is true - transformedOptions[field] = options[field] - else if _.isArray(op) - - # Complex function - [fields..., fn] = op - vals = _.map(fields, (f) -> - return options[f] - ) - - - # Apply function - transformedOptions[field] = fn.apply( null , vals) - - # Replace old options with new transformed options - return transformedOptions - else - logger.warn("Unsupported Language options: ", beautifierOptions) - return options - - # Apply language-specific option transformations - options = transformOptions(beautifier, language.name, options) - - # Beautify text with language options - @emit "beautify::start" - beautifier.beautify(text, language.name, options) - .then(resolve) - .catch(reject) - .finally(=> - @emit "beautify::end" - ) - - # Check if Analytics is enabled - if atom.config.get("atom-beautify.analytics") - - # Setup Analytics - analytics = new Analytics(analyticsWriteKey) - unless atom.config.get("atom-beautify._analyticsUserId") - uuid = require("node-uuid") - atom.config.set "atom-beautify._analyticsUserId", uuid.v4() - - # Setup Analytics User Id - userId = atom.config.get("atom-beautify._analyticsUserId") - analytics.identify userId : userId - version = pkg.version - analytics.track - userId : atom.config.get("atom-beautify._analyticsUserId") - event : "Beautify" - properties : - language : language?.name - grammar : grammar - extension : fileExtension - version : version - options : allOptions - label : language?.name - category : version - - if unsupportedGrammar - if atom.config.get("atom-beautify.muteUnsupportedLanguageErrors") - return resolve( null ) - else - repoBugsUrl = pkg.bugs.url - - - # issueTitle = "Add support for language with grammar ' - # issueBody = """ - # - # **Atom Version**: - # **Atom Beautify Version**: - # **Platform**: - # - # ``` - # - # ``` - # - # """ - # requestLanguageUrl = " - # detail = "If you would like to request this language be supported please create an issue by clicking + @emit "beautify::end" ) + # Check if Analytics is enabled + if atom.config.get("atom-beautify.analytics") - findFileResults : {} + # Setup Analytics + analytics = new Analytics(analyticsWriteKey) + unless atom.config.get("atom-beautify._analyticsUserId") + uuid = require("node-uuid") + atom.config.set "atom-beautify._analyticsUserId", uuid.v4() + + # Setup Analytics User Id + userId = atom.config.get("atom-beautify._analyticsUserId") + analytics.identify userId : userId + version = pkg.version + analytics.track + userId : atom.config.get("atom-beautify._analyticsUserId") + event : "Beautify" + properties : + language : language?.name + grammar : grammar + extension : fileExtension + version : version + options : allOptions + label : language?.name + category : version + + if unsupportedGrammar + if atom.config.get("atom-beautify.muteUnsupportedLanguageErrors") + return resolve( null ) + else + repoBugsUrl = pkg.bugs.url - # CLI - getUserHome : -> - process.env.HOME or process.env.HOMEPATH or process.env.USERPROFILE - verifyExists : (fullPath) -> - fs ?= require("fs") - ( if fs.existsSync(fullPath) then fullPath else null ) + # issueTitle = "Add support for language with grammar ' + # issueBody = """ + # + # **Atom Version**: + # **Atom Beautify Version**: + # **Platform**: + # + # ``` + # + # ``` + # + # """ + # requestLanguageUrl = " + # detail = "If you would like to request this language be supported please create an issue by clicking - path ?= require("path") - dir = dir or process.cwd() - filename = path.normalize(path.join(dir, name)) - return @findFileResults[filename] if @findFileResults[filename] isnt undefined - parent = path.resolve(dir, "../") - if @verifyExists(filename) - @findFileResults[filename] = filename - return filename - if dir is parent - @findFileResults[filename] = null - return null - if upwards - findFile name, parent - else - return null - - - ### - Tries to find a configuration file in either project directory - or in the home directory. Configuration files are named - '.jsbeautifyrc'. - - @param {string} config name of the configuration file - @param {string} file path to the file to be linted - @param {boolean} upwards should recurse upwards on failure? (default: true) - - @returns {string} a path to the config file - ### - findConfig : (config, file, upwards = true) -> - path ?= require("path") - dir = path.dirname(path.resolve(file)) - envs = @getUserHome() - home = path.normalize(path.join(envs, config)) - proj = @findFile(config, dir, upwards) - logger.verbose(dir, proj, home) - return proj if proj - return home if @verifyExists(home) - null - getConfigOptionsFromSettings : (langs) -> - config = atom.config.get('atom-beautify') - options = {} - - - # logger.verbose(langs, config); - # Iterate over keys of the settings - _.every _.keys(config), (k) -> - - # Check if keys start with a language - p = k.split("_")[0] - idx = _.indexOf(langs, p) - - - # logger.verbose(k, p, idx); - if idx >= 0 - - # Remove the language prefix and nest in options - lang = langs[idx] - opt = k.replace( new RegExp("^" + lang + "_"), "") - options[lang] = options[lang] or {} - options[lang][opt] = config[k] - - # logger.verbose(lang, opt); - true - - # logger.verbose(options); - options - - # Look for .jsbeautifierrc in file and home path, check env variables - getConfig : (startPath, upwards = true) -> - - # Verify that startPath is a string - startPath = ( if ( typeof startPath is "string") then startPath else "") - return {} unless startPath - - - # Get the path to the config file - configPath = @findConfig(".jsbeautifyrc", startPath, upwards) - externalOptions = undefined - if configPath - fs ?= require("fs") - contents = fs.readFileSync(configPath, - encoding : "utf8" + atom?.notifications.addWarning(title, { + detail + dismissable : true + }) + return resolve( null ) ) - unless contents - externalOptions = {} - else - try - strip ?= require("strip-json-comments") - externalOptions = JSON.parse(strip(contents)) - catch e - logger.debug "Failed parsing config as JSON: " + configPath - # Attempt as YAML - try - yaml ?= require("yaml-front-matter") - externalOptions = yaml.safeLoad(contents) - catch e - logger.debug "Failed parsing config as YAML and JSON: " + configPath - externalOptions = {} - else + ) + + + findFileResults : {} + + + # CLI + getUserHome : -> + process.env.HOME or process.env.HOMEPATH or process.env.USERPROFILE + verifyExists : (fullPath) -> + fs ?= require("fs") + ( if fs.existsSync(fullPath) then fullPath else null ) + + + + # Storage for memoized results from find file + # Should prevent lots of directory traversal & + # lookups when liniting an entire project + ### + Searches for a file with a specified name starting with + 'dir' and going all the way up either until it finds the file + or hits the root. + + @param {string} name filename to search for (e.g. .jshintrc) + @param {string} dir directory to start search from (default: + current working directory) + @param {boolean} upwards should recurse upwards on failure? (default: true) + + @returns {string} normalized filename + ### + findFile : (name, dir, upwards = true) -> + path ?= require("path") + dir = dir or process.cwd() + filename = path.normalize(path.join(dir, name)) + return @findFileResults[filename] if @findFileResults[filename] isnt undefined + parent = path.resolve(dir, "../") + if @verifyExists(filename) + @findFileResults[filename] = filename + return filename + if dir is parent + @findFileResults[filename] = null + return null + if upwards + findFile name, parent + else + return null + + + ### + Tries to find a configuration file in either project directory + or in the home directory. Configuration files are named + '.jsbeautifyrc'. + + @param {string} config name of the configuration file + @param {string} file path to the file to be linted + @param {boolean} upwards should recurse upwards on failure? (default: true) + + @returns {string} a path to the config file + ### + findConfig : (config, file, upwards = true) -> + path ?= require("path") + dir = path.dirname(path.resolve(file)) + envs = @getUserHome() + home = path.normalize(path.join(envs, config)) + proj = @findFile(config, dir, upwards) + logger.verbose(dir, proj, home) + return proj if proj + return home if @verifyExists(home) + null + getConfigOptionsFromSettings : (langs) -> + config = atom.config.get('atom-beautify') + options = {} + + + # logger.verbose(langs, config); + # Iterate over keys of the settings + _.every _.keys(config), (k) -> + + # Check if keys start with a language + p = k.split("_")[0] + idx = _.indexOf(langs, p) + + + # logger.verbose(k, p, idx); + if idx >= 0 + + # Remove the language prefix and nest in options + lang = langs[idx] + opt = k.replace( new RegExp("^" + lang + "_"), "") + options[lang] = options[lang] or {} + options[lang][opt] = config[k] + + # logger.verbose(lang, opt); + true + + # logger.verbose(options); + options + + # Look for .jsbeautifierrc in file and home path, check env variables + getConfig : (startPath, upwards = true) -> + + # Verify that startPath is a string + startPath = ( if ( typeof startPath is "string") then startPath else "") + return {} unless startPath + + + # Get the path to the config file + configPath = @findConfig(".jsbeautifyrc", startPath, upwards) + externalOptions = undefined + if configPath + fs ?= require("fs") + contents = fs.readFileSync(configPath, + encoding : "utf8" + ) + unless contents + externalOptions = {} + else + try + strip ?= require("strip-json-comments") + externalOptions = JSON.parse(strip(contents)) + catch e + + logger.debug "Failed parsing config as JSON: " + configPath + # Attempt as YAML + try + yaml ?= require("yaml-front-matter") + externalOptions = yaml.safeLoad(contents) + catch e + logger.debug "Failed parsing config as YAML and JSON: " + configPath externalOptions = {} - externalOptions - getOptionsForPath : (editedFilePath, editor) -> - languageNamespaces = @languages.namespaces + else + externalOptions = {} + externalOptions + getOptionsForPath : (editedFilePath, editor) -> + languageNamespaces = @languages.namespaces - # Editor Options - editorOptions = {} - if editor? + # Editor Options + editorOptions = {} + if editor? - # Get current Atom editor configuration - isSelection = !!editor.getSelectedText() - softTabs = editor.softTabs - tabLength = editor.getTabLength() - editorOptions = - indent_size : ( if softTabs then tabLength else 1) - indent_char : ( if softTabs then " " else "\t") - indent_with_tabs : not softTabs + # Get current Atom editor configuration + isSelection = !!editor.getSelectedText() + softTabs = editor.softTabs + tabLength = editor.getTabLength() + editorOptions = + indent_size : ( if softTabs then tabLength else 1) + indent_char : ( if softTabs then " " else "\t") + indent_with_tabs : not softTabs - # From Package Settings - configOptions = @getConfigOptionsFromSettings(languageNamespaces) + # From Package Settings + configOptions = @getConfigOptionsFromSettings(languageNamespaces) - # Get configuration in User's Home directory - userHome = @getUserHome() + # Get configuration in User's Home directory + userHome = @getUserHome() - # FAKEFILENAME forces `path` to treat as file path and its parent directory - # is the userHome. See implementation of findConfig - # and how path.dirname(DIRECTORY) returns the parent directory of DIRECTORY - homeOptions = @getConfig(path.join(userHome, "FAKEFILENAME"), false) - if editedFilePath? + # FAKEFILENAME forces `path` to treat as file path and its parent directory + # is the userHome. See implementation of findConfig + # and how path.dirname(DIRECTORY) returns the parent directory of DIRECTORY + homeOptions = @getConfig(path.join(userHome, "FAKEFILENAME"), false) + if editedFilePath? - # Handle EditorConfig options - # http://editorconfig.org/ - editorconfig ?= require('editorconfig') - editorConfigOptions = editorconfig.parse(editedFilePath) - .then((editorConfigOptions) => + # Handle EditorConfig options + # http://editorconfig.org/ + editorconfig ?= require('editorconfig') + editorConfigOptions = editorconfig.parse(editedFilePath) + .then((editorConfigOptions) => - logger.verbose('editorConfigOptions', editorConfigOptions) + logger.verbose('editorConfigOptions', editorConfigOptions) - # Transform EditorConfig to Atom Beautify's config structure and naming - if editorConfigOptions.indent_style is 'space' - editorConfigOptions.indent_char = " " + # Transform EditorConfig to Atom Beautify's config structure and naming + if editorConfigOptions.indent_style is 'space' + editorConfigOptions.indent_char = " " - # if (editorConfigOptions.indent_size) - # editorConfigOptions.indent_size = config.indent_size - else if editorConfigOptions.indent_style is 'tab' - editorConfigOptions.indent_char = "\t" - editorConfigOptions.indent_with_tabs = true - if (editorConfigOptions.tab_width) - editorConfigOptions.indent_size = editorConfigOptions.tab_width + # if (editorConfigOptions.indent_size) + # editorConfigOptions.indent_size = config.indent_size + else if editorConfigOptions.indent_style is 'tab' + editorConfigOptions.indent_char = "\t" + editorConfigOptions.indent_with_tabs = true + if (editorConfigOptions.tab_width) + editorConfigOptions.indent_size = editorConfigOptions.tab_width - # Nest options under _default namespace - return { - _default: - editorConfigOptions - } - ) - - # Get all options in configuration files from this directory upwards to root - projectOptions = [] - p = path.dirname(editedFilePath) - - - # Check if p is root (top directory) - while p isnt path.resolve(p, "../") - - # Get config for p - pf = path.join(p, "FAKEFILENAME") - pc = @getConfig(pf, false) - - isNested = @isNestedOptions(pc) - unless isNested - pc = { - _default: pc - } - - # Add config for p to project's config options - projectOptions.push(pc) - - # logger.verbose p, pc - # Move upwards - p = path.resolve(p, "../") - else - editorConfigOptions = {} - projectOptions = [] - - # Combine all options together - allOptions = [ - { - _default: - editorOptions - }, - configOptions, - { - _default: - homeOptions - }, + # Nest options under _default namespace + return { + _default: editorConfigOptions - ] - # Reverse and add projectOptions to all options - projectOptions.reverse() - allOptions = allOptions.concat(projectOptions) + } + ) - # logger.verbose(allOptions) - return allOptions - - isNestedOptions : (currOptions) -> - containsNested = false - key = undefined - - # Check if already nested under _default - if currOptions._default - return true - - # Check to see if config file uses nested object format to split up js/css/html options - for key of currOptions - - # Check if is supported language - if _.indexOf(@languages.namespaces, key) >= 0 and typeof currOptions[key] is "object" # Check if nested object (more options in value) - containsNested = true - break # Found, break out of loop, no need to continue - - return containsNested - - getOptions : (selections, allOptions) => - self = this - _ ?= require("lodash") - extend ?= require("extend") - - logger.verbose('getOptions selections', selections, allOptions) - - # logger.verbose(selection, allOptions); - # Reduce all options into correctly merged options. - options = _.reduce(allOptions, (result, currOptions) => - collectedConfig = currOptions._default or {} - containsNested = @isNestedOptions(currOptions) - logger.verbose(containsNested, currOptions) - # logger.verbose(containsNested, currOptions); - - # Create a flat object of config options if nested format was used - unless containsNested - # _.merge collectedConfig, currOptions - currOptions = { - _default: currOptions - } - - # Merge with selected options - # where `selection` could be `html`, `js`, 'css', etc - for selection in selections - # Merge current options on top of fallback options - logger.verbose('options', selection, currOptions[selection]); - _.merge collectedConfig, currOptions[selection] - logger.verbose('options', selection, collectedConfig); - - extend result, collectedConfig - , {}) + # Get all options in configuration files from this directory upwards to root + projectOptions = [] + p = path.dirname(editedFilePath) - # TODO: Clean. - # There is a bug in nopt - # See https://github.com/npm/nopt/issues/38 - # logger.verbose('pre-clean', JSON.stringify(options)); - # options = cleanOptions(options, knownOpts); - # logger.verbose('post-clean', JSON.stringify(options)); - options + # Check if p is root (top directory) + while p isnt path.resolve(p, "../") + + # Get config for p + pf = path.join(p, "FAKEFILENAME") + pc = @getConfig(pf, false) + + isNested = @isNestedOptions(pc) + unless isNested + pc = { + _default: pc + } + + # Add config for p to project's config options + projectOptions.push(pc) + + # logger.verbose p, pc + # Move upwards + p = path.resolve(p, "../") + else + editorConfigOptions = {} + projectOptions = [] + + # Combine all options together + allOptions = [ + { + _default: + editorOptions + }, + configOptions, + { + _default: + homeOptions + }, + editorConfigOptions + ] + # Reverse and add projectOptions to all options + projectOptions.reverse() + allOptions = allOptions.concat(projectOptions) + + # logger.verbose(allOptions) + return allOptions + + isNestedOptions : (currOptions) -> + containsNested = false + key = undefined + + # Check if already nested under _default + if currOptions._default + return true + + # Check to see if config file uses nested object format to split up js/css/html options + for key of currOptions + + # Check if is supported language + if _.indexOf(@languages.namespaces, key) >= 0 and typeof currOptions[key] is "object" # Check if nested object (more options in value) + containsNested = true + break # Found, break out of loop, no need to continue + + return containsNested + + getOptions : (selections, allOptions) => + self = this + _ ?= require("lodash") + extend ?= require("extend") + + logger.verbose('getOptions selections', selections, allOptions) + + # logger.verbose(selection, allOptions); + # Reduce all options into correctly merged options. + options = _.reduce(allOptions, (result, currOptions) => + collectedConfig = currOptions._default or {} + containsNested = @isNestedOptions(currOptions) + logger.verbose(containsNested, currOptions) + # logger.verbose(containsNested, currOptions); + + # Create a flat object of config options if nested format was used + unless containsNested + # _.merge collectedConfig, currOptions + currOptions = { + _default: currOptions + } + + # Merge with selected options + # where `selection` could be `html`, `js`, 'css', etc + for selection in selections + # Merge current options on top of fallback options + logger.verbose('options', selection, currOptions[selection]); + _.merge collectedConfig, currOptions[selection] + logger.verbose('options', selection, collectedConfig); + + extend result, collectedConfig + , {}) + + + # TODO: Clean. + # There is a bug in nopt + # See https://github.com/npm/nopt/issues/38 + # logger.verbose('pre-clean', JSON.stringify(options)); + # options = cleanOptions(options, knownOpts); + # logger.verbose('post-clean', JSON.stringify(options)); + options diff --git a/src/beautifiers/js-beautify.coffee b/src/beautifiers/js-beautify.coffee index 369f94a..202533c 100644 --- a/src/beautifiers/js-beautify.coffee +++ b/src/beautifiers/js-beautify.coffee @@ -2,52 +2,52 @@ Beautifier = require('./beautifier') module.exports = class JSBeautify extends Beautifier - name: "JS Beautify" + name: "JS Beautify" - options: { - HTML: true - XML: true - Handlebars: true - Mustache: true - Marko: true - JavaScript: true - JSON: true - CSS: - indent_size: true - indent_char: true - selector_separator_newline: true - newline_between_rules: true - preserve_newlines: true - wrap_line_length: true - } + options: { + HTML: true + XML: true + Handlebars: true + Mustache: true + Marko: true + JavaScript: true + JSON: true + CSS: + indent_size: true + indent_char: true + selector_separator_newline: true + newline_between_rules: true + preserve_newlines: true + wrap_line_length: true + } - beautify: (text, language, options) -> - @verbose("JS Beautify language #{language}") - return new @Promise((resolve, reject) => - try - switch language - when "JSON", "JavaScript" - beautifyJS = require("js-beautify") - text = beautifyJS(text, options) - resolve text - when "Handlebars", "Mustache" - # jshint ignore: start - options.indent_handlebars = true # Force jsbeautify to indent_handlebars - # jshint ignore: end - beautifyHTML = require("js-beautify").html - text = beautifyHTML(text, options) - resolve text - when "HTML (Liquid)", "HTML", "XML", "Marko", "Web Form/Control (C#)", "Web Handler (C#)" - beautifyHTML = require("js-beautify").html - text = beautifyHTML(text, options) - @debug("Beautified HTML: #{text}") - resolve text - when "CSS" - beautifyCSS = require("js-beautify").css - text = beautifyCSS(text, options) - resolve text - catch err - @error("JS Beautify error: #{err}") - reject(err) + beautify: (text, language, options) -> + @verbose("JS Beautify language #{language}") + return new @Promise((resolve, reject) => + try + switch language + when "JSON", "JavaScript" + beautifyJS = require("js-beautify") + text = beautifyJS(text, options) + resolve text + when "Handlebars", "Mustache" + # jshint ignore: start + options.indent_handlebars = true # Force jsbeautify to indent_handlebars + # jshint ignore: end + beautifyHTML = require("js-beautify").html + text = beautifyHTML(text, options) + resolve text + when "HTML (Liquid)", "HTML", "XML", "Marko", "Web Form/Control (C#)", "Web Handler (C#)" + beautifyHTML = require("js-beautify").html + text = beautifyHTML(text, options) + @debug("Beautified HTML: #{text}") + resolve text + when "CSS" + beautifyCSS = require("js-beautify").css + text = beautifyCSS(text, options) + resolve text + catch err + @error("JS Beautify error: #{err}") + reject(err) - ) + ) diff --git a/src/beautifiers/perltidy.coffee b/src/beautifiers/perltidy.coffee index 50fe6e0..5821d38 100644 --- a/src/beautifiers/perltidy.coffee +++ b/src/beautifiers/perltidy.coffee @@ -5,26 +5,26 @@ Requires [perltidy](http://perltidy.sourceforge.net) Beautifier = require('./beautifier') module.exports = class PerlTidy extends Beautifier - name: "Perltidy" + name: "Perltidy" - options: { - Perl: true - } + options: { + Perl: true + } - cli: (options) -> - if not options.perltidy_path? - return new Error("'Perl Perltidy Path' not set!" + - " Please set this in the Atom Beautify package settings.") - else - return options.perltidy_path + cli: (options) -> + if not options.perltidy_path? + return new Error("'Perl Perltidy Path' not set!" + + " Please set this in the Atom Beautify package settings.") + else + return options.perltidy_path - beautify: (text, language, options) -> - @run("perltidy", [ - '--standard-output' - '--standard-error-output' - '--quiet' - "--profile=#{options.perltidy_profile}" if options.perltidy_profile? - @tempFile("input", text) - ], help: { - link: "http://perltidy.sourceforge.net/" - }) + beautify: (text, language, options) -> + @run("perltidy", [ + '--standard-output' + '--standard-error-output' + '--quiet' + "--profile=#{options.perltidy_profile}" if options.perltidy_profile? + @tempFile("input", text) + ], help: { + link: "http://perltidy.sourceforge.net/" + }) diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index fd2386d..1d63195 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -6,70 +6,70 @@ Requires https://github.com/FriendsOfPHP/PHP-CS-Fixer Beautifier = require('./beautifier') module.exports = class PHPCSFixer extends Beautifier - name: "PHP-CS-Fixer" + name: "PHP-CS-Fixer" - options: { - PHP: true - } + options: { + PHP: true + } - beautify: (text, language, options) -> - @debug('php-cs-fixer', options) + beautify: (text, language, options) -> + @debug('php-cs-fixer', options) - isWin = @isWindows - if isWin - # Find php-cs-fixer.phar script - @Promise.all([ - @which(options.cs_fixer_path) if options.cs_fixer_path - @which('php-cs-fixer') - ]).then((paths) => - @debug('php-cs-fixer paths', paths) - _ = require('lodash') - # Get first valid, absolute path - phpCSFixerPath = _.find(paths, (p) -> p and p.charAt(0) is '/' ) - @verbose('phpCSFixerPath', phpCSFixerPath) - @debug('phpCSFixerPath', phpCSFixerPath, paths) - # Check if PHP-CS-Fixer path was found - if phpCSFixerPath? - # Found PHP-CS-Fixer path - @run("php", [ - phpCSFixerPath - "fix" - "--level=#{options.level}" if options.level - "--fixers=#{options.fixers}" if options.fixers - tempFile = @tempFile("temp", text) - ], { - ignoreReturnCode: true - help: { - link: "http://php.net/manual/en/install.php" - } - }) - .then(=> - @readFile(tempFile) - ) - else - @verbose('php-cs-fixer not found!') - # Could not find PHP-CS-Fixer path - @Promise.reject(@commandNotFoundError( - 'php-cs-fixer' - { - link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" - program: "php-cs-fixer.phar" - pathOption: "PHP - CS Fixer Path" - }) - ) + isWin = @isWindows + if isWin + # Find php-cs-fixer.phar script + @Promise.all([ + @which(options.cs_fixer_path) if options.cs_fixer_path + @which('php-cs-fixer') + ]).then((paths) => + @debug('php-cs-fixer paths', paths) + _ = require('lodash') + # Get first valid, absolute path + phpCSFixerPath = _.find(paths, (p) -> p and p.charAt(0) is '/' ) + @verbose('phpCSFixerPath', phpCSFixerPath) + @debug('phpCSFixerPath', phpCSFixerPath, paths) + # Check if PHP-CS-Fixer path was found + if phpCSFixerPath? + # Found PHP-CS-Fixer path + @run("php", [ + phpCSFixerPath + "fix" + "--level=#{options.level}" if options.level + "--fixers=#{options.fixers}" if options.fixers + tempFile = @tempFile("temp", text) + ], { + ignoreReturnCode: true + help: { + link: "http://php.net/manual/en/install.php" + } + }) + .then(=> + @readFile(tempFile) ) else - @run("php-cs-fixer", [ - "fix" - "--level=#{options.level}" if options.level - "--fixers=#{options.fixers}" if options.fixers - tempFile = @tempFile("temp", text) - ], { - ignoreReturnCode: true - help: { - link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" - } - }) - .then(=> - @readFile(tempFile) - ) + @verbose('php-cs-fixer not found!') + # Could not find PHP-CS-Fixer path + @Promise.reject(@commandNotFoundError( + 'php-cs-fixer' + { + link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" + program: "php-cs-fixer.phar" + pathOption: "PHP - CS Fixer Path" + }) + ) + ) + else + @run("php-cs-fixer", [ + "fix" + "--level=#{options.level}" if options.level + "--fixers=#{options.fixers}" if options.fixers + tempFile = @tempFile("temp", text) + ], { + ignoreReturnCode: true + help: { + link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" + } + }) + .then(=> + @readFile(tempFile) + ) diff --git a/src/beautifiers/prettydiff.coffee b/src/beautifiers/prettydiff.coffee index 4db3b05..8c0fc20 100644 --- a/src/beautifiers/prettydiff.coffee +++ b/src/beautifiers/prettydiff.coffee @@ -2,107 +2,107 @@ Beautifier = require('./beautifier') module.exports = class PrettyDiff extends Beautifier - name: "Pretty Diff" - options: { - # Apply these options first / globally, for all languages - _: - inchar: "indent_char" - insize: "indent_size" - objsort: (objsort) -> - objsort or false - preserve: ['preserve_newlines', (preserve_newlines) -> - if (preserve_newlines is true ) then \ - "all" else "none" - ] - cssinsertlines: "newline_between_rules" - comments: ["indent_comments", (indent_comments) -> - if (indent_comments is true) then \ - "indent" else "noindent" - ] - force: "force_indentation" - quoteConvert: "convert_quotes" - vertical: ['align_assignments', (align_assignments) -> - if (align_assignments is true ) then \ - "all" else "none" - ] - wrap: "wrap_line_length" - # Apply language-specific options - CSV: true - ERB: true - EJS: true - HTML: true - XML: true - Spacebars: true - JSX: true - JavaScript: true - CSS: true - SCSS: true - Sass: true - JSON: true - TSS: true - Twig: true - LESS: true - Swig: true - Visualforce: true - } + name: "Pretty Diff" + options: { + # Apply these options first / globally, for all languages + _: + inchar: "indent_char" + insize: "indent_size" + objsort: (objsort) -> + objsort or false + preserve: ['preserve_newlines', (preserve_newlines) -> + if (preserve_newlines is true ) then \ + "all" else "none" + ] + cssinsertlines: "newline_between_rules" + comments: ["indent_comments", (indent_comments) -> + if (indent_comments is true) then \ + "indent" else "noindent" + ] + force: "force_indentation" + quoteConvert: "convert_quotes" + vertical: ['align_assignments', (align_assignments) -> + if (align_assignments is true ) then \ + "all" else "none" + ] + wrap: "wrap_line_length" + # Apply language-specific options + CSV: true + ERB: true + EJS: true + HTML: true + XML: true + Spacebars: true + JSX: true + JavaScript: true + CSS: true + SCSS: true + Sass: true + JSON: true + TSS: true + Twig: true + LESS: true + Swig: true + Visualforce: true + } - beautify: (text, language, options) -> + beautify: (text, language, options) -> - return new @Promise((resolve, reject) => - prettydiff = require("prettydiff") - _ = require('lodash') + return new @Promise((resolve, reject) => + prettydiff = require("prettydiff") + _ = require('lodash') - # Select Prettydiff language - lang = "auto" - switch language - when "CSV" - lang = "csv" - when "EJS", "Twig" - lang = "ejs" - when "ERB" - lang = "html_ruby" - when "Handlebars", "Mustache", "Spacebars" - lang = "handlebars" - when "SGML", "Swig" - lang = "markup" - when "XML", "Visualforce" - lang = "xml" - when "HTML" - lang = "html" - when "JavaScript" - lang = "javascript" - when "JSON" - lang = "json" - when "JSX" - lang = "jsx" - when "JSTL" - lang = "jsp" - when "CSS" - lang = "css" - when "LESS" - lang = "less" - when "SCSS", "Sass" - lang = "scss" - when "TSS" - lang = "tss" - else - lang = "auto" + # Select Prettydiff language + lang = "auto" + switch language + when "CSV" + lang = "csv" + when "EJS", "Twig" + lang = "ejs" + when "ERB" + lang = "html_ruby" + when "Handlebars", "Mustache", "Spacebars" + lang = "handlebars" + when "SGML", "Swig" + lang = "markup" + when "XML", "Visualforce" + lang = "xml" + when "HTML" + lang = "html" + when "JavaScript" + lang = "javascript" + when "JSON" + lang = "json" + when "JSX" + lang = "jsx" + when "JSTL" + lang = "jsp" + when "CSS" + lang = "css" + when "LESS" + lang = "less" + when "SCSS", "Sass" + lang = "scss" + when "TSS" + lang = "tss" + else + lang = "auto" - # Prettydiff Arguments - args = - source: text - lang: lang - mode: "beautify" + # Prettydiff Arguments + args = + source: text + lang: lang + mode: "beautify" - # Merge args intos options - _.merge(options, args) + # Merge args intos options + _.merge(options, args) - # Beautify - @verbose('prettydiff', options) - output = prettydiff.api(options) - result = output[0] + # Beautify + @verbose('prettydiff', options) + output = prettydiff.api(options) + result = output[0] - # Return beautified text - resolve(result) + # Return beautified text + resolve(result) - ) + ) diff --git a/src/beautifiers/rubocop.coffee b/src/beautifiers/rubocop.coffee index 5673f74..df19fb5 100644 --- a/src/beautifiers/rubocop.coffee +++ b/src/beautifiers/rubocop.coffee @@ -6,35 +6,35 @@ Requires https://github.com/bbatsov/rubocop Beautifier = require('./beautifier') module.exports = class Rubocop extends Beautifier - name: "Rubocop" + name: "Rubocop" - options: { - Ruby: - indent_size: true + options: { + Ruby: + indent_size: true + } + + beautify: (text, language, options) -> + + # Generate config file + yaml = require("yaml-front-matter") + + config = { + "Style/IndentationWidth": + "Width": options.indent_size } + configStr = yaml.safeDump(config) + @debug("rubocop", config, configStr) - beautify: (text, language, options) -> - - # Generate config file - yaml = require("yaml-front-matter") - - config = { - "Style/IndentationWidth": - "Width": options.indent_size - } - configStr = yaml.safeDump(config) - @debug("rubocop", config, configStr) - - @run("rubocop", [ - "--auto-correct" - "--config", @tempFile("rubocop-config", configStr) - tempFile = @tempFile("temp", text) - ], {ignoreReturnCode: true}) - .then(=> - # console.log('rubocop', arguments, tempFile) - @readFile(tempFile) - # .then((text) -> - # console.log('rubocop', text) - # return text - # ) - ) + @run("rubocop", [ + "--auto-correct" + "--config", @tempFile("rubocop-config", configStr) + tempFile = @tempFile("temp", text) + ], {ignoreReturnCode: true}) + .then(=> + # console.log('rubocop', arguments, tempFile) + @readFile(tempFile) + # .then((text) -> + # console.log('rubocop', text) + # return text + # ) + ) diff --git a/src/beautifiers/ruby-beautify.coffee b/src/beautifiers/ruby-beautify.coffee index 19dfcb0..be27af6 100644 --- a/src/beautifiers/ruby-beautify.coffee +++ b/src/beautifiers/ruby-beautify.coffee @@ -6,19 +6,19 @@ Requires https://github.com/erniebrodeur/ruby-beautify Beautifier = require('./beautifier') module.exports = class RubyBeautify extends Beautifier - name: "Ruby Beautify" + name: "Ruby Beautify" - options: { - Ruby: - indent_size: true - indent_char: true - } + options: { + Ruby: + indent_size: true + indent_char: true + } - beautify: (text, language, options) -> - @run("rbeautify", [ - if options.indent_char is '\t' then "--tabs" else "--spaces" - "--indent_count", options.indent_count - @tempFile("input", text) - ], help: { - link: "https://github.com/erniebrodeur/ruby-beautify" - }) + beautify: (text, language, options) -> + @run("rbeautify", [ + if options.indent_char is '\t' then "--tabs" else "--spaces" + "--indent_count", options.indent_count + @tempFile("input", text) + ], help: { + link: "https://github.com/erniebrodeur/ruby-beautify" + }) diff --git a/src/beautifiers/rustfmt.coffee b/src/beautifiers/rustfmt.coffee index 27711a8..273b2e1 100644 --- a/src/beautifiers/rustfmt.coffee +++ b/src/beautifiers/rustfmt.coffee @@ -7,21 +7,21 @@ Beautifier = require('./beautifier') module.exports = class rustfmt extends Beautifier - name: "rustfmt" + name: "rustfmt" - options: { - Rust: true - } + options: { + Rust: true + } - beautify: (text, language, options) -> - program = options.rustfmt_path or "rustfmt" - @run(program, [ - tmpFile = @tempFile("tmp", text) - ], help: { - link: "https://github.com/nrc/rustfmt" - program: "rustfmt" - pathOption: "Rust - Rustfmt Path" - }) - .then(=> - @readFile(tmpFile) - ) + beautify: (text, language, options) -> + program = options.rustfmt_path or "rustfmt" + @run(program, [ + tmpFile = @tempFile("tmp", text) + ], help: { + link: "https://github.com/nrc/rustfmt" + program: "rustfmt" + pathOption: "Rust - Rustfmt Path" + }) + .then(=> + @readFile(tmpFile) + ) diff --git a/src/beautifiers/sqlformat.coffee b/src/beautifiers/sqlformat.coffee index 9ff1b77..e7a3905 100644 --- a/src/beautifiers/sqlformat.coffee +++ b/src/beautifiers/sqlformat.coffee @@ -6,19 +6,19 @@ Requires https://github.com/andialbrecht/sqlparse Beautifier = require('./beautifier') module.exports = class sqlformat extends Beautifier - name: "sqlformat" + name: "sqlformat" - options: { - SQL: true - } + options: { + SQL: true + } - beautify: (text, language, options) -> - @run("sqlformat", [ - @tempFile("input", text) - "--reindent" - "--indent_width=#{options.indent_size}" if options.indent_size? - "--keywords=#{options.keywords}" if options.keywords? - "--identifiers=#{options.identifiers}" if options.identifiers? - ], help: { - link: "https://github.com/andialbrecht/sqlparse" - }) + beautify: (text, language, options) -> + @run("sqlformat", [ + @tempFile("input", text) + "--reindent" + "--indent_width=#{options.indent_size}" if options.indent_size? + "--keywords=#{options.keywords}" if options.keywords? + "--identifiers=#{options.identifiers}" if options.identifiers? + ], help: { + link: "https://github.com/andialbrecht/sqlparse" + }) diff --git a/src/beautifiers/tidy-markdown.coffee b/src/beautifiers/tidy-markdown.coffee index c21830d..f666e06 100644 --- a/src/beautifiers/tidy-markdown.coffee +++ b/src/beautifiers/tidy-markdown.coffee @@ -2,14 +2,14 @@ Beautifier = require('./beautifier') module.exports = class TidyMarkdown extends Beautifier - name: "Tidy Markdown" - options: { - Markdown: false - } + name: "Tidy Markdown" + options: { + Markdown: false + } - beautify: (text, language, options) -> - return new @Promise((resolve, reject) -> - tidyMarkdown = require 'tidy-markdown' - cleanMarkdown = tidyMarkdown(text) - resolve(cleanMarkdown) - ) + beautify: (text, language, options) -> + return new @Promise((resolve, reject) -> + tidyMarkdown = require 'tidy-markdown' + cleanMarkdown = tidyMarkdown(text) + resolve(cleanMarkdown) + ) diff --git a/src/beautifiers/typescript-formatter.coffee b/src/beautifiers/typescript-formatter.coffee index 90705f3..9be5bc8 100644 --- a/src/beautifiers/typescript-formatter.coffee +++ b/src/beautifiers/typescript-formatter.coffee @@ -2,28 +2,28 @@ Beautifier = require('./beautifier') module.exports = class TypeScriptFormatter extends Beautifier - name: "TypeScript Formatter" - options: { - TypeScript: true - } + name: "TypeScript Formatter" + options: { + TypeScript: true + } - beautify: (text, language, options) -> - return new @Promise((resolve, reject) => + beautify: (text, language, options) -> + return new @Promise((resolve, reject) => - format = require("typescript-formatter/lib/formatter") - formatterUtils = require("typescript-formatter/lib/utils") + format = require("typescript-formatter/lib/formatter") + formatterUtils = require("typescript-formatter/lib/utils") - opts = formatterUtils.createDefaultFormatCodeOptions() - opts.TabSize = options.tab_width or options.indent_size - opts.IndentSize = options.indent_size - opts.IndentStyle = 'space' - opts.convertTabsToSpaces = true - @verbose('typescript', text, opts) - try - result = format(text, opts) - @verbose(result) - resolve result - catch e - return reject(e) + opts = formatterUtils.createDefaultFormatCodeOptions() + opts.TabSize = options.tab_width or options.indent_size + opts.IndentSize = options.indent_size + opts.IndentStyle = 'space' + opts.convertTabsToSpaces = true + @verbose('typescript', text, opts) + try + result = format(text, opts) + @verbose(result) + resolve result + catch e + return reject(e) - ) + ) diff --git a/src/beautifiers/uncrustify/cfg.coffee b/src/beautifiers/uncrustify/cfg.coffee index de4aa41..57219aa 100644 --- a/src/beautifiers/uncrustify/cfg.coffee +++ b/src/beautifiers/uncrustify/cfg.coffee @@ -65,11 +65,11 @@ module.exports = (options, cb) -> fs.write info.fd, text or "", (err) -> # console.log(err); - return cb(err) if err + return cb(err) if err fs.close info.fd, (err) -> # console.log(err); - return cb(err) if err + return cb(err) if err cb null, info.path diff --git a/src/beautifiers/uncrustify/index.coffee b/src/beautifiers/uncrustify/index.coffee index c4e45a5..3f359da 100644 --- a/src/beautifiers/uncrustify/index.coffee +++ b/src/beautifiers/uncrustify/index.coffee @@ -9,76 +9,76 @@ expandHomeDir = require('expand-home-dir') _ = require('lodash') module.exports = class Uncrustify extends Beautifier - name: "Uncrustify" - options: { - C: true - "C++": true - "C#": true - "Objective-C": true - D: true - Pawn: true - Vala: true - Java: true - } + name: "Uncrustify" + options: { + C: true + "C++": true + "C#": true + "Objective-C": true + D: true + Pawn: true + Vala: true + Java: true + } - beautify: (text, language, options) -> - # console.log('uncrustify.beautify', language, options) - return new @Promise((resolve, reject) => - configPath = options.configPath - unless configPath - # No custom config path - cfg options, (error, cPath) -> - throw error if error - resolve cPath - else - # Has custom config path - editor = atom.workspace.getActiveTextEditor() - if editor? - basePath = path.dirname(editor.getPath()) - # console.log(basePath); - configPath = path.resolve(basePath, configPath) - resolve configPath - else - reject(new Error("No Uncrustify Config Path set! Please configure Uncrustify with Atom Beautify.")) - ) - .then((configPath) => - - # Expand Home Directory in Config Path - configPath = expandHomeDir(configPath) - - # Select Uncrustify language - lang = "C" # Default is C - switch language - when "C" - lang = "C" - when "C++" - lang = "CPP" - when "C#" - lang = "CS" - when "Objective-C", "Objective-C++" - lang = "OC+" - when "D" - lang = "D" - when "Pawn" - lang = "PAWN" - when "Vala" - lang = "VALA" - when "Java" - lang = "JAVA" - - @run("uncrustify", [ - "-c" - configPath - "-f" - @tempFile("input", text) - "-o" - outputFile = @tempFile("output", text) - "-l" - lang - ], help: { - link: "http://sourceforge.net/projects/uncrustify/" - }) - .then(=> - @readFile(outputFile) - ) + beautify: (text, language, options) -> + # console.log('uncrustify.beautify', language, options) + return new @Promise((resolve, reject) => + configPath = options.configPath + unless configPath + # No custom config path + cfg options, (error, cPath) -> + throw error if error + resolve cPath + else + # Has custom config path + editor = atom.workspace.getActiveTextEditor() + if editor? + basePath = path.dirname(editor.getPath()) + # console.log(basePath); + configPath = path.resolve(basePath, configPath) + resolve configPath + else + reject(new Error("No Uncrustify Config Path set! Please configure Uncrustify with Atom Beautify.")) + ) + .then((configPath) => + + # Expand Home Directory in Config Path + configPath = expandHomeDir(configPath) + + # Select Uncrustify language + lang = "C" # Default is C + switch language + when "C" + lang = "C" + when "C++" + lang = "CPP" + when "C#" + lang = "CS" + when "Objective-C", "Objective-C++" + lang = "OC+" + when "D" + lang = "D" + when "Pawn" + lang = "PAWN" + when "Vala" + lang = "VALA" + when "Java" + lang = "JAVA" + + @run("uncrustify", [ + "-c" + configPath + "-f" + @tempFile("input", text) + "-o" + outputFile = @tempFile("output", text) + "-l" + lang + ], help: { + link: "http://sourceforge.net/projects/uncrustify/" + }) + .then(=> + @readFile(outputFile) ) + ) diff --git a/src/beautifiers/uncrustify/possible-options.json b/src/beautifiers/uncrustify/possible-options.json index d7e73ab..9415a8f 100644 --- a/src/beautifiers/uncrustify/possible-options.json +++ b/src/beautifiers/uncrustify/possible-options.json @@ -1 +1,145 @@ -["newlines","input_tab_size","output_tab_size","string_escape_char","string_escape_char2","tok_split_gte","utf8_bom","utf8_byte","utf8_force","indent_columns","indent_continue","indent_with_tabs","indent_cmt_with_tabs","indent_align_string","indent_xml_string","indent_brace","indent_braces","indent_braces_no_func","indent_braces_no_class","indent_braces_no_struct","indent_brace_parent","indent_namespace","indent_namespace_level","indent_namespace_limit","indent_extern","indent_class","indent_class_colon","indent_ctor_init_leading","indent_ctor_init","indent_else_if","indent_var_def_blk","indent_var_def_cont","indent_func_def_force_col1","indent_func_call_param","indent_func_def_param","indent_func_proto_param","indent_func_class_param","indent_func_ctor_var_param","indent_template_param","indent_func_param_double","indent_func_const","indent_func_throw","indent_member","indent_sing_line_comments","indent_relative_single_line_comments","indent_switch_case","indent_case_shift","indent_case_brace","indent_col1_comment","indent_label","indent_access_spec","indent_access_spec_body","indent_paren_nl","indent_paren_close","indent_comma_paren","indent_bool_paren","indent_first_bool_expr","indent_square_nl","indent_preserve_sql","indent_align_assign","indent_oc_block","indent_oc_block_msg","indent_oc_msg_colon","sp_arith","sp_assign","sp_cpp_lambda_assign","sp_cpp_lambda_paren","sp_assign_default","sp_before_assign","sp_after_assign","sp_enum_assign","sp_enum_before_assign","sp_enum_after_assign","sp_pp_concat","sp_pp_stringify","sp_before_pp_stringify","sp_bool","sp_compare","sp_inside_paren","sp_paren_paren","sp_balance_nested_parens","sp_paren_brace","sp_before_ptr_star","sp_before_unnamed_ptr_star","sp_between_ptr_star","sp_after_ptr_star","sp_after_ptr_star_func","sp_ptr_star_paren","sp_before_ptr_star_func","sp_before_byref","sp_before_unnamed_byref","sp_after_byref","sp_after_byref_func","sp_before_byref_func","sp_after_type","sp_before_template_paren","sp_template_angle","sp_before_angle","sp_inside_angle","sp_after_angle","sp_angle_paren","sp_angle_word","sp_angle_shift","sp_permit_cpp11_shift","sp_before_sparen","sp_inside_sparen","sp_inside_sparen_close","sp_inside_sparen_open","sp_after_sparen","sp_sparen_brace","sp_invariant_paren","sp_after_invariant_paren","sp_special_semi","sp_before_semi","sp_before_semi_for","sp_before_semi_for_empty","sp_after_semi","sp_after_semi_for","sp_after_semi_for_empty","sp_before_square","sp_before_squares","sp_inside_square","sp_after_comma","sp_before_comma","sp_paren_comma","sp_before_ellipsis","sp_after_class_colon","sp_before_class_colon","sp_before_case_colon","sp_after_operator","sp_after_operator_sym","sp_after_cast","sp_inside_paren_cast","sp_cpp_cast_paren","sp_sizeof_paren","sp_after_tag","sp_inside_braces_enum","sp_inside_braces_struct","sp_inside_braces","sp_inside_braces_empty","sp_type_func","sp_func_proto_paren","sp_func_def_paren","sp_inside_fparens","sp_inside_fparen","sp_inside_tparen","sp_after_tparen_close","sp_square_fparen","sp_fparen_brace","sp_func_call_paren","sp_func_call_paren_empty","sp_func_call_user_paren","sp_func_class_paren","sp_return_paren","sp_attribute_paren","sp_defined_paren","sp_throw_paren","sp_after_throw","sp_catch_paren","sp_version_paren","sp_scope_paren","sp_macro","sp_macro_func","sp_else_brace","sp_brace_else","sp_brace_typedef","sp_catch_brace","sp_brace_catch","sp_finally_brace","sp_brace_finally","sp_try_brace","sp_getset_brace","sp_before_dc","sp_after_dc","sp_d_array_colon","sp_not","sp_inv","sp_addr","sp_member","sp_deref","sp_sign","sp_incdec","sp_before_nl_cont","sp_after_oc_scope","sp_after_oc_colon","sp_before_oc_colon","sp_after_oc_dict_colon","sp_before_oc_dict_colon","sp_after_send_oc_colon","sp_before_send_oc_colon","sp_after_oc_type","sp_after_oc_return_type","sp_after_oc_at_sel","sp_after_oc_at_sel_parens","sp_inside_oc_at_sel_parens","sp_before_oc_block_caret","sp_after_oc_block_caret","sp_after_oc_msg_receiver","sp_after_oc_property","sp_cond_colon","sp_cond_question","sp_case_label","sp_range","sp_after_for_colon","sp_before_for_colon","sp_extern_paren","sp_cmt_cpp_start","sp_endif_cmt","sp_after_new","sp_before_tr_emb_cmt","sp_num_before_tr_emb_cmt","sp_annotation_paren","align_keep_tabs","align_with_tabs","align_on_tabstop","align_number_left","align_func_params","align_same_func_call_params","align_var_def_span","align_var_def_star_style","align_var_def_amp_style","align_var_def_thresh","align_var_def_gap","align_var_def_colon","align_var_def_attribute","align_var_def_inline","align_assign_span","align_assign_thresh","align_enum_equ_span","align_enum_equ_thresh","align_var_struct_span","align_var_struct_thresh","align_var_struct_gap","align_struct_init_span","align_typedef_gap","align_typedef_span","align_typedef_func","align_typedef_star_style","align_typedef_amp_style","align_right_cmt_span","align_right_cmt_mix","align_right_cmt_gap","align_right_cmt_at_col","align_func_proto_span","align_func_proto_gap","align_on_operator","align_mix_var_proto","align_single_line_func","align_single_line_brace","align_single_line_brace_gap","align_oc_msg_spec_span","align_nl_cont","align_pp_define_together","align_pp_define_gap","align_pp_define_span","align_left_shift","align_oc_msg_colon_span","align_oc_msg_colon_first","align_oc_decl_colon","nl_collapse_empty_body","nl_assign_leave_one_liners","nl_class_leave_one_liners","nl_enum_leave_one_liners","nl_getset_leave_one_liners","nl_func_leave_one_liners","nl_if_leave_one_liners","nl_oc_msg_leave_one_liner","nl_start_of_file","nl_start_of_file_min","nl_end_of_file","nl_end_of_file_min","nl_assign_brace","nl_assign_square","nl_after_square_assign","nl_func_var_def_blk","nl_typedef_blk_start","nl_typedef_blk_end","nl_typedef_blk_in","nl_var_def_blk_start","nl_var_def_blk_end","nl_var_def_blk_in","nl_fcall_brace","nl_enum_brace","nl_struct_brace","nl_union_brace","nl_if_brace","nl_brace_else","nl_elseif_brace","nl_else_brace","nl_else_if","nl_brace_finally","nl_finally_brace","nl_try_brace","nl_getset_brace","nl_for_brace","nl_catch_brace","nl_brace_catch","nl_while_brace","nl_scope_brace","nl_unittest_brace","nl_version_brace","nl_using_brace","nl_brace_brace","nl_do_brace","nl_brace_while","nl_switch_brace","nl_multi_line_cond","nl_multi_line_define","nl_before_case","nl_before_throw","nl_after_case","nl_case_colon_brace","nl_namespace_brace","nl_template_class","nl_class_brace","nl_class_init_args","nl_func_type_name","nl_func_type_name_class","nl_func_scope_name","nl_func_proto_type_name","nl_func_paren","nl_func_def_paren","nl_func_decl_start","nl_func_def_start","nl_func_decl_start_single","nl_func_def_start_single","nl_func_decl_args","nl_func_def_args","nl_func_decl_end","nl_func_def_end","nl_func_decl_end_single","nl_func_def_end_single","nl_func_decl_empty","nl_func_def_empty","nl_oc_msg_args","nl_fdef_brace","nl_return_expr","nl_after_semicolon","nl_after_brace_open","nl_after_brace_open_cmt","nl_after_vbrace_open","nl_after_vbrace_open_empty","nl_after_brace_close","nl_after_vbrace_close","nl_brace_struct_var","nl_define_macro","nl_squeeze_ifdef","nl_before_if","nl_after_if","nl_before_for","nl_after_for","nl_before_while","nl_after_while","nl_before_switch","nl_after_switch","nl_before_do","nl_after_do","nl_ds_struct_enum_cmt","nl_ds_struct_enum_close_brace","nl_class_colon","nl_create_if_one_liner","nl_create_for_one_liner","nl_create_while_one_liner","pos_arith","pos_assign","pos_bool","pos_compare","pos_conditional","pos_comma","pos_class_comma","pos_class_colon","code_width","ls_for_split_full","ls_func_split_full","ls_code_width","nl_max","nl_after_func_proto","nl_after_func_proto_group","nl_after_func_body","nl_after_func_body_class","nl_after_func_body_one_liner","nl_before_block_comment","nl_before_c_comment","nl_before_cpp_comment","nl_after_multiline_comment","nl_after_struct","nl_after_class","nl_before_access_spec","nl_after_access_spec","nl_comment_func_def","nl_after_try_catch_finally","nl_around_cs_property","nl_between_get_set","nl_property_brace","eat_blanks_after_open_brace","eat_blanks_before_close_brace","nl_remove_extra_newlines","nl_before_return","nl_after_return","nl_after_annotation","nl_between_annotation","mod_full_brace_do","mod_full_brace_for","mod_full_brace_function","mod_full_brace_if","mod_full_brace_if_chain","mod_full_brace_nl","mod_full_brace_while","mod_full_brace_using","mod_paren_on_return","mod_pawn_semicolon","mod_full_paren_if_bool","mod_remove_extra_semicolon","mod_add_long_function_closebrace_comment","mod_add_long_switch_closebrace_comment","mod_add_long_ifdef_endif_comment","mod_add_long_ifdef_else_comment","mod_sort_import","mod_sort_using","mod_sort_include","mod_move_case_break","mod_case_brace","mod_remove_empty_return","cmt_width","cmt_reflow_mode","cmt_indent_multi","cmt_c_group","cmt_c_nl_start","cmt_c_nl_end","cmt_cpp_group","cmt_cpp_nl_start","cmt_cpp_nl_end","cmt_cpp_to_c","cmt_star_cont","cmt_sp_before_star_cont","cmt_sp_after_star_cont","cmt_multi_check_last","cmt_insert_file_header","cmt_insert_file_footer","cmt_insert_func_header","cmt_insert_class_header","cmt_insert_oc_msg_header","cmt_insert_before_preproc","pp_indent","pp_indent_at_level","pp_indent_count","pp_space","pp_space_count","pp_indent_region","pp_region_indent_code","pp_indent_if","pp_if_indent_code","pp_define_at_level"] +["newlines", "input_tab_size", "output_tab_size", "string_escape_char", + "string_escape_char2", "tok_split_gte", "utf8_bom", "utf8_byte", "utf8_force", + "indent_columns", "indent_continue", "indent_with_tabs", + "indent_cmt_with_tabs", "indent_align_string", "indent_xml_string", + "indent_brace", "indent_braces", "indent_braces_no_func", + "indent_braces_no_class", "indent_braces_no_struct", "indent_brace_parent", + "indent_namespace", "indent_namespace_level", "indent_namespace_limit", + "indent_extern", "indent_class", "indent_class_colon", + "indent_ctor_init_leading", "indent_ctor_init", "indent_else_if", + "indent_var_def_blk", "indent_var_def_cont", "indent_func_def_force_col1", + "indent_func_call_param", "indent_func_def_param", "indent_func_proto_param", + "indent_func_class_param", "indent_func_ctor_var_param", + "indent_template_param", "indent_func_param_double", "indent_func_const", + "indent_func_throw", "indent_member", "indent_sing_line_comments", + "indent_relative_single_line_comments", "indent_switch_case", + "indent_case_shift", "indent_case_brace", "indent_col1_comment", + "indent_label", "indent_access_spec", "indent_access_spec_body", + "indent_paren_nl", "indent_paren_close", "indent_comma_paren", + "indent_bool_paren", "indent_first_bool_expr", "indent_square_nl", + "indent_preserve_sql", "indent_align_assign", "indent_oc_block", + "indent_oc_block_msg", "indent_oc_msg_colon", "sp_arith", "sp_assign", + "sp_cpp_lambda_assign", "sp_cpp_lambda_paren", "sp_assign_default", + "sp_before_assign", "sp_after_assign", "sp_enum_assign", + "sp_enum_before_assign", "sp_enum_after_assign", "sp_pp_concat", + "sp_pp_stringify", "sp_before_pp_stringify", "sp_bool", "sp_compare", + "sp_inside_paren", "sp_paren_paren", "sp_balance_nested_parens", + "sp_paren_brace", "sp_before_ptr_star", "sp_before_unnamed_ptr_star", + "sp_between_ptr_star", "sp_after_ptr_star", "sp_after_ptr_star_func", + "sp_ptr_star_paren", "sp_before_ptr_star_func", "sp_before_byref", + "sp_before_unnamed_byref", "sp_after_byref", "sp_after_byref_func", + "sp_before_byref_func", "sp_after_type", "sp_before_template_paren", + "sp_template_angle", "sp_before_angle", "sp_inside_angle", "sp_after_angle", + "sp_angle_paren", "sp_angle_word", "sp_angle_shift", "sp_permit_cpp11_shift", + "sp_before_sparen", "sp_inside_sparen", "sp_inside_sparen_close", + "sp_inside_sparen_open", "sp_after_sparen", "sp_sparen_brace", + "sp_invariant_paren", "sp_after_invariant_paren", "sp_special_semi", + "sp_before_semi", "sp_before_semi_for", "sp_before_semi_for_empty", + "sp_after_semi", "sp_after_semi_for", "sp_after_semi_for_empty", + "sp_before_square", "sp_before_squares", "sp_inside_square", "sp_after_comma", + "sp_before_comma", "sp_paren_comma", "sp_before_ellipsis", + "sp_after_class_colon", "sp_before_class_colon", "sp_before_case_colon", + "sp_after_operator", "sp_after_operator_sym", "sp_after_cast", + "sp_inside_paren_cast", "sp_cpp_cast_paren", "sp_sizeof_paren", + "sp_after_tag", "sp_inside_braces_enum", "sp_inside_braces_struct", + "sp_inside_braces", "sp_inside_braces_empty", "sp_type_func", + "sp_func_proto_paren", "sp_func_def_paren", "sp_inside_fparens", + "sp_inside_fparen", "sp_inside_tparen", "sp_after_tparen_close", + "sp_square_fparen", "sp_fparen_brace", "sp_func_call_paren", + "sp_func_call_paren_empty", "sp_func_call_user_paren", "sp_func_class_paren", + "sp_return_paren", "sp_attribute_paren", "sp_defined_paren", "sp_throw_paren", + "sp_after_throw", "sp_catch_paren", "sp_version_paren", "sp_scope_paren", + "sp_macro", "sp_macro_func", "sp_else_brace", "sp_brace_else", + "sp_brace_typedef", "sp_catch_brace", "sp_brace_catch", "sp_finally_brace", + "sp_brace_finally", "sp_try_brace", "sp_getset_brace", "sp_before_dc", + "sp_after_dc", "sp_d_array_colon", "sp_not", "sp_inv", "sp_addr", "sp_member", + "sp_deref", "sp_sign", "sp_incdec", "sp_before_nl_cont", "sp_after_oc_scope", + "sp_after_oc_colon", "sp_before_oc_colon", "sp_after_oc_dict_colon", + "sp_before_oc_dict_colon", "sp_after_send_oc_colon", + "sp_before_send_oc_colon", "sp_after_oc_type", "sp_after_oc_return_type", + "sp_after_oc_at_sel", "sp_after_oc_at_sel_parens", + "sp_inside_oc_at_sel_parens", "sp_before_oc_block_caret", + "sp_after_oc_block_caret", "sp_after_oc_msg_receiver", "sp_after_oc_property", + "sp_cond_colon", "sp_cond_question", "sp_case_label", "sp_range", + "sp_after_for_colon", "sp_before_for_colon", "sp_extern_paren", + "sp_cmt_cpp_start", "sp_endif_cmt", "sp_after_new", "sp_before_tr_emb_cmt", + "sp_num_before_tr_emb_cmt", "sp_annotation_paren", "align_keep_tabs", + "align_with_tabs", "align_on_tabstop", "align_number_left", + "align_func_params", "align_same_func_call_params", "align_var_def_span", + "align_var_def_star_style", "align_var_def_amp_style", "align_var_def_thresh", + "align_var_def_gap", "align_var_def_colon", "align_var_def_attribute", + "align_var_def_inline", "align_assign_span", "align_assign_thresh", + "align_enum_equ_span", "align_enum_equ_thresh", "align_var_struct_span", + "align_var_struct_thresh", "align_var_struct_gap", "align_struct_init_span", + "align_typedef_gap", "align_typedef_span", "align_typedef_func", + "align_typedef_star_style", "align_typedef_amp_style", "align_right_cmt_span", + "align_right_cmt_mix", "align_right_cmt_gap", "align_right_cmt_at_col", + "align_func_proto_span", "align_func_proto_gap", "align_on_operator", + "align_mix_var_proto", "align_single_line_func", "align_single_line_brace", + "align_single_line_brace_gap", "align_oc_msg_spec_span", "align_nl_cont", + "align_pp_define_together", "align_pp_define_gap", "align_pp_define_span", + "align_left_shift", "align_oc_msg_colon_span", "align_oc_msg_colon_first", + "align_oc_decl_colon", "nl_collapse_empty_body", "nl_assign_leave_one_liners", + "nl_class_leave_one_liners", "nl_enum_leave_one_liners", + "nl_getset_leave_one_liners", "nl_func_leave_one_liners", + "nl_if_leave_one_liners", "nl_oc_msg_leave_one_liner", "nl_start_of_file", + "nl_start_of_file_min", "nl_end_of_file", "nl_end_of_file_min", + "nl_assign_brace", "nl_assign_square", "nl_after_square_assign", + "nl_func_var_def_blk", "nl_typedef_blk_start", "nl_typedef_blk_end", + "nl_typedef_blk_in", "nl_var_def_blk_start", "nl_var_def_blk_end", + "nl_var_def_blk_in", "nl_fcall_brace", "nl_enum_brace", "nl_struct_brace", + "nl_union_brace", "nl_if_brace", "nl_brace_else", "nl_elseif_brace", + "nl_else_brace", "nl_else_if", "nl_brace_finally", "nl_finally_brace", + "nl_try_brace", "nl_getset_brace", "nl_for_brace", "nl_catch_brace", + "nl_brace_catch", "nl_while_brace", "nl_scope_brace", "nl_unittest_brace", + "nl_version_brace", "nl_using_brace", "nl_brace_brace", "nl_do_brace", + "nl_brace_while", "nl_switch_brace", "nl_multi_line_cond", + "nl_multi_line_define", "nl_before_case", "nl_before_throw", "nl_after_case", + "nl_case_colon_brace", "nl_namespace_brace", "nl_template_class", + "nl_class_brace", "nl_class_init_args", "nl_func_type_name", + "nl_func_type_name_class", "nl_func_scope_name", "nl_func_proto_type_name", + "nl_func_paren", "nl_func_def_paren", "nl_func_decl_start", + "nl_func_def_start", "nl_func_decl_start_single", "nl_func_def_start_single", + "nl_func_decl_args", "nl_func_def_args", "nl_func_decl_end", + "nl_func_def_end", "nl_func_decl_end_single", "nl_func_def_end_single", + "nl_func_decl_empty", "nl_func_def_empty", "nl_oc_msg_args", "nl_fdef_brace", + "nl_return_expr", "nl_after_semicolon", "nl_after_brace_open", + "nl_after_brace_open_cmt", "nl_after_vbrace_open", + "nl_after_vbrace_open_empty", "nl_after_brace_close", "nl_after_vbrace_close", + "nl_brace_struct_var", "nl_define_macro", "nl_squeeze_ifdef", "nl_before_if", + "nl_after_if", "nl_before_for", "nl_after_for", "nl_before_while", + "nl_after_while", "nl_before_switch", "nl_after_switch", "nl_before_do", + "nl_after_do", "nl_ds_struct_enum_cmt", "nl_ds_struct_enum_close_brace", + "nl_class_colon", "nl_create_if_one_liner", "nl_create_for_one_liner", + "nl_create_while_one_liner", "pos_arith", "pos_assign", "pos_bool", + "pos_compare", "pos_conditional", "pos_comma", "pos_class_comma", + "pos_class_colon", "code_width", "ls_for_split_full", "ls_func_split_full", + "ls_code_width", "nl_max", "nl_after_func_proto", "nl_after_func_proto_group", + "nl_after_func_body", "nl_after_func_body_class", + "nl_after_func_body_one_liner", "nl_before_block_comment", + "nl_before_c_comment", "nl_before_cpp_comment", "nl_after_multiline_comment", + "nl_after_struct", "nl_after_class", "nl_before_access_spec", + "nl_after_access_spec", "nl_comment_func_def", "nl_after_try_catch_finally", + "nl_around_cs_property", "nl_between_get_set", "nl_property_brace", + "eat_blanks_after_open_brace", "eat_blanks_before_close_brace", + "nl_remove_extra_newlines", "nl_before_return", "nl_after_return", + "nl_after_annotation", "nl_between_annotation", "mod_full_brace_do", + "mod_full_brace_for", "mod_full_brace_function", "mod_full_brace_if", + "mod_full_brace_if_chain", "mod_full_brace_nl", "mod_full_brace_while", + "mod_full_brace_using", "mod_paren_on_return", "mod_pawn_semicolon", + "mod_full_paren_if_bool", "mod_remove_extra_semicolon", + "mod_add_long_function_closebrace_comment", + "mod_add_long_switch_closebrace_comment", "mod_add_long_ifdef_endif_comment", + "mod_add_long_ifdef_else_comment", "mod_sort_import", "mod_sort_using", + "mod_sort_include", "mod_move_case_break", "mod_case_brace", + "mod_remove_empty_return", "cmt_width", "cmt_reflow_mode", "cmt_indent_multi", + "cmt_c_group", "cmt_c_nl_start", "cmt_c_nl_end", "cmt_cpp_group", + "cmt_cpp_nl_start", "cmt_cpp_nl_end", "cmt_cpp_to_c", "cmt_star_cont", + "cmt_sp_before_star_cont", "cmt_sp_after_star_cont", "cmt_multi_check_last", + "cmt_insert_file_header", "cmt_insert_file_footer", "cmt_insert_func_header", + "cmt_insert_class_header", "cmt_insert_oc_msg_header", + "cmt_insert_before_preproc", "pp_indent", "pp_indent_at_level", + "pp_indent_count", "pp_space", "pp_space_count", "pp_indent_region", + "pp_region_indent_code", "pp_indent_if", "pp_if_indent_code", + "pp_define_at_level" +] \ No newline at end of file diff --git a/src/languages/c-sharp.coffee b/src/languages/c-sharp.coffee index b947412..4aa7a82 100644 --- a/src/languages/c-sharp.coffee +++ b/src/languages/c-sharp.coffee @@ -1,27 +1,27 @@ module.exports = { - name: "C#" - namespace: "cs" + name: "C#" + namespace: "cs" - ### - Supported Grammars - ### - grammars: [ - "C#" - ] + ### + Supported Grammars + ### + grammars: [ + "C#" + ] - ### - Supported extensions - ### - extensions: [ - 'cs' - ] + ### + Supported extensions + ### + extensions: [ + 'cs' + ] - options: - configPath: - title: "Config Path" - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + title: "Config Path" + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/c.coffee b/src/languages/c.coffee index 914c39c..a2b3296 100644 --- a/src/languages/c.coffee +++ b/src/languages/c.coffee @@ -1,26 +1,26 @@ module.exports = { - name: "C" - namespace: "c" + name: "C" + namespace: "c" - ### - Supported Grammars - ### - grammars: [ - "C" - ] + ### + Supported Grammars + ### + grammars: [ + "C" + ] - ### - Supported extensions - ### - extensions: [ - "c" - ] + ### + Supported extensions + ### + extensions: [ + "c" + ] - options: - configPath: - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/coffeescript.coffee b/src/languages/coffeescript.coffee index f166430..2d930a4 100644 --- a/src/languages/coffeescript.coffee +++ b/src/languages/coffeescript.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "CoffeeScript" - namespace: "coffeescript" - fallback: ['js'] + name: "CoffeeScript" + namespace: "coffeescript" + fallback: ['js'] - ### - Supported Grammars - ### - grammars: [ - "CoffeeScript" - ] + ### + Supported Grammars + ### + grammars: [ + "CoffeeScript" + ] - ### - Supported extensions - ### - extensions: [ - "coffee" - ] + ### + Supported extensions + ### + extensions: [ + "coffee" + ] - defaultBeautifier: "coffee-fmt" + defaultBeautifier: "coffee-fmt" -} \ No newline at end of file +} diff --git a/src/languages/cpp.coffee b/src/languages/cpp.coffee index 80a4709..6f7c6f8 100644 --- a/src/languages/cpp.coffee +++ b/src/languages/cpp.coffee @@ -1,36 +1,36 @@ module.exports = { - name: "C++" - namespace: "cpp" + name: "C++" + namespace: "cpp" - ### - Supported Grammars - ### - grammars: [ - "C++" - ] + ### + Supported Grammars + ### + grammars: [ + "C++" + ] - ### - Supported extensions - ### - extensions: [ - "h" - "hh" - "cc" - "cpp" - "cxx" - "C" - "c++" - "hpp" - "hxx" - "h++" - ] + ### + Supported extensions + ### + extensions: [ + "h" + "hh" + "cc" + "cpp" + "cxx" + "C" + "c++" + "hpp" + "hxx" + "h++" + ] - options: - configPath: - title: "Config Path" - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + title: "Config Path" + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/css.coffee b/src/languages/css.coffee index 6e37f03..ff75dcf 100644 --- a/src/languages/css.coffee +++ b/src/languages/css.coffee @@ -7,75 +7,75 @@ defaultIndentWithTabs = not softTabs module.exports = { - name: "CSS" - namespace: "css" + name: "CSS" + namespace: "css" - ### - Supported Grammars - ### - grammars: [ - "CSS" - ] + ### + Supported Grammars + ### + grammars: [ + "CSS" + ] - ### - Supported extensions - ### - extensions: [ - "css" - ] + ### + Supported extensions + ### + extensions: [ + "css" + ] - defaultBeautifier: "JS Beautify" + defaultBeautifier: "JS Beautify" - options: - # CSS - indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indentation size/length" - indent_char: - type: 'string' - default: defaultIndentChar - minimum: 0 - description: "Indentation character" - selector_separator_newline: - type: 'boolean' - default: false - description: "Add a newline between multiple selectors" - newline_between_rules: - type: 'boolean' - default: false - description: "Add a newline between CSS rules" - preserve_newlines: - type: 'boolean' - default: false - description: "Retain empty lines. "+ - "Consecutive empty lines will be converted to \ + options: + # CSS + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + indent_char: + type: 'string' + default: defaultIndentChar + minimum: 0 + description: "Indentation character" + selector_separator_newline: + type: 'boolean' + default: false + description: "Add a newline between multiple selectors" + newline_between_rules: + type: 'boolean' + default: false + description: "Add a newline between CSS rules" + preserve_newlines: + type: 'boolean' + default: false + description: "Retain empty lines. "+ + "Consecutive empty lines will be converted to \ a single empty line." - wrap_line_length: - type: 'integer' - default: 0 - description: "Maximum amount of characters per line (0 = disable)" - indent_comments: - type: 'boolean' - default: true - description: "Determines whether comments should be indented." - force_indentation: - type: 'boolean' - default: false - description: "if indentation should be forcefully applied to\ + wrap_line_length: + type: 'integer' + default: 0 + description: "Maximum amount of characters per line (0 = disable)" + indent_comments: + type: 'boolean' + default: true + description: "Determines whether comments should be indented." + force_indentation: + type: 'boolean' + default: false + description: "if indentation should be forcefully applied to\ markup even if it disruptively adds unintended whitespace \ to the documents rendered output" - convert_quotes: - type: 'string' - default: "none" - description: "Convert the quote characters delimiting strings \ + convert_quotes: + type: 'string' + default: "none" + description: "Convert the quote characters delimiting strings \ from either double or single quotes to the other." - enum: ["none", "double", "single"] - align_assignments: - type: 'boolean' - default: false - description: "If lists of assignments or properties should be \ + enum: ["none", "double", "single"] + align_assignments: + type: 'boolean' + default: false + description: "If lists of assignments or properties should be \ vertically aligned for faster and easier reading." -} \ No newline at end of file +} diff --git a/src/languages/csv.coffee b/src/languages/csv.coffee index a05dac3..3326167 100644 --- a/src/languages/csv.coffee +++ b/src/languages/csv.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "CSV" - description: "Comma-Separated Values" - namespace: "csv" + name: "CSV" + description: "Comma-Separated Values" + namespace: "csv" - ### - Supported Grammars - ### - grammars: [ - "CSV" - ] + ### + Supported Grammars + ### + grammars: [ + "CSV" + ] - ### - Supported extensions - ### - extensions: [ - 'csv' - ] + ### + Supported extensions + ### + extensions: [ + 'csv' + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/d.coffee b/src/languages/d.coffee index dcf2d8a..85ffa77 100644 --- a/src/languages/d.coffee +++ b/src/languages/d.coffee @@ -1,25 +1,25 @@ module.exports = { - name: "D" - namespace: "d" + name: "D" + namespace: "d" - ### - Supported Grammars - ### - grammars: [ - "D" - ] + ### + Supported Grammars + ### + grammars: [ + "D" + ] - ### - Supported extensions - ### - extensions: [ - ] + ### + Supported extensions + ### + extensions: [ + ] - options: - configPath: - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/ejs.coffee b/src/languages/ejs.coffee index 04faff0..1222064 100644 --- a/src/languages/ejs.coffee +++ b/src/languages/ejs.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "EJS" - description: "Embedded JavaScript" - namespace: "ejs" - fallback: ['html', 'js'] + name: "EJS" + description: "Embedded JavaScript" + namespace: "ejs" + fallback: ['html', 'js'] - ### - Supported Grammars - ### - grammars: [ - "JavaScript Template" - "HTML (Angular)" - ] + ### + Supported Grammars + ### + grammars: [ + "JavaScript Template" + "HTML (Angular)" + ] - ### - Supported extensions - ### - extensions: [] + ### + Supported extensions + ### + extensions: [] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/erb.coffee b/src/languages/erb.coffee index 925de50..46e75d0 100644 --- a/src/languages/erb.coffee +++ b/src/languages/erb.coffee @@ -1,26 +1,26 @@ module.exports = { - name: "ERB" - namespace: "erb" - fallback: ['html'] + name: "ERB" + namespace: "erb" + fallback: ['html'] - ### - Supported Grammars - ### - grammars: [ - "HTML (Ruby - ERB)" - "HTML (Rails)" - ] + ### + Supported Grammars + ### + grammars: [ + "HTML (Ruby - ERB)" + "HTML (Rails)" + ] - ### - Supported extensions - ### - extensions: [ - 'erb' - ] + ### + Supported extensions + ### + extensions: [ + 'erb' + ] - defaultBeautifier: "Pretty Diff" + defaultBeautifier: "Pretty Diff" - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/fortran.coffee b/src/languages/fortran.coffee index 16162a6..e2ba124 100644 --- a/src/languages/fortran.coffee +++ b/src/languages/fortran.coffee @@ -1,34 +1,34 @@ module.exports = { - name: "Fortran" - namespace: "fortran" + name: "Fortran" + namespace: "fortran" - ### - Supported Grammars - ### - grammars: [ - "Fortran - Modern" - ] + ### + Supported Grammars + ### + grammars: [ + "Fortran - Modern" + ] - ### - Supported extensions - ### - extensions: [ - "f90" - ] + ### + Supported extensions + ### + extensions: [ + "f90" + ] - ### - - ### - options: - # JavaScript - emacs_path: - type: 'string' - default: "" - description: "Path to the `emacs` executable" - emacs_script_path: - type: 'string' - default: "" - description: "Path to the emacs script" + ### + + ### + options: + # JavaScript + emacs_path: + type: 'string' + default: "" + description: "Path to the `emacs` executable" + emacs_script_path: + type: 'string' + default: "" + description: "Path to the emacs script" } diff --git a/src/languages/go.coffee b/src/languages/go.coffee index 174a029..39d4426 100644 --- a/src/languages/go.coffee +++ b/src/languages/go.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Go" - description: "Golang" - namespace: "go" + name: "Go" + description: "Golang" + namespace: "go" - ### - Supported Grammars - ### - grammars: [ - "Go" - ] + ### + Supported Grammars + ### + grammars: [ + "Go" + ] - ### - Supported extensions - ### - extensions: [ - "go" - ] + ### + Supported extensions + ### + extensions: [ + "go" + ] - options: [] - -} \ No newline at end of file + options: [] + +} diff --git a/src/languages/handlebars.coffee b/src/languages/handlebars.coffee index 64aed27..1cafdf1 100644 --- a/src/languages/handlebars.coffee +++ b/src/languages/handlebars.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Handlebars" - namespace: "handlebars" - fallback: ['html','mustache'] + name: "Handlebars" + namespace: "handlebars" + fallback: ['html','mustache'] - ### - Supported Grammars - ### - grammars: [ - "Handlebars" - ] + ### + Supported Grammars + ### + grammars: [ + "Handlebars" + ] - ### - Supported extensions - ### - extensions: [ - "hbs" - ] + ### + Supported extensions + ### + extensions: [ + "hbs" + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/html.coffee b/src/languages/html.coffee index d48e1ac..c6f117e 100644 --- a/src/languages/html.coffee +++ b/src/languages/html.coffee @@ -7,79 +7,79 @@ defaultIndentWithTabs = not softTabs module.exports = { - name: "HTML" - namespace: "html" + name: "HTML" + namespace: "html" - ### - Supported Grammars - ### - grammars: [ - "HTML" - ] + ### + Supported Grammars + ### + grammars: [ + "HTML" + ] - ### - Supported extensions - ### - extensions: [ - "html" - ] + ### + Supported extensions + ### + extensions: [ + "html" + ] - options: - indent_inner_html: - type: 'boolean' - default: false - description: "Indent and sections." - indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indentation size/length" - indent_char: - type: 'string' - default: defaultIndentChar - minimum: 0 - description: "Indentation character" - brace_style: - type: 'string' - default: "collapse" - enum: ["collapse", "expand", "end-expand", "none"] - description: "[collapse|expand|end-expand|none]" - indent_scripts: - type: 'string' - default: "normal" - enum: ["keep", "separate", "normal"] - description: "[keep|separate|normal]" - wrap_line_length: - type: 'integer' - default: 250 - description: "Maximum characters per line (0 disables)" - wrap_attributes: - type: 'string' - default: "auto" - enum: ["auto", "force"] - description: "Wrap attributes to new lines [auto|force]" - wrap_attributes_indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indent wrapped attributes to after N characters" - preserve_newlines: - type: 'boolean' - default: true - description: "Preserve line-breaks" - max_preserve_newlines: - type: 'integer' - default: 10 - description: "Number of line-breaks to be preserved in one chunk" - unformatted: - type: 'array' - default: ['a', 'sub', 'sup', 'b', 'i', 'u'] - items: - type: 'string' - description: "List of tags (defaults to inline) that should not be reformatted" - end_with_newline: - type: 'boolean' - default: false - description: "End output with newline" + options: + indent_inner_html: + type: 'boolean' + default: false + description: "Indent and sections." + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + indent_char: + type: 'string' + default: defaultIndentChar + minimum: 0 + description: "Indentation character" + brace_style: + type: 'string' + default: "collapse" + enum: ["collapse", "expand", "end-expand", "none"] + description: "[collapse|expand|end-expand|none]" + indent_scripts: + type: 'string' + default: "normal" + enum: ["keep", "separate", "normal"] + description: "[keep|separate|normal]" + wrap_line_length: + type: 'integer' + default: 250 + description: "Maximum characters per line (0 disables)" + wrap_attributes: + type: 'string' + default: "auto" + enum: ["auto", "force"] + description: "Wrap attributes to new lines [auto|force]" + wrap_attributes_indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indent wrapped attributes to after N characters" + preserve_newlines: + type: 'boolean' + default: true + description: "Preserve line-breaks" + max_preserve_newlines: + type: 'integer' + default: 10 + description: "Number of line-breaks to be preserved in one chunk" + unformatted: + type: 'array' + default: ['a', 'sub', 'sup', 'b', 'i', 'u'] + items: + type: 'string' + description: "List of tags (defaults to inline) that should not be reformatted" + end_with_newline: + type: 'boolean' + default: false + description: "End output with newline" -} \ No newline at end of file +} diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 5f35da7..86e8595 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -67,10 +67,10 @@ module.exports = class Languages Constructor ### constructor: -> - @languages = _.map(@languageNames, (name) -> - require("./#{name}") - ) - @namespaces = _.map(@languages, (language) -> language.namespace) + @languages = _.map(@languageNames, (name) -> + require("./#{name}") + ) + @namespaces = _.map(@languages, (language) -> language.namespace) ### Get language for grammar and extension @@ -78,8 +78,8 @@ module.exports = class Languages getLanguages: ({name, namespace, grammar, extension}) -> # console.log('getLanguages', name, namespace, grammar, extension, @languages) _.union( - _.filter(@languages, (language) -> _.isEqual(language.name, name)) - _.filter(@languages, (language) -> _.isEqual(language.namespace, namespace)) - _.filter(@languages, (language) -> _.contains(language.grammars, grammar)) - _.filter(@languages, (language) -> _.contains(language.extensions, extension)) + _.filter(@languages, (language) -> _.isEqual(language.name, name)) + _.filter(@languages, (language) -> _.isEqual(language.namespace, namespace)) + _.filter(@languages, (language) -> _.contains(language.grammars, grammar)) + _.filter(@languages, (language) -> _.contains(language.extensions, extension)) ) diff --git a/src/languages/java.coffee b/src/languages/java.coffee index bc73432..df37da2 100644 --- a/src/languages/java.coffee +++ b/src/languages/java.coffee @@ -1,26 +1,26 @@ module.exports = { - name: "Java" - namespace: "java" + name: "Java" + namespace: "java" - ### - Supported Grammars - ### - grammars: [ - "Java" - ] + ### + Supported Grammars + ### + grammars: [ + "Java" + ] - ### - Supported extensions - ### - extensions: [ - "java" - ] + ### + Supported extensions + ### + extensions: [ + "java" + ] - options: - configPath: - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/javascript.coffee b/src/languages/javascript.coffee index f9e507e..cb947ae 100644 --- a/src/languages/javascript.coffee +++ b/src/languages/javascript.coffee @@ -7,103 +7,103 @@ defaultIndentWithTabs = not softTabs module.exports = { - name: "JavaScript" - namespace: "js" + name: "JavaScript" + namespace: "js" - ### - Supported Grammars - ### - grammars: [ - "JavaScript" - ] + ### + Supported Grammars + ### + grammars: [ + "JavaScript" + ] - ### - Supported extensions - ### - extensions: [ - "js" - ] + ### + Supported extensions + ### + extensions: [ + "js" + ] - defaultBeautifier: "JS Beautify" + defaultBeautifier: "JS Beautify" - ### + ### + + ### + options: + # JavaScript + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + indent_char: + type: 'string' + default: defaultIndentChar + description: "Indentation character" + indent_level: + type: 'integer' + default: 0 + description: "Initial indentation level" + indent_with_tabs: + type: 'boolean' + default: defaultIndentWithTabs + description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`" + preserve_newlines: + type: 'boolean' + default: true + description: "Preserve line-breaks" + max_preserve_newlines: + type: 'integer' + default: 10 + description: "Number of line-breaks to be preserved in one chunk" + space_in_paren: + type: 'boolean' + default: false + description: "Add padding spaces within paren, ie. f( a, b )" + jslint_happy: + type: 'boolean' + default: false + description: "Enable jslint-stricter mode" + space_after_anon_function: + type: 'boolean' + default: false + description: "Add a space before an anonymous function's parens, ie. function ()" + brace_style: + type: 'string' + default: "collapse" + enum: ["collapse", "expand", "end-expand", "none"] + description: "[collapse|expand|end-expand|none]" + break_chained_methods: + type: 'boolean' + default: false + description: "Break chained method calls across subsequent lines" + keep_array_indentation: + type: 'boolean' + default: false + description: "Preserve array indentation" + keep_function_indentation: + type: 'boolean' + default: false + description: "" + space_before_conditional: + type: 'boolean' + default: true + description: "" + eval_code: + type: 'boolean' + default: false + description: "" + unescape_strings: + type: 'boolean' + default: false + description: "Decode printable characters encoded in xNN notation" + wrap_line_length: + type: 'integer' + default: 0 + description: "Wrap lines at next opportunity after N characters" + end_with_newline: + type: 'boolean' + default: false + description: "End output with newline" - ### - options: - # JavaScript - indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indentation size/length" - indent_char: - type: 'string' - default: defaultIndentChar - description: "Indentation character" - indent_level: - type: 'integer' - default: 0 - description: "Initial indentation level" - indent_with_tabs: - type: 'boolean' - default: defaultIndentWithTabs - description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`" - preserve_newlines: - type: 'boolean' - default: true - description: "Preserve line-breaks" - max_preserve_newlines: - type: 'integer' - default: 10 - description: "Number of line-breaks to be preserved in one chunk" - space_in_paren: - type: 'boolean' - default: false - description: "Add padding spaces within paren, ie. f( a, b )" - jslint_happy: - type: 'boolean' - default: false - description: "Enable jslint-stricter mode" - space_after_anon_function: - type: 'boolean' - default: false - description: "Add a space before an anonymous function's parens, ie. function ()" - brace_style: - type: 'string' - default: "collapse" - enum: ["collapse", "expand", "end-expand", "none"] - description: "[collapse|expand|end-expand|none]" - break_chained_methods: - type: 'boolean' - default: false - description: "Break chained method calls across subsequent lines" - keep_array_indentation: - type: 'boolean' - default: false - description: "Preserve array indentation" - keep_function_indentation: - type: 'boolean' - default: false - description: "" - space_before_conditional: - type: 'boolean' - default: true - description: "" - eval_code: - type: 'boolean' - default: false - description: "" - unescape_strings: - type: 'boolean' - default: false - description: "Decode printable characters encoded in xNN notation" - wrap_line_length: - type: 'integer' - default: 0 - description: "Wrap lines at next opportunity after N characters" - end_with_newline: - type: 'boolean' - default: false - description: "End output with newline" - -} \ No newline at end of file +} diff --git a/src/languages/json.coffee b/src/languages/json.coffee index a03bb2f..928c310 100644 --- a/src/languages/json.coffee +++ b/src/languages/json.coffee @@ -1,21 +1,21 @@ module.exports = { - name: "JSON" - namespace: "json" - fallback: ['js'] + name: "JSON" + namespace: "json" + fallback: ['js'] - ### - Supported Grammars - ### - grammars: [ - "JSON" - ] + ### + Supported Grammars + ### + grammars: [ + "JSON" + ] - ### - Supported extensions - ### - extensions: [ - "json" - ] + ### + Supported extensions + ### + extensions: [ + "json" + ] -} \ No newline at end of file +} diff --git a/src/languages/jsx.coffee b/src/languages/jsx.coffee index e07c586..e89b3b6 100644 --- a/src/languages/jsx.coffee +++ b/src/languages/jsx.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "JSX" - namespace: "jsx" - fallback: ['js'] + name: "JSX" + namespace: "jsx" + fallback: ['js'] - ### - Supported Grammars - ### - grammars: [ - "JSX" - "JavaScript (JSX)" - ] + ### + Supported Grammars + ### + grammars: [ + "JSX" + "JavaScript (JSX)" + ] - ### - Supported extensions - ### - extensions: [ - "jsx", - "js" - ] + ### + Supported extensions + ### + extensions: [ + "jsx", + "js" + ] } diff --git a/src/languages/less.coffee b/src/languages/less.coffee index fb83ea5..df1b398 100644 --- a/src/languages/less.coffee +++ b/src/languages/less.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "LESS" - namespace: "less" - fallback: ['css','scss','sass'] + name: "LESS" + namespace: "less" + fallback: ['css','scss','sass'] - ### - Supported Grammars - ### - grammars: [ - "LESS" - ] + ### + Supported Grammars + ### + grammars: [ + "LESS" + ] - ### - Supported extensions - ### - extensions: [ - 'less' - ] + ### + Supported extensions + ### + extensions: [ + 'less' + ] - defaultBeautifier: "Pretty Diff" + defaultBeautifier: "Pretty Diff" -} \ No newline at end of file +} diff --git a/src/languages/markdown.coffee b/src/languages/markdown.coffee index 8ad4d49..4bc1ad7 100644 --- a/src/languages/markdown.coffee +++ b/src/languages/markdown.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Markdown" - namespace: "markdown" + name: "Markdown" + namespace: "markdown" - ### - Supported Grammars - ### - grammars: [ - "GitHub Markdown" - ] + ### + Supported Grammars + ### + grammars: [ + "GitHub Markdown" + ] - ### - Supported extensions - ### - extensions: [ - "markdown" - "md" - ] + ### + Supported extensions + ### + extensions: [ + "markdown" + "md" + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/marko.coffee b/src/languages/marko.coffee index 6253e4d..f8df162 100644 --- a/src/languages/marko.coffee +++ b/src/languages/marko.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Marko" - namespace: "marko" - fallback: ['html'] + name: "Marko" + namespace: "marko" + fallback: ['html'] - ### - Supported Grammars - ### - grammars: [ - "Marko" - ] + ### + Supported Grammars + ### + grammars: [ + "Marko" + ] - ### - Supported extensions - ### - extensions: [ - "marko" - ] + ### + Supported extensions + ### + extensions: [ + "marko" + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/mustache.coffee b/src/languages/mustache.coffee index 4172f55..6523504 100644 --- a/src/languages/mustache.coffee +++ b/src/languages/mustache.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Mustache" - namespace: "mustache" - fallback: ['html','handlebars'] + name: "Mustache" + namespace: "mustache" + fallback: ['html','handlebars'] - ### - Supported Grammars - ### - grammars: [ - "HTML (Mustache)" - ] + ### + Supported Grammars + ### + grammars: [ + "HTML (Mustache)" + ] - ### - Supported extensions - ### - extensions: [ - "mustache" - ] + ### + Supported extensions + ### + extensions: [ + "mustache" + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/objective-c.coffee b/src/languages/objective-c.coffee index f66f90e..a7cef07 100644 --- a/src/languages/objective-c.coffee +++ b/src/languages/objective-c.coffee @@ -1,31 +1,31 @@ module.exports = { - name: "Objective-C" - namespace: "objectivec" - fallback: [] + name: "Objective-C" + namespace: "objectivec" + fallback: [] - ### - Supported Grammars - ### - grammars: [ - "Objective-C" - "Objective-C++" - ] + ### + Supported Grammars + ### + grammars: [ + "Objective-C" + "Objective-C++" + ] - ### - Supported extensions - ### - extensions: [ - "m" - "mm" - "h" - ] + ### + Supported extensions + ### + extensions: [ + "m" + "mm" + "h" + ] - options: - configPath: - title: "Config Path" - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + title: "Config Path" + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/pawn.coffee b/src/languages/pawn.coffee index 054ccaf..fa1e1a5 100644 --- a/src/languages/pawn.coffee +++ b/src/languages/pawn.coffee @@ -1,24 +1,24 @@ module.exports = { - name: "Pawn" - namespace: "pawn" + name: "Pawn" + namespace: "pawn" - ### - Supported Grammars - ### - grammars: [ - "Pawn" - ] + ### + Supported Grammars + ### + grammars: [ + "Pawn" + ] - ### - Supported extensions - ### - extensions: [] + ### + Supported extensions + ### + extensions: [] - options: - configPath: - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/perl.coffee b/src/languages/perl.coffee index 162011c..a1cc485 100644 --- a/src/languages/perl.coffee +++ b/src/languages/perl.coffee @@ -1,26 +1,26 @@ module.exports = { - name: "Perl" - namespace: "perl" + name: "Perl" + namespace: "perl" - ### - Supported Grammars - ### - grammars: [ - "Perl", "Perl 6" - ] + ### + Supported Grammars + ### + grammars: [ + "Perl", "Perl 6" + ] - ### - Supported extensions - ### - extensions: [ - "pl" - ] + ### + Supported extensions + ### + extensions: [ + "pl" + ] - options: - perltidy_profile: - type: 'string' - default: "" - description: "Specify a configuration file which will override the default name of .perltidyrc" + options: + perltidy_profile: + type: 'string' + default: "" + description: "Specify a configuration file which will override the default name of .perltidyrc" -} \ No newline at end of file +} diff --git a/src/languages/php.coffee b/src/languages/php.coffee index 1b44403..3fd1b4b 100644 --- a/src/languages/php.coffee +++ b/src/languages/php.coffee @@ -1,35 +1,35 @@ module.exports = { - name: "PHP" - namespace: "php" + name: "PHP" + namespace: "php" - ### - Supported Grammars - ### - grammars: [ - "PHP" - ] + ### + Supported Grammars + ### + grammars: [ + "PHP" + ] - ### - Supported extensions - ### - extensions: [ - "php" - ] + ### + Supported extensions + ### + extensions: [ + "php" + ] - options: - cs_fixer_path: - title: "PHP-CS-Fixer Path" - type: 'string' - default: "" - description: "Path to the `php-cs-fixer` CLI executable" - fixers: - type: 'string' - default: "" - description: "Add fixer(s). i.e. linefeed,-short_tag,indentation" - level: - type: 'string' - default: "" - description: "By default, all PSR-2 fixers and some additional ones are run." + options: + cs_fixer_path: + title: "PHP-CS-Fixer Path" + type: 'string' + default: "" + description: "Path to the `php-cs-fixer` CLI executable" + fixers: + type: 'string' + default: "" + description: "Add fixer(s). i.e. linefeed,-short_tag,indentation" + level: + type: 'string' + default: "" + description: "By default, all PSR-2 fixers and some additional ones are run." -} \ No newline at end of file +} diff --git a/src/languages/python.coffee b/src/languages/python.coffee index bb882a9..5825ae7 100644 --- a/src/languages/python.coffee +++ b/src/languages/python.coffee @@ -7,38 +7,38 @@ defaultIndentWithTabs = not softTabs module.exports = { - name: "Python" - namespace: "python" + name: "Python" + namespace: "python" - ### - Supported Grammars - ### - grammars: [ - "Python" - ] + ### + Supported Grammars + ### + grammars: [ + "Python" + ] - ### - Supported extensions - ### - extensions: [ - "py" - ] + ### + Supported extensions + ### + extensions: [ + "py" + ] - options: - max_line_length: - type: 'integer' - default: 79 - description: "set maximum allowed line length" - indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indentation size/length" - ignore: - type: 'array' - default: ["E24"] - items: - type: 'string' - description: "do not fix these errors/warnings" + options: + max_line_length: + type: 'integer' + default: 79 + description: "set maximum allowed line length" + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + ignore: + type: 'array' + default: ["E24"] + items: + type: 'string' + description: "do not fix these errors/warnings" -} \ No newline at end of file +} diff --git a/src/languages/ruby.coffee b/src/languages/ruby.coffee index 9bab6eb..e409dfd 100644 --- a/src/languages/ruby.coffee +++ b/src/languages/ruby.coffee @@ -7,35 +7,35 @@ defaultIndentWithTabs = not softTabs module.exports = { - name: "Ruby" - namespace: "ruby" + name: "Ruby" + namespace: "ruby" - ### - Supported Grammars - ### - grammars: [ - "Ruby" - "Ruby on Rails" - ] + ### + Supported Grammars + ### + grammars: [ + "Ruby" + "Ruby on Rails" + ] - ### - Supported extensions - ### - extensions: [ - "rb" - ] + ### + Supported extensions + ### + extensions: [ + "rb" + ] - options: - indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indentation size/length" - indent_char: - type: 'string' - default: defaultIndentChar - description: "Indentation character" - enum: [" ", "\t"] + options: + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + indent_char: + type: 'string' + default: defaultIndentChar + description: "Indentation character" + enum: [" ", "\t"] -} \ No newline at end of file +} diff --git a/src/languages/rust.coffee b/src/languages/rust.coffee index 9a7641c..6e0aa06 100644 --- a/src/languages/rust.coffee +++ b/src/languages/rust.coffee @@ -1,27 +1,27 @@ module.exports = { - name: "Rust" - namespace: "rust" + name: "Rust" + namespace: "rust" - ### - Supported Grammars - ### - grammars: [ - "Rust" - ] + ### + Supported Grammars + ### + grammars: [ + "Rust" + ] - ### - Supported extensions - ### - extensions: [ - "rs" - "rlib" - ] + ### + Supported extensions + ### + extensions: [ + "rs" + "rlib" + ] - options: - rustfmt_path: - type: 'string' - default: "" - description: "Path to rustfmt program" + options: + rustfmt_path: + type: 'string' + default: "" + description: "Path to rustfmt program" -} \ No newline at end of file +} diff --git a/src/languages/sass.coffee b/src/languages/sass.coffee index ace8141..03e49ca 100644 --- a/src/languages/sass.coffee +++ b/src/languages/sass.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Sass" - namespace: "sass" - fallback: ['css', 'scss'] + name: "Sass" + namespace: "sass" + fallback: ['css', 'scss'] - ### - Supported Grammars - ### - grammars: [ - "Sass" - ] + ### + Supported Grammars + ### + grammars: [ + "Sass" + ] - ### - Supported extensions - ### - extensions: [ - "sass" - ] + ### + Supported extensions + ### + extensions: [ + "sass" + ] - defaultBeautifier: "Pretty Diff" + defaultBeautifier: "Pretty Diff" -} \ No newline at end of file +} diff --git a/src/languages/scss.coffee b/src/languages/scss.coffee index 896b0ab..6dcd8b1 100644 --- a/src/languages/scss.coffee +++ b/src/languages/scss.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "SCSS" - namespace: "scss" - fallback: ['css', 'sass'] + name: "SCSS" + namespace: "scss" + fallback: ['css', 'sass'] - ### - Supported Grammars - ### - grammars: [ - "SCSS" - ] + ### + Supported Grammars + ### + grammars: [ + "SCSS" + ] - ### - Supported extensions - ### - extensions: [ - "scss" - ] + ### + Supported extensions + ### + extensions: [ + "scss" + ] - defaultBeautifier: "Pretty Diff" + defaultBeautifier: "Pretty Diff" -} \ No newline at end of file +} diff --git a/src/languages/spacebars.coffee b/src/languages/spacebars.coffee index b7a6113..69cd1b2 100644 --- a/src/languages/spacebars.coffee +++ b/src/languages/spacebars.coffee @@ -1,22 +1,22 @@ module.exports = { - name: "Spacebars" - description: "Spacebars" - namespace: "spacebars" - fallback: ['html'] + name: "Spacebars" + description: "Spacebars" + namespace: "spacebars" + fallback: ['html'] - ### - Supported Grammars - ### - grammars: [ - "Spacebars" - ] + ### + Supported Grammars + ### + grammars: [ + "Spacebars" + ] - ### - Supported extensions - ### - extensions: [] + ### + Supported extensions + ### + extensions: [] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/sql.coffee b/src/languages/sql.coffee index e73e2a2..c674c1e 100644 --- a/src/languages/sql.coffee +++ b/src/languages/sql.coffee @@ -7,40 +7,40 @@ defaultIndentWithTabs = not softTabs module.exports = { - name: "SQL" - namespace: "sql" + name: "SQL" + namespace: "sql" - ### - Supported Grammars - ### - grammars: [ - "SQL (Rails)" - "SQL" - ] + ### + Supported Grammars + ### + grammars: [ + "SQL (Rails)" + "SQL" + ] - ### - Supported extensions - ### - extensions: [ - "sql" - ] + ### + Supported extensions + ### + extensions: [ + "sql" + ] - options: - # SQL - indent_size: - type: 'integer' - default: defaultIndentSize - minimum: 0 - description: "Indentation size/length" - keywords: - type: 'string' - default: "upper" - description: "Change case of keywords" - enum: ["lower","upper","capitalize"] - identifiers: - type: 'string' - default: "lower" - description: "Change case of identifiers" - enum: ["lower","upper","capitalize"] + options: + # SQL + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + keywords: + type: 'string' + default: "upper" + description: "Change case of keywords" + enum: ["lower","upper","capitalize"] + identifiers: + type: 'string' + default: "lower" + description: "Change case of identifiers" + enum: ["lower","upper","capitalize"] -} \ No newline at end of file +} diff --git a/src/languages/swig.coffee b/src/languages/swig.coffee index d26fba3..bebd6aa 100644 --- a/src/languages/swig.coffee +++ b/src/languages/swig.coffee @@ -1,24 +1,24 @@ module.exports = { - name: "Swig" - namespace: "swig" - fallback: ['html'] + name: "Swig" + namespace: "swig" + fallback: ['html'] - ### - Supported Grammars - ### - grammars: [ - "HTML (Swig)" - "SWIG" - ] + ### + Supported Grammars + ### + grammars: [ + "HTML (Swig)" + "SWIG" + ] - ### - Supported extensions - ### - extensions: [ - 'swig' - ] + ### + Supported extensions + ### + extensions: [ + 'swig' + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/tss.coffee b/src/languages/tss.coffee index 08bd704..127f38e 100644 --- a/src/languages/tss.coffee +++ b/src/languages/tss.coffee @@ -1,22 +1,22 @@ module.exports = { - name: "TSS" - description: "Titanium Style Sheets" - namespace: "tss" - fallback: ['css', 'sass'] + name: "TSS" + description: "Titanium Style Sheets" + namespace: "tss" + fallback: ['css', 'sass'] - ### - Supported Grammars - ### - grammars: [ - "TSS" - ] + ### + Supported Grammars + ### + grammars: [ + "TSS" + ] - ### - Supported extensions - ### - extensions: [ - "tss" - ] + ### + Supported extensions + ### + extensions: [ + "tss" + ] -} \ No newline at end of file +} diff --git a/src/languages/twig.coffee b/src/languages/twig.coffee index a43405d..d963a16 100644 --- a/src/languages/twig.coffee +++ b/src/languages/twig.coffee @@ -1,24 +1,24 @@ module.exports = { - name: "Twig" - description: "Twig" - namespace: "twig" - fallback: ['html', 'js', 'php'] + name: "Twig" + description: "Twig" + namespace: "twig" + fallback: ['html', 'js', 'php'] - ### - Supported Grammars - ### - grammars: [ - "HTML (Twig)" - ] + ### + Supported Grammars + ### + grammars: [ + "HTML (Twig)" + ] - ### - Supported extensions - ### - extensions: [ - 'twig' - ] + ### + Supported extensions + ### + extensions: [ + 'twig' + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/typescript.coffee b/src/languages/typescript.coffee index 3a0d28c..1ab966e 100644 --- a/src/languages/typescript.coffee +++ b/src/languages/typescript.coffee @@ -1,21 +1,21 @@ module.exports = { - name: "TypeScript" - namespace: "typescript" - fallback: ['js'] + name: "TypeScript" + namespace: "typescript" + fallback: ['js'] - ### - Supported Grammars - ### - grammars: [ - "TypeScript" - ] + ### + Supported Grammars + ### + grammars: [ + "TypeScript" + ] - ### - Supported extensions - ### - extensions: [ - "ts" - ] + ### + Supported extensions + ### + extensions: [ + "ts" + ] -} \ No newline at end of file +} diff --git a/src/languages/vala.coffee b/src/languages/vala.coffee index 36c5ba7..7bdddfb 100644 --- a/src/languages/vala.coffee +++ b/src/languages/vala.coffee @@ -1,27 +1,27 @@ module.exports = { - name: "Vala" - namespace: "vala" + name: "Vala" + namespace: "vala" - ### - Supported Grammars - ### - grammars: [ - "Vala" - ] + ### + Supported Grammars + ### + grammars: [ + "Vala" + ] - ### - Supported extensions - ### - extensions: [ - "vala" - "vapi" - ] + ### + Supported extensions + ### + extensions: [ + "vala" + "vapi" + ] - options: - configPath: - type: 'string' - default: "" - description: "Path to uncrustify config file. i.e. uncrustify.cfg" + options: + configPath: + type: 'string' + default: "" + description: "Path to uncrustify config file. i.e. uncrustify.cfg" -} \ No newline at end of file +} diff --git a/src/languages/visualforce.coffee b/src/languages/visualforce.coffee index cba1016..9c4627e 100644 --- a/src/languages/visualforce.coffee +++ b/src/languages/visualforce.coffee @@ -1,23 +1,23 @@ module.exports = { - name: "Visualforce" - namespace: "visualforce" - fallback: ['html','xml'] + name: "Visualforce" + namespace: "visualforce" + fallback: ['html','xml'] - ### - Supported Grammars - ### - grammars: [ - "Visualforce" - ] + ### + Supported Grammars + ### + grammars: [ + "Visualforce" + ] - ### - Supported extensions - ### - extensions: [ - "page" - ] + ### + Supported extensions + ### + extensions: [ + "page" + ] - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/languages/xml.coffee b/src/languages/xml.coffee index 59f1799..587fcec 100644 --- a/src/languages/xml.coffee +++ b/src/languages/xml.coffee @@ -1,26 +1,26 @@ module.exports = { - name: "XML" - description: "XML" - namespace: "xml" - fallback: ['html'] + name: "XML" + description: "XML" + namespace: "xml" + fallback: ['html'] - ### - Supported Grammars - ### - grammars: [ - "XML" - ] + ### + Supported Grammars + ### + grammars: [ + "XML" + ] - ### - Supported extensions - ### - extensions: [ - 'xml' - ] + ### + Supported extensions + ### + extensions: [ + 'xml' + ] - defaultBeautifier: "Pretty Diff" + defaultBeautifier: "Pretty Diff" - options: [] + options: [] -} \ No newline at end of file +} diff --git a/src/views/loading-view.coffee b/src/views/loading-view.coffee index 284effa..0023f25 100644 --- a/src/views/loading-view.coffee +++ b/src/views/loading-view.coffee @@ -2,37 +2,37 @@ module.exports = class LoadingView extends View - @content: -> + @content: -> + @div + class: 'atom-beautify message-panel', => @div - class: 'atom-beautify message-panel', => + class: 'overlay from-top', => + @div class: "tool-panel panel-bottom", => + @div class: "inset-panel", => + @div class: "panel-heading", => + @div class: 'btn-toolbar pull-right', => + @button + class: 'btn' + click: 'hide' + 'Hide' + @span + class: 'text-primary' + outlet: 'title' + 'Atom Beautify' @div - class: 'overlay from-top', => - @div class: "tool-panel panel-bottom", => - @div class: "inset-panel", => - @div class: "panel-heading", => - @div class: 'btn-toolbar pull-right', => - @button - class: 'btn' - click: 'hide' - 'Hide' - @span - class: 'text-primary' - outlet: 'title' - 'Atom Beautify' - @div - class: "panel-body padded select-list text-center" - outlet: 'body' - => - @div => - @span - class: 'text-center loading loading-spinner-large inline-block' - @div - class: '' - 'Beautification in progress.' + class: "panel-body padded select-list text-center" + outlet: 'body' + => + @div => + @span + class: 'text-center loading loading-spinner-large inline-block' + @div + class: '' + 'Beautification in progress.' - hide: (event, element) => - @detach() + hide: (event, element) => + @detach() - show: => - if not @.hasParent() - atom.workspace.addTopPanel(item: @) + show: => + if not @.hasParent() + atom.workspace.addTopPanel(item: @) diff --git a/src/views/message-view.coffee b/src/views/message-view.coffee index 22512e5..2879d0f 100644 --- a/src/views/message-view.coffee +++ b/src/views/message-view.coffee @@ -2,80 +2,80 @@ module.exports = class MessageView extends View - messages: [] - @content: -> + messages: [] + @content: -> + @div + class: 'atom-beautify message-panel', => @div - class: 'atom-beautify message-panel', => + class: 'overlay from-top', => + @div class: "tool-panel panel-bottom", => + @div class: "inset-panel", => + @div class: "panel-heading", => + @div class: 'btn-toolbar pull-right', => + @button + class: 'btn' + click: 'clearMessages' + 'Clear' + @span + class: '' + outlet: 'title' + 'Atom Beautify Message' @div - class: 'overlay from-top', => - @div class: "tool-panel panel-bottom", => - @div class: "inset-panel", => - @div class: "panel-heading", => - @div class: 'btn-toolbar pull-right', => - @button - class: 'btn' - click: 'clearMessages' - 'Clear' - @span - class: '' - outlet: 'title' - 'Atom Beautify Message' - @div - class: "panel-body padded select-list" - outlet: 'body' - => - @ol - class: 'list-group', - outlet: 'messageItems' - => - @li class: 'two-lines', => - @div class: 'status status-removed icon icon-diff-added', '' - @div class: 'primary-line icon icon-alert', 'This is the title' - @div class: 'secondary-line no-icon', 'Secondary line' - @li class: 'two-lines', => - @div class: 'status status-removed icon icon-diff-added', '' - @div class: 'primary-line icon icon-alert', 'This is the title Currently there is no way to display a message to the user, such as errors or warnings or deprecation notices (see #40). Let\'s put a little overlay on the top for displaying such information.' - @div class: 'secondary-line no-icon', 'This is the title Currently there is no way to display a message to the user, such as errors or warnings or deprecation notices (see #40). Let\'s put a little overlay on the top for displaying such information.' - @li class: 'two-lines', => - @div class: 'status status-removed icon icon-diff-added', '' - @div class: 'primary-line icon icon-alert', 'test' - @div class: 'secondary-line no-icon', 'Secondary line' - @li class: 'two-lines', => - @div class: 'status status-removed icon icon-diff-added', '' - @div class: 'primary-line icon icon-alert', 'This is the title' - @div class: 'secondary-line no-icon', 'Secondary line' - @li class: 'two-lines', => - @div class: 'status status-removed icon icon-diff-added', '' - @div class: 'primary-line icon icon-alert', 'This is the title' - @div class: 'secondary-line no-icon', 'Secondary line' - @li class: 'two-lines', => - @div class: 'status status-added icon icon-diff-added', '' - @div class: 'primary-line icon icon-file-text', 'Primary line' - @div class: 'secondary-line no-icon', 'Secondary line' + class: "panel-body padded select-list" + outlet: 'body' + => + @ol + class: 'list-group', + outlet: 'messageItems' + => + @li class: 'two-lines', => + @div class: 'status status-removed icon icon-diff-added', '' + @div class: 'primary-line icon icon-alert', 'This is the title' + @div class: 'secondary-line no-icon', 'Secondary line' + @li class: 'two-lines', => + @div class: 'status status-removed icon icon-diff-added', '' + @div class: 'primary-line icon icon-alert', 'This is the title Currently there is no way to display a message to the user, such as errors or warnings or deprecation notices (see #40). Let\'s put a little overlay on the top for displaying such information.' + @div class: 'secondary-line no-icon', 'This is the title Currently there is no way to display a message to the user, such as errors or warnings or deprecation notices (see #40). Let\'s put a little overlay on the top for displaying such information.' + @li class: 'two-lines', => + @div class: 'status status-removed icon icon-diff-added', '' + @div class: 'primary-line icon icon-alert', 'test' + @div class: 'secondary-line no-icon', 'Secondary line' + @li class: 'two-lines', => + @div class: 'status status-removed icon icon-diff-added', '' + @div class: 'primary-line icon icon-alert', 'This is the title' + @div class: 'secondary-line no-icon', 'Secondary line' + @li class: 'two-lines', => + @div class: 'status status-removed icon icon-diff-added', '' + @div class: 'primary-line icon icon-alert', 'This is the title' + @div class: 'secondary-line no-icon', 'Secondary line' + @li class: 'two-lines', => + @div class: 'status status-added icon icon-diff-added', '' + @div class: 'primary-line icon icon-file-text', 'Primary line' + @div class: 'secondary-line no-icon', 'Secondary line' - constructor: -> - super + constructor: -> + super - destroy: -> + destroy: -> - addMessage: (message) => - @messages.push(message); - @refresh() + addMessage: (message) => + @messages.push(message); + @refresh() - clearMessages: => - @messages = [] - @refresh() + clearMessages: => + @messages = [] + @refresh() - close: (event, element) => - @detach() + close: (event, element) => + @detach() - show: => - if not @.hasParent() - atom.workspaceView.appendToTop @ + show: => + if not @.hasParent() + atom.workspaceView.appendToTop @ - refresh: => - # If the messages list is empty, view should be closed. - if @messages.length is 0 - @close() - else - @show() + refresh: => + # If the messages list is empty, view should be closed. + if @messages.length is 0 + @close() + else + @show()