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

Support v2 Linter API #18

Merged
merged 6 commits into from
Feb 7, 2019
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
10 changes: 2 additions & 8 deletions lib/linter-swiftc.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
module.exports = LinterSwiftc =
config:
compilerExecPath:
title: 'Compiler Executable Path'
description: 'The path of the compiler executable, with binary name. By
default will use `swiftc` from your path.'
type: 'string'
default: 'swiftc'
activate: ->
# Show the user an error if they do not have the appropriate
# Swift Language package from Atom Package Manager installed.
Expand Down Expand Up @@ -33,8 +26,9 @@ module.exports = LinterSwiftc =
LinterProvider = require './provider'
provider = new LinterProvider()
return {
name: 'swiftc'
grammarScopes: ['source.swift']
scope: 'file'
lint: provider.lint
lintOnFly: false
lintsOnChange: false
}
27 changes: 17 additions & 10 deletions lib/provider.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
path = require 'path'
helpers = require 'atom-linter';
child_process = require 'child_process'

VALID_SEVERITY = ['error', 'warning', 'info']

getSeverity = (givenSeverity) ->
severity = givenSeverity.toLowerCase()
return if severity not in VALID_SEVERITY then 'warning' else severity

module.exports = class LinterProvider
regex = ///
(\S+): #The file with issue.
Expand All @@ -18,10 +25,10 @@ module.exports = class LinterProvider

# This is based on code taken right from the linter-plus rewrite
# of `linter-crystal`.
lint: (TextEditor) ->
lint: (textEditor) ->
new Promise (Resolve) ->
file = path.basename TextEditor.getPath()
cwd = path.dirname TextEditor.getPath()
file = path.basename textEditor.getPath()
cwd = path.dirname textEditor.getPath()
data = []
command = getCommandWithFile file
console.log "Swift Linter Command: #{command}" if atom.inDevMode()
Expand All @@ -32,11 +39,11 @@ module.exports = class LinterProvider
for line in data
console.log "Swift Linter Provider: #{line}" if atom.inDevMode()
if line.match regex
[file, line, column, type, message] = line.match(regex)[1..5]
toReturn.push(
type: type,
text: message,
filePath: path.join(cwd, file).normalize()
range: [[line - 1, column - 1], [line - 1, column - 1]]
)
[file, line, column, severity, excerpt] = line.match(regex)[1..5]
toReturn.push
severity: getSeverity(severity)
excerpt: excerpt
location:
file: path.join(cwd, file).normalize()
position: helpers.generateRange(textEditor, Number.parseInt(line, 10) - 1, Number.parseInt(column, 10) - 1)
Resolve toReturn
59 changes: 56 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,72 @@
{
"name": "linter-swiftc",
"activationCommands": [],
"main": "./lib/linter-swiftc",
"version": "2.0.0",
"description": "Lint Swift using swiftc",
"repository": "https://github.com/AtomLinter/linter-swiftc",
"license": "MIT",
"engines": {
"atom": ">0.50.0"
"atom": ">0.50.0 <2.0.0"
},
"configSchema": {
"compilerExecPath": {
"default": "swiftc",
"description": "The path of the compiler executable, with binary name. By default will use `swiftc` from your path.",
"type": "string"
}
},
"dependencies": {
"atom-linter": "^10.0.0"
},
"devDependencies": {
"coffeelint": "^1.15.0"
},
"package-deps": [
"linter:2.0.0"
],
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
"2.0.0": "provideLinter"
}
}
},
"coffeelintConfig": {
"max_line_length": {
"value": 120,
"level": "warn"
},
"no_empty_param_list": {
"level": "error"
},
"arrow_spacing": {
"level": "error"
},
"no_interpolation_in_single_quotes": {
"level": "error"
},
"no_debugger": {
"level": "error"
},
"prefer_english_operator": {
"level": "error"
},
"colon_assignment_spacing": {
"spacing": {
"left": 0,
"right": 1
},
"level": "error"
},
"braces_spacing": {
"spaces": 0,
"level": "error"
},
"spacing_after_comma": {
"level": "error"
},
"no_stand_alone_at": {
"level": "error"
}
}
}