Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Show a warning if your local CoffeeLint needs upgrading
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
AsaAyers committed May 25, 2015
1 parent 390727d commit 4740ac7
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions lib/linter-coffeelint.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,36 @@ class LinterCoffeelint extends Linter
}))
return 'coffeelint'

configImportsModules: (config) ->
return true for ruleName, rconfig of config when rconfig.module?
return userConfig?.coffeelint?.transforms?

canImportModules: (coffeelint) ->
[major, minor, patch] = coffeelint.VERSION.split('.').map(toInt)

if major > 1
return true
if major is 1 and minor > 9
return true
if major is 1 and minor is 9 and patch >= 5
return true
false

isCompatibleWithAtom: (coffeelint) ->
[major, minor, patch] = coffeelint.VERSION.split('.').map(toInt)

if major > 1
return true
if major is 1 and minor > 9
return true
if major is 1 and minor is 9 and patch >= 1
return true
false

lintFile: (filePath, callback) ->
filename = path.basename filePath
origPath = path.join @cwd, filename
showUpgradeError = false

coffeeLintPath = @_resolveCoffeeLint(origPath)
coffeelint = require(coffeeLintPath)
Expand All @@ -36,9 +63,10 @@ class LinterCoffeelint extends Linter
# this assumption, so CoffeeLint < 1.9.1 will fail to find CoffeeScript.
# See https://github.com/clutchski/coffeelint/pull/383
[major, minor, patch] = coffeelint.VERSION.split('.').map(toInt)
if (major <= 1 and minor < 9) or (major is 1 and minor is 9 and patch is 0)
if not @isCompatibleWithAtom(coffeelint)
coffeeLintPath = 'coffeelint'
coffeelint = require(coffeeLintPath)
showUpgradeError = true

configFinder = require("#{coffeeLintPath}/lib/configfinder")

Expand All @@ -47,7 +75,12 @@ class LinterCoffeelint extends Linter

try
config = configFinder.getConfig(origPath)
result = coffeelint.lint(source, config, isLiterate)
console.log('using coffeelint', coffeelint.VERSION,
@configImportsModules(config), @canImportModules(coffeelint) )
if @configImportsModules(config) and not @canImportModules(coffeelint)
showUpgradeError = true
else
result = coffeelint.lint(source, config, isLiterate)
catch e
result = []
console.log(e.message)
Expand All @@ -59,6 +92,14 @@ class LinterCoffeelint extends Linter
rule: 'none'
})

if showUpgradeError
result = [{
lineNumber: 1
level: 'error'
message: "http://git.io/local_upgrade upgrade your project's CoffeeLint"
rule: 'none'
}]

callback(result.map(@transform))

transform: (m) =>
Expand Down

0 comments on commit 4740ac7

Please sign in to comment.