diff --git a/.gitignore b/.gitignore index ade14b9..7524296 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store +.idea npm-debug.log node_modules diff --git a/README.md b/README.md index 24846ee..98f9b98 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,16 @@ This linter plugin for [Linter](https://github.com/AtomLinter/Linter) provides a Linter package must be installed in order to use this plugin. If Linter is not installed, please follow the instructions [here](https://github.com/AtomLinter/Linter). ### Plugin installation -``` +```ShellSession $ apm install linter-csslint ``` ## Settings You can configure linter-csslint by editing ~/.atom/config.cson (choose Open Your Config in Atom menu): -``` +```cson 'linter-csslint': - 'csslintExecutablePath': null #csslint path. run 'which csslint' to find the path + #csslint path. run 'which csslint' to find the path + 'executablePath': null ``` ## Contributing @@ -25,15 +26,12 @@ If you would like to contribute enhancements or fixes, please do the following: 1. Hack on a separate topic branch created from the latest `master`. 1. Commit and push the topic branch. 1. Make a pull request. -1. welcome to the club +1. Welcome to the club! Please note that modifications should follow these coding guidelines: - Indent is 2 spaces. -- Code should pass coffeelint linter. +- Code should pass [CoffeeLint](http://www.coffeelint.org/) with the provided `coffeelint.json` - Vertical whitespace helps readability, don’t be afraid to use it. -Thank you for helping out! - -## Donation -[![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) +**Thank you for helping out!** diff --git a/coffeelint.json b/coffeelint.json new file mode 100644 index 0000000..cf6b722 --- /dev/null +++ b/coffeelint.json @@ -0,0 +1,38 @@ +{ + "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" + } +} diff --git a/lib/init.coffee b/lib/init.coffee deleted file mode 100644 index a194ab1..0000000 --- a/lib/init.coffee +++ /dev/null @@ -1,11 +0,0 @@ -path = require 'path' - -module.exports = - config: - csslintExecutablePath: - default: path.join __dirname, '..', 'node_modules', '.bin' - title: 'CSSLint Executable Path' - type: 'string' - - activate: -> - console.log 'activate linter-csslint' diff --git a/lib/linter-csslint.coffee b/lib/linter-csslint.coffee deleted file mode 100644 index f3ab838..0000000 --- a/lib/linter-csslint.coffee +++ /dev/null @@ -1,37 +0,0 @@ -linterPath = atom.packages.getLoadedPackage("linter").path -Linter = require "#{linterPath}/lib/linter" - -class LinterCsslint extends Linter - - # The syntax that the linter handles. May be a string or - # list/tuple of strings. Names should be all lowercase. - @syntax: ['source.css', 'source.html'] - - # A string, list, tuple or callable that returns a string, list or tuple, - # containing the command line (with arguments) used to lint. - cmd: 'csslint --format=compact' - - linterName: 'csslint' - - # A regex pattern used to extract information from the executable's output. - regex: - '.+:\\s*' + # filename - # csslint emits errors that pertain to the code as a whole, - # in which case there is no line/col information, so that - # part is optional. - '(line (?\\d+), col (?\\d+), )?' + - '((?Error)|(?Warning)) - (?.*)' - - #isNodeExecutable: yes - - constructor: (editor)-> - super(editor) - - @configSubscription = atom.config.observe 'linter-csslint.csslintExecutablePath', => - @executablePath = atom.config.get 'linter-csslint.csslintExecutablePath' - - destroy: -> - super - @configSubscription.dispose() - -module.exports = LinterCsslint diff --git a/lib/main.coffee b/lib/main.coffee new file mode 100644 index 0000000..d8bbbb6 --- /dev/null +++ b/lib/main.coffee @@ -0,0 +1,34 @@ +helpers = require('atom-linter') +path = require('path') + +module.exports = + provideLinter: -> + helpers = require('atom-linter') + provider = + grammarScopes: ['source.css', 'source.html'] + scope: 'file' + lintOnFly: true + lint: (textEditor) -> + filePath = textEditor.getPath() + text = textEditor.getText() + 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 diff --git a/package.json b/package.json index 178147a..4d68912 100644 --- a/package.json +++ b/package.json @@ -6,16 +6,20 @@ "linter", "lint" ], - "main": "./lib/init", - "linter-package": true, - "version": "0.0.14", + "main": "./lib/main", + "version": "0.0.15", "description": "Lint CSS on the fly, using csslint", "repository": "https://github.com/AtomLinter/linter-csslint", "license": "MIT", - "engines": { - "atom": ">0.50.0" - }, "dependencies": { - "csslint": "~0.10.0" + "csslint": "AtomLinter/csslint", + "atom-linter": "^3.0.0" + }, + "providedServices": { + "linter": { + "versions": { + "1.0.0": "provideLinter" + } + } } }