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

Commit ca1c9e6

Browse files
committed
Refactoring.
1 parent fa69449 commit ca1c9e6

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

lib/init.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ module.exports =
33
executablePath:
44
type: 'string'
55
default: 'rustc'
6-
description: 'Path to rust compiller.'
7-
cargoFilename:
6+
description: 'Path to rust compiller'
7+
cargoManifestFilename:
88
type: 'string'
99
default: 'Cargo.toml'
10-
description: 'Cargo configuration file.'
10+
description: 'Cargo manifest filename'
1111
lintOnChange:
1212
type: 'boolean'
1313
default: true
14-
description: 'Lint file on change (experimental).'
14+
description: 'Lint file on change (experimental)'
1515

1616
activate: ->
1717
console.log 'Linter-Rust: package loaded,

lib/linter-rust.coffee

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ linterPath = atom.packages.getLoadedPackage("linter").path
22
Linter = require "#{linterPath}/lib/linter"
33

44
{exec} = require 'child_process'
5-
{log, warn} = require "#{linterPath}/lib/utils"
5+
{log, warn, findFile} = require "#{linterPath}/lib/utils"
66
fs = require 'fs'
77
path = require 'path'
88
tmp = require('tmp')
@@ -15,7 +15,7 @@ class LinterRust extends Linter
1515
linterName: 'rust'
1616
errorStream: 'stderr'
1717
regex: '(?<file>.+):(?<line>\\d+):(?<col>\\d+):\\s*(\\d+):(\\d+)\\s+((?<error>error|fatal error)|(?<warning>warning)|(?<info>note)):\\s+(?<message>.+)\n'
18-
cargoFilename: ''
18+
cargoManifestFilename: ''
1919
dependencyDir: "target/debug/deps"
2020
tmpFile: null
2121
lintOnChange: false
@@ -29,8 +29,8 @@ class LinterRust extends Linter
2929
@enabled = false
3030
@rustcPath = rustcPath
3131
exec "\"#{@rustcPath}\" --version", @executionCheckHandler
32-
atom.config.observe 'linter-rust.cargoFilename', =>
33-
@cargoFilename = atom.config.get 'linter-rust.cargoFilename'
32+
atom.config.observe 'linter-rust.cargoManifestFilename', =>
33+
@cargoManifestFilename = atom.config.get 'linter-rust.cargoMainifestFilename'
3434
atom.config.observe 'linter-rust.lintOnChange', =>
3535
@lintOnChange = atom.config.get 'linter-rust.lintOnChange'
3636

@@ -51,7 +51,7 @@ class LinterRust extends Linter
5151

5252
initCmd: =>
5353
@cmd = [@rustcPath, '-Z', 'no-trans', '--color', 'never']
54-
cargoPath = do @locateCargo
54+
cargoPath = do @locateCargoManifest
5555
if cargoPath
5656
@cmd.push '-L'
5757
@cmd.push path.join cargoPath, @dependencyDir
@@ -70,17 +70,10 @@ class LinterRust extends Linter
7070
super fileName, callback
7171

7272

73-
locateCargo: ->
74-
directory = path.resolve path.dirname do @editor.getPath
75-
root_dir = if /^win/.test process.platform then /^.:\\$/ else /^\/$/
76-
loop
77-
cargoFile = path.join directory, @cargoFilename
78-
return directory if fs.existsSync cargoFile
73+
locateCargoManifest: ->
74+
cur_dir = path.resolve path.dirname do @editor.getPath
75+
return findFile(cur_dir, @cargoManifestFilename)
7976

80-
break if root_dir.test directory
81-
directory = path.resolve path.join directory, '..'
82-
83-
return false
8477

8578
processMessage: (message, callback) ->
8679
if @tmpFile

0 commit comments

Comments
 (0)