forked from AtomLinter/linter-rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c48607
commit d5ed9a1
Showing
6 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{exists} = require 'fs' | ||
{join, resolve} = require 'path' | ||
|
||
module.exports = (dir, file, cb) -> | ||
absolute = join dir, file | ||
exists absolute, (doesExist) -> | ||
return cb absolute if doesExist | ||
parent = resolve dir, '..' | ||
return cb() if dir is parent | ||
module.exports parent, file, cb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{createHash} = require 'crypto' | ||
|
||
module.exports = (buffer) -> | ||
hash = createHash 'md5' | ||
hash.end buffer | ||
hash.read().toString 'hex' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
lint = require './lint' | ||
{CompositeDisposable} = require 'atom' | ||
|
||
module.exports = | ||
config: | ||
executablePath: | ||
title: 'Rubocop Executable Path' | ||
description: 'The path where rubocop is located' | ||
type: 'string' | ||
title: 'Executable Path' | ||
default: 'rubocop' | ||
additionalArguments: | ||
title: 'Additional Arguments' | ||
type: 'string' | ||
default: '' | ||
|
||
activate: -> | ||
console.log 'activate linter-rubocop' | ||
@subscriptions = new CompositeDisposable | ||
@subscriptions.add atom.config.observe 'linter-rubocop.additionalArguments', | ||
(args) => @additionalArguments = if args then args.split ' ' else [] | ||
@subscriptions.add atom.config.observe 'linter-rubocop.executablePath', | ||
(executablePath) => @executablePath = executablePath | ||
|
||
deactivate: -> | ||
@subscriptions.dispose() | ||
|
||
provideLinter: -> | ||
provider = | ||
grammarScopes: ['source.ruby', 'source.ruby.rails', 'source.ruby.rspec'] | ||
scope: 'file' | ||
lintOnFly: true | ||
lint: (editor) => lint editor, @executablePath, @additionalArguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
findFile = require './find-file' | ||
hash = require './hash' | ||
{BufferedProcess} = require 'atom' | ||
{join} = require 'path' | ||
{tmpdir} = require 'os' | ||
{unlink, writeFile} = require 'fs' | ||
|
||
module.exports = (editor, command, args) -> | ||
filePath = editor.getPath() | ||
rails = editor.getGrammar().scopeName is 'source.ruby.rails' | ||
tmpPath = join tmpdir(), hash filePath | ||
out = '' | ||
|
||
appendToOut = (data) -> out += data | ||
getConfig = (cb) -> findFile filePath, '.rubocop.yml', cb | ||
writeTmp = (cb) -> writeFile tmpPath, editor.getText(), cb | ||
cleanup = (cb) -> unlink tmpPath, cb | ||
|
||
new Promise (resolve, reject) -> getConfig (config) -> writeTmp (er) -> | ||
return reject er if er | ||
new BufferedProcess | ||
command: command | ||
args: [ | ||
'-f' | ||
'json' | ||
(if config then ['-c', config] else [])... | ||
(if rails then ['-R'] else [])... | ||
args... | ||
tmpPath | ||
] | ||
stdout: appendToOut | ||
stderr: appendToOut | ||
exit: -> cleanup -> | ||
try {offenses} = JSON.parse(out).files[0] | ||
return reject new Error out unless offenses | ||
resolve offenses.map (offense) -> | ||
line = (offense.location?.line or 1) - 1 | ||
col = (offense.location?.column or 1) - 1 | ||
type: | ||
switch offense.severity | ||
when 'refactor', 'convention', 'warning' then 'warning' | ||
else 'error' | ||
text: (offense.message or 'Unknown Error') + | ||
(if offense.cop_name then " (#{offense.cop_name})" else ''), | ||
filePath: filePath, | ||
range: [ | ||
[line, col], | ||
[line, col + (offense.location?.length or 0)] | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters