From 2d05590f6be6c5d45a591353eba16c313788f35f Mon Sep 17 00:00:00 2001 From: Eisha CHEN-YEN-SU Date: Wed, 31 Jan 2018 23:04:07 +0100 Subject: [PATCH] main.coffee: Fix old version warning This fixes the old version warning by properly comparing the version numbers between `result` and `COALA_MIN_VERSION` instead of comparing these strings lexicographically. Closes https://github.com/coala/coala-atom/issues/48 --- lib/main.coffee | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/main.coffee b/lib/main.coffee index 7856cf3..99a162d 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -2,6 +2,29 @@ helpers = require 'atom-linter' path = require 'path' +# Test if the version number v1 is older than v2 +isOlderThan = (v1, v2) -> + subversions1 = v1.split('.') + subversions2 = v2.split('.') + for idx in [0..3] + unless Number(subversions1[idx] == Number(subversions2[idx])) + return Number(subversions1[idx]) < Number(subversions2[idx]) + # If the three first version numbers were equal. + if isDevVersion(v1) && isDevVersion(v2) + return devNumber(v1) < devNumber(v2) + else if isDevVersion(v1) && !(isDevVersion(v2)) + return true + # If the version numbers are equal, then v1 is not older than v2. + return false + +isDevVersion = (v) -> + subversions = v.split('.') + return (subversions.length > 3) && (subversions[3].slice(0, 3) == 'dev') + +devNumber = (v) -> + subversions = v.split('.') + return Number(subversions[3].slice(3, subversions.length)) + COALA_MIN_VERSION = '0.10.0' module.exports = config: @@ -29,7 +52,7 @@ module.exports = # Check version of coala version = helpers.exec(@executable, ['--version']).then (result) -> - if result <= COALA_MIN_VERSION + if isOlderThan(result, COALA_MIN_VERSION) atom.notifications.addError \ 'You are using an old version of coala !', 'detail': 'Please upgrade your version of coala.\n