This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
93c4bb6
commit 75fcbee
Showing
2 changed files
with
25 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters