Skip to content

Commit

Permalink
main.coffee: Fix old version warning
Browse files Browse the repository at this point in the history
This fixes the old version warning by properly compare
the version numbers between `result` and `COALA_MIN_VERSION`
instead of comparing these strings lexicographically.

Closes coala#48
  • Loading branch information
Kagamihime committed Jan 31, 2018
1 parent 64b758d commit 9152296
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9152296

Please sign in to comment.