From deb978614c658ea74e7374ca4053e48ffb13eb82 Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Mon, 18 Jan 2016 21:18:55 +0100 Subject: [PATCH] Adds disabling of linting --- init.coffee | 6 +++++- linter-mzn.coffee | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/init.coffee b/init.coffee index f1fb36d..3710783 100644 --- a/init.coffee +++ b/init.coffee @@ -2,10 +2,14 @@ module.exports = AtomLanguageMZN = config: + enableLinter: + type: 'boolean' + default: true + description: "Enable linting using `mzn2fzn`" mzn2fznPath: type: 'string' default: 'mzn2fzn' - description: "Path to Minizinc's compiler `mzn2fzn`" + description: 'Path to Minizinc\'s compiler `mzn2fzn`' activate: (state) -> console.log 'language-mzn: package loaded, diff --git a/linter-mzn.coffee b/linter-mzn.coffee index f078277..8207205 100644 --- a/linter-mzn.coffee +++ b/linter-mzn.coffee @@ -7,30 +7,33 @@ class LinterMZN atom.config.get "language-mzn.#{key}" lint: (textEditor) => - return new Promise (resolve, reject) => - output = '' - command = @config 'mzn2fznPath' - args = ['--instance-check-only', textEditor.getPath()] - options = process.env + if @config 'enableLinter' + return new Promise (resolve, reject) => + output = '' + command = @config 'mzn2fznPath' + args = ['--instance-check-only', textEditor.getPath()] + options = process.env - stdout = (data) -> - atom.notifications.addWarning data - stderr = (data) -> - output += data - exit = (code) => - if code is 0 + stdout = (data) -> + atom.notifications.addWarning data + stderr = (data) -> + output += data + exit = (code) => + if code is 0 + resolve [] + else + messages = @parse output, textEditor.getPath() + resolve messages + + @lintProcess = new BufferedProcess({command, args, options, stdout, stderr, exit}) + @lintProcess.onWillThrowError ({error, handle}) -> + atom.notifications.addError "Failed to run #{command}", + detail: "#{error.message}" + dismissable: true + handle() resolve [] - else - messages = @parse output, textEditor.getPath() - resolve messages - - @lintProcess = new BufferedProcess({command, args, options, stdout, stderr, exit}) - @lintProcess.onWillThrowError ({error, handle}) -> - atom.notifications.addError "Failed to run #{command}", - detail: "#{error.message}" - dismissable: true - handle() - resolve [] + else + return [] parse: (output, filePath) => messages = []