add JSCS Fixer
- Cannot be configured via the settings UI yet. - Only fixes files, that have a .jscsrc file in one of their parent folders (up to the project root folder in Atom).
This commit is contained in:
parent
75fa934dbe
commit
e56304625c
|
@ -46,6 +46,10 @@
|
|||
{
|
||||
"name": "Ramón Cahenzli",
|
||||
"url": "https://github.com/psy-q"
|
||||
},
|
||||
{
|
||||
"name": "Clemens Damke",
|
||||
"url": "https://github.com/Cortys"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
|
@ -69,6 +73,7 @@
|
|||
"extend": "^2.0.1",
|
||||
"handlebars": "^3.0.3",
|
||||
"js-beautify": "^1.5.6",
|
||||
"jscs": "^1.13.1",
|
||||
"lodash": "3.9.3",
|
||||
"loophole": "^1.0.0",
|
||||
"node-dir": "^0.1.8",
|
||||
|
|
|
@ -42,6 +42,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
'gofmt'
|
||||
'fortran-beautifier'
|
||||
'js-beautify'
|
||||
'jscs'
|
||||
'perltidy'
|
||||
'php-cs-fixer'
|
||||
'prettydiff'
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
"use strict"
|
||||
Beautifier = require('./beautifier')
|
||||
Checker = require 'jscs'
|
||||
cliConfig = require 'jscs/lib/cli-config'
|
||||
|
||||
checker = null
|
||||
|
||||
module.exports = class JSCSFixer extends Beautifier
|
||||
name: "JSCS Fixer"
|
||||
|
||||
options: {
|
||||
JavaScript: false
|
||||
}
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
@verbose("JSCS Fixer language #{language}")
|
||||
return new @Promise((resolve, reject) =>
|
||||
try
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
path = if editor? then editor.getPath() else undefined
|
||||
config = if path? then cliConfig.load(undefined, atom.project.relativizePath(path)[0]) else undefined
|
||||
if !checker?
|
||||
checker = new Checker()
|
||||
checker.registerDefaultRules()
|
||||
if !config?
|
||||
throw new Error("No JSCS config found.")
|
||||
checker.configure(config)
|
||||
result = checker.fixString(text, path)
|
||||
if result.errors.getErrorCount() > 0
|
||||
@error(result.errors.getErrorList().reduce((res, err) =>
|
||||
"#{res}<br> Line #{err.line}: #{err.message}"
|
||||
, "JSCS Fixer error:"))
|
||||
|
||||
resolve result.output
|
||||
|
||||
catch err
|
||||
@error("JSCS Fixer error: #{err}")
|
||||
reject(err)
|
||||
|
||||
)
|
Loading…
Reference in New Issue