From cce18c052ac92bd57e7e4803f9a8a2ef7b260f7f Mon Sep 17 00:00:00 2001 From: 1000ch Date: Sun, 26 Jul 2015 16:47:47 +0900 Subject: [PATCH 1/4] rewrite --- index.js | 41 ++++++++++++++++++++++++++++++++++++++ lib/init.coffee | 10 ---------- lib/linter-jsonlint.coffee | 34 ------------------------------- package.json | 14 +++++++++---- 4 files changed, 51 insertions(+), 48 deletions(-) create mode 100644 index.js delete mode 100644 lib/init.coffee delete mode 100644 lib/linter-jsonlint.coffee diff --git a/index.js b/index.js new file mode 100644 index 0000000..85a8252 --- /dev/null +++ b/index.js @@ -0,0 +1,41 @@ +'use babel'; + +import { Range } from 'atom'; +import jsonlint from 'jsonlint'; + +export default class LinterJsonLint { + + static activate() {} + + static deactivate() {} + + static regex = '.+?line\\s(\\d+)' + + static provideLinter() { + return { + grammarScopes: ['source.json'], + scope: 'file', + lintOnFly: true, + lint: (editor) => { + + let path = editor.getPath(); + let text = editor.getText(); + + try { + jsonlint.parse(text); + } catch (e) { + let line = e.message.match(this.regex)[1]; + return [{ + type: 'error', + text: e.message, + filePath: path, + range: new Range([Number(line), 0]) + }]; + } + + return []; + } + } + } + +} \ No newline at end of file diff --git a/lib/init.coffee b/lib/init.coffee deleted file mode 100644 index f10ea55..0000000 --- a/lib/init.coffee +++ /dev/null @@ -1,10 +0,0 @@ -path = require 'path' - -module.exports = - config: - jsonlintExecutablePath: - type: 'string' - default: path.join __dirname, '..', 'node_modules', 'jsonlint', 'lib' - - activate: -> - console.log 'activate linter-jsonlint' diff --git a/lib/linter-jsonlint.coffee b/lib/linter-jsonlint.coffee deleted file mode 100644 index 90a1b8c..0000000 --- a/lib/linter-jsonlint.coffee +++ /dev/null @@ -1,34 +0,0 @@ -linterPath = atom.packages.getLoadedPackage("linter").path -Linter = require "#{linterPath}/lib/linter" -findFile = require "#{linterPath}/lib/util" - -class LinterJsonlint extends Linter - # The syntax that the linter handles. May be a string or - # list/tuple of strings. Names should be all lowercase. - @syntax: 'source.json' - - # A string, list, tuple or callable that returns a string, list or tuple, - # containing the command line (with arguments) used to lint. - cmd: 'cli.js -cq' - - linterName: 'jsonlint' - - isNodeExecutable: yes - - errorStream: 'stderr' - - # A regex pattern used to extract information from the executable's output. - regex: - '.+?line\\s(?\\d+),\\scol\\s(?\\d+),\\s(?.+)' - - constructor: (editor)-> - super(editor) - - @configSubscription = atom.config.observe 'linter-jsonlint.jsonlintExecutablePath', => - @executablePath = atom.config.get 'linter-jsonlint.jsonlintExecutablePath' - - destroy: -> - super - @configSubscription.dispose() - -module.exports = LinterJsonlint diff --git a/package.json b/package.json index 5db7da4..18736f0 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,21 @@ { "name": "linter-jsonlint", - "linter-package": true, - "main": "./lib/init", + "main": "index.js", "version": "0.1.4", "description": "Lint JSON on the fly", "repository": "https://github.com/AtomLinter/linter-jsonlint", "license": "MIT", "engines": { - "atom": ">0.50.0" + "atom": ">=1.0.0" }, "dependencies": { - "jsonlint": "~1.6.0" + "jsonlint": "~1.6.2" + }, + "providedServices": { + "linter": { + "versions": { + "1.0.0": "provideLinter" + } + } } } From 133d256796098e7ae10a5970fe7ddaccac7933d0 Mon Sep 17 00:00:00 2001 From: 1000ch Date: Mon, 27 Jul 2015 11:08:13 +0900 Subject: [PATCH 2/4] update --- index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 85a8252..dc9005d 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,6 @@ import jsonlint from 'jsonlint'; export default class LinterJsonLint { - static activate() {} - - static deactivate() {} - static regex = '.+?line\\s(\\d+)' static provideLinter() { @@ -24,12 +20,15 @@ export default class LinterJsonLint { try { jsonlint.parse(text); } catch (e) { - let line = e.message.match(this.regex)[1]; + + let line = Number(e.message.match(this.regex)[1]); + let column = 0; + return [{ type: 'error', text: e.message, filePath: path, - range: new Range([Number(line), 0]) + range: new Range([line, column], [line, column]) }]; } @@ -38,4 +37,4 @@ export default class LinterJsonLint { } } -} \ No newline at end of file +} From 15b55522944a421272397eec984a0755845de5a8 Mon Sep 17 00:00:00 2001 From: 1000ch Date: Tue, 28 Jul 2015 22:19:22 +0900 Subject: [PATCH 3/4] s/e/E --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index dc9005d..8cbc15f 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ export default class LinterJsonLint { let column = 0; return [{ - type: 'error', + type: 'Error', text: e.message, filePath: path, range: new Range([line, column], [line, column]) From 96af916dd8cf738c5d99e692414fc691d649bf99 Mon Sep 17 00:00:00 2001 From: 1000ch Date: Tue, 28 Jul 2015 22:20:30 +0900 Subject: [PATCH 4/4] make diff --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8cbc15f..17997d7 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ export default class LinterJsonLint { type: 'Error', text: e.message, filePath: path, - range: new Range([line, column], [line, column]) + range: new Range([line, column], [line, column + 1]) }]; }