Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Fix #44, #51, others? Use provider API #54

Merged
merged 1 commit into from
Aug 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{BufferedProcess, CompositeDisposable} = require 'atom'
{exists, unlink, writeFile} = require 'fs'
{join, resolve} = require 'path'
{randomBytes} = require 'crypto'
{tmpdir} = require 'os'

findFile = (dir, file, cb) ->
absolute = join dir, file
exists absolute, (doesExist) ->
return cb absolute if doesExist
parent = resolve dir, '..'
return cb() if dir is parent
findFile parent, file, cb

lint = (editor, command, args) ->
filePath = editor.getPath()
tmpPath = join tmpdir(), randomBytes(32).toString 'hex'
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 [])...
args...
tmpPath
]
stdout: appendToOut
stderr: appendToOut
exit: -> cleanup ->
try {offenses: errors} = JSON.parse(out).files[0]
return reject new Error out unless errors
resolve errors.map (error) ->
{line, column, length} =
error.location || {line: 1, column: 1, length: 0}
type:
switch error.severity
when 'refactor', 'convention', 'warning' then 'warning'
else 'error'
text: (error.message or 'Unknown Error') +
(if error.cop_name then " (#{error.cop_name})" else ''),
filePath: filePath,
range: [[line - 1, column - 1], [line - 1, column + length - 1]]

module.exports =
config:
executablePath:
type: 'string'
title: 'Executable Path'
default: 'rubocop'
additionalArguments:
title: 'Additional Arguments'
type: 'string'
default: ''

activate: ->
prefix = 'linter-rubocop.'
@subscriptions = new CompositeDisposable
@subscriptions.add atom.config.observe "#{prefix}executablePath",
(executablePath) => @executablePath = executablePath
@subscriptions.add atom.config.observe "#{prefix}additionalArguments",
(args) => @additionalArguments = if args then args.split ' ' else []

deactivate: ->
@subscriptions.dispose()

provideLinter: ->
provider =
grammarScopes: ['source.ruby', 'source.ruby.rails', 'source.ruby.rspec'],
scope: 'file'
lintOnFly: true
lint: (editor) => lint editor, @executablePath, @additionalArguments
10 changes: 0 additions & 10 deletions lib/init.coffee

This file was deleted.

34 changes: 0 additions & 34 deletions lib/linter-rubocop.coffee

This file was deleted.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "linter-rubocop",
"linter-package": true,
"activationCommands": [],
"main": "./lib/init",
"version": "0.2.7",
"description": "Lint `Ruby` on the fly, using rubocop",
"repository": "https://github.com/AtomLinter/linter-rubocop",
"license": "MIT",
"engines": {
"atom": ">0.50.0"
},
"dependencies": {}
"providedServices": {
"linter": {
"versions": {
"1.1.0": "provideLinter"
}
}
}
}