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

Commit 8fed941

Browse files
committed
Initial commit
0 parents  commit 8fed941

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 0.0.1
2+
* Implemented first version of 'linter-rust'

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# linter-rust
2+
3+
This package will lint your opened Rust-files in Atom, using [rustc](http://www.rust-lang.org).
4+
5+
## Installation
6+
7+
* Install [Rust](http://www.rust-lang.org).
8+
* `$ apm install linter` (if you don't have [AtomLinter/Linter](https://github.com/AtomLinter/Linter) installed).
9+
* `$ apm install linter-rust`
10+
11+
## Other available linters
12+
There are other linters available - take a look at the linters [mainpage](https://github.com/AtomLinter/Linter).
13+
14+
## Donation
15+
[![Share the love!](https://chewbacco-stuff.s3.amazonaws.com/donate.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KXUYS4ARNHCN8)

lib/init.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports =
2+
configDefaults:
3+
'Executable path': null
4+
5+
activate: ->
6+
console.log 'Linter-Rust: package loaded,
7+
ready to get initialized by AtomLinter.'

lib/linter-rust.coffee

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
linterPath = atom.packages.getLoadedPackage("linter").path
2+
Linter = require "#{linterPath}/lib/linter"
3+
4+
{config} = atom
5+
{exec} = require 'child_process'
6+
{log, warn} = require "#{linterPath}/lib/utils"
7+
8+
9+
class LinterRust extends Linter
10+
@enable: false
11+
@syntax: 'source.rust'
12+
cmd: 'rustc'
13+
executablePath: null
14+
linterName: 'rust'
15+
errorStream: 'stderr'
16+
regex: '^(.+):(?<line>\\d+):(?<col>\\d+):\\s*(\\d+):(\\d+)\\s+((?<error>error|fatal error)|(?<warning>warning)):\\s+(?<message>.+)\n'
17+
18+
constructor: (@editor) ->
19+
super @editor
20+
@executablePath = config.getSettings()['linter-rust']['Executable path']
21+
@cmd = if @executablePath then @executablePath else @cmd
22+
exec "#{@cmd} --version", @executionCheckHandler
23+
@cmd = "#{@cmd} --no-trans --color never"
24+
log 'Linter-Rust: initialization completed'
25+
26+
executionCheckHandler: (error, stdout, stderr) =>
27+
versionRegEx = /rustc ([\d\.]+)/
28+
if not versionRegEx.test(stdout)
29+
result = if error? then '#' + error.code + ': ' else ''
30+
result += 'stdout: ' + stdout if stdout.length > 0
31+
result += 'stderr: ' + stderr if stderr.length > 0
32+
console.error "Linter-Rust: #{@cmd} was not executable: #{result}"
33+
else
34+
@enabled = true
35+
log "Linter-Rust: found rust " + versionRegEx.exec(stdout)[1]
36+
37+
lintFile: (filePath, callback) =>
38+
if @enabled
39+
super filePath, callback
40+
else
41+
@processMessage "", callback
42+
43+
formatMessage: (match) ->
44+
type = if match.error then match.error else match.warning
45+
"#{type} #{match.message}"
46+
47+
module.exports = LinterRust

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "linter-rust",
3+
"linter-package": true,
4+
"activationEvents": [],
5+
"main": "./lib/init",
6+
"version": "0.0.1",
7+
"description": "Lint Rust on the fly, using rustc",
8+
"repository": "https://github.com/AtomLinter/linter-rust",
9+
"license": "MIT",
10+
"engines": {
11+
"atom": ">0.50.0"
12+
},
13+
"dependencies": {}
14+
}

0 commit comments

Comments
 (0)