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

Commit

Permalink
Exec async using node
Browse files Browse the repository at this point in the history
Move to the AtomLinter/csslint for until `stdin` and `JSON` support are
implemented in the main repository.
Use helpers.execNode to run the linter.
  • Loading branch information
Arcanemagus committed Jul 29, 2015
1 parent 93c4bb6 commit 75fcbee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.
69 changes: 23 additions & 46 deletions lib/main.coffee
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@
csslint = require('csslint').CSSLint
helpers = require('atom-linter')
path = require('path')
fs = require('fs')

# Adapted from cli/common.js in CSSLint
gatherRules = (options, ruleset) ->
warnings = options.rules or options.warnings
errors = options.errors
if warnings
ruleset = ruleset or {}
warnings.split(",").map (value) ->
ruleset[value] = 1
if errors
ruleset = ruleset or {}
errors.split(",").map (value) ->
ruleset[value] = 2
return ruleset

module.exports =
activate: ->
@rules = csslint.getRules()

provideLinter: ->
helpers = require('atom-linter')
provider =
grammarScopes: ['source.css', 'source.html']
scope: 'file'
lintOnFly: true
lint: (textEditor) =>
lint: (textEditor) ->
filePath = textEditor.getPath()
text = textEditor.getText()
settingRules = @rules
try
configData = fs.readFileSync(path.join(path.dirname(filePath), '.csslintrc'), "utf-8")
if configData
fileConfig = JSON.parse(configData)
else
fileConfig = {}
ruleset = gatherRules(fileConfig, settingRules)
lintResult = csslint.verify(text, ruleset)
if lintResult.messages.length < 1
return []
toReturn = []
for data in lintResult.messages
line = data.line - 1
col = data.col - 1
toReturn.push({
type: data.type.charAt(0).toUpperCase() + data.type.slice(1),
text: data.message,
filePath: filePath
range: [[line, col], [line, col]],
trace: [{
type: "Text",
text: '[' + data.rule.id + '] ' + data.rule.desc
}]
})
return toReturn
parameters = ['--format=json', '-']
exec = path.join(__dirname, '..', 'node_modules', 'csslint', 'cli.js')
helpers.execNode(exec, parameters, {stdin: text}).then (output) ->
lintResult = JSON.parse(output)
toReturn = []
if lintResult.messages.length < 1
return toReturn
for data in lintResult.messages
line = data.line - 1
col = data.col - 1
toReturn.push({
type: data.type.charAt(0).toUpperCase() + data.type.slice(1),
text: data.message,
filePath: filePath
range: [[line, col], [line, col]],
trace: [{
type: "Text",
text: '[' + data.rule.id + '] ' + data.rule.desc
}]
})
return toReturn
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"repository": "https://github.com/AtomLinter/linter-csslint",
"license": "MIT",
"dependencies": {
"csslint": "~0.10.0"
"csslint": "AtomLinter/csslint",
"atom-linter": "^3.0.0"
},
"providedServices": {
"linter": {
Expand Down

0 comments on commit 75fcbee

Please sign in to comment.