Skip to content

Commit

Permalink
Added coffeelinting
Browse files Browse the repository at this point in the history
Run by typing 'cake lint' on the command line.
  • Loading branch information
thelinmichael committed Jan 26, 2014
1 parent 269324e commit 5af83e7
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.settings
/node_modules
/demo/js/analytics.js
*.log
23 changes: 11 additions & 12 deletions BttrLazyLoading.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BttrLazyLoading

@$container = $(@options.container)
@constructor.dpr = window.devicePixelRatio if typeof window.devicePixelRatio == 'number'

@whiteList = ['lg', 'md', 'sm', 'xs']
@blackList = []

Expand All @@ -44,7 +44,7 @@ class BttrLazyLoading
###
Private Functions
###
_updateCanvasSize = () ->
_updateCanvasSize = () ->
imgObject = _getImgObject.call @
@$clone.attr 'width', imgObject.width
@$clone.attr 'height', imgObject.height
Expand All @@ -63,7 +63,7 @@ class BttrLazyLoading
if typeof v is 'object'
$.extend(@options[i[0]], v)
else
@options[i[0]] = v if typeof @options[i[0]] isnt 'undefined'
@options[i[0]] = v if typeof @options[i[0]] isnt 'undefined'

_setupEvents = (onOrOff) ->
onLoad = () =>
Expand All @@ -89,7 +89,7 @@ class BttrLazyLoading
@$img.hide()
@$clone.attr 'width', imgObject.width
@$clone.attr 'height', imgObject.height
@$clone.show()
@$clone.show()

setTimeout () =>
@$img.trigger 'bttrlazyloading.beforeLoad'
Expand Down Expand Up @@ -175,18 +175,18 @@ class BttrLazyLoading

if @loaded && @options.updatemanually
return false

imgObject = _getImgObject.call @
if !imgObject.src or @loaded is _getImageSrc.call @, imgObject.src, imgObject.range
return false

threshold = 0
if !@loaded
if !@loaded
threshold = @options.threshold
return _isWithinViewport.call @, threshold

# http://upshots.org/javascript/jquery-test-if-element-is-in-viewport-visible-on-screen
_isWithinViewport = (threshold) ->
_isWithinViewport = (threshold) ->
isWindow = (@options.container is window)
viewport =
top : (if isWindow then @$container.scrollTop() else @$container.offset().top) + threshold
Expand All @@ -198,7 +198,7 @@ class BttrLazyLoading
bounds.right = bounds.left + @$wrapper.outerWidth()
bounds.bottom = bounds.top + @$wrapper.outerHeight()

return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom))

_update = () ->
# If the range changed (window resize) we update the canvas size
Expand Down Expand Up @@ -248,8 +248,8 @@ $.fn.bttrlazyloading.Constructor = BttrLazyLoading

class BttrLazyLoadingGlobal

version : '1.0.0-rc.2'
@ranges =
version : '1.0.0-rc.2'
@ranges =
xs : 767
sm : 768
md : 992
Expand Down Expand Up @@ -292,5 +292,4 @@ class BttrLazyLoadingGlobal
$.extend true, this.constructor.ranges, object
this

$.bttrlazyloading = new BttrLazyLoadingGlobal()

$.bttrlazyloading = new BttrLazyLoadingGlobal()
12 changes: 10 additions & 2 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fs = require 'fs'
CoffeeScript = require 'coffee-script'
{exec} = require 'child_process'
{exec} = require 'child_process'

FILE_COFFEE = 'BttrLazyLoading.coffee'
FILE_COMPILED_JS = 'jquery.bttrlazyloading.js'
Expand All @@ -19,6 +19,9 @@ task 'tag.patch', 'Patch tag incrementation', ->
task 'build', 'Compile and uglify BttrLazyLoading.coffee', ->
compressFiles()

task 'lint', 'Run linting for CoffeeScripts', ->
runLinting()

tag = (version) ->
# Preparing
console.log "Increasing from #{getVersion()} to #{version}..."
Expand All @@ -28,6 +31,11 @@ tag = (version) ->
# Save the new version within the version file if success
fs.writeFileSync FILE_VERSION, version

runLinting = ->
exec './node_modules/.bin/coffeelint -f coffeelint.json ' + [FILE_COFFEE], (err, stdout, stderr) ->
console.log stderr
console.log stdout

compressFiles = ->
try
fs.writeFileSync FILE_COMPILED_JS, copyright + CoffeeScript.compile "#{fs.readFileSync FILE_COFFEE}"
Expand All @@ -50,7 +58,7 @@ run = (cmd, args, successCallback) ->
console.log "command used: #{cmd} #{args.join(' ')}"

# Execute the command
child = spawn cmd, args
child = exec cmd, args

child.on 'exit', (code) ->
# Success
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BttrLazyLoading is a Jquery plugin that allows your web application to defer ima

[Demo and Documentation](http://bttrlazyloading.julienrenaux.fr/)

## Instalation
## Installation

BttrLazyLoading depends on jQuery (meaning jQuery must be included before the plugin files).

Expand Down
114 changes: 114 additions & 0 deletions coffeelint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"coffeescript_error": {
"level": "error"
},
"arrow_spacing": {
"name": "arrow_spacing",
"level": "ignore"
},
"no_tabs": {
"name": "no_tabs",
"level": "ignore"
},
"no_trailing_whitespace": {
"name": "no_trailing_whitespace",
"level": "error",
"allowed_in_comments": false,
"allowed_in_empty_lines": true
},
"max_line_length": {
"name": "max_line_length",
"value": 80,
"level": "ignore",
"limitComments": true
},
"line_endings": {
"name": "line_endings",
"level": "ignore",
"value": "unix"
},
"no_trailing_semicolons": {
"name": "no_trailing_semicolons",
"level": "error"
},
"indentation": {
"name": "indentation",
"value": 2,
"level": "error"
},
"camel_case_classes": {
"name": "camel_case_classes",
"level": "error"
},
"colon_assignment_spacing": {
"name": "colon_assignment_spacing",
"level": "ignore",
"spacing": {
"left": 0,
"right": 0
}
},
"no_implicit_braces": {
"name": "no_implicit_braces",
"level": "ignore",
"strict": true
},
"no_plusplus": {
"name": "no_plusplus",
"level": "ignore"
},
"no_throwing_strings": {
"name": "no_throwing_strings",
"level": "error"
},
"no_backticks": {
"name": "no_backticks",
"level": "error"
},
"no_implicit_parens": {
"name": "no_implicit_parens",
"level": "ignore"
},
"no_empty_param_list": {
"name": "no_empty_param_list",
"level": "ignore"
},
"no_stand_alone_at": {
"name": "no_stand_alone_at",
"level": "ignore"
},
"space_operators": {
"name": "space_operators",
"level": "ignore"
},
"duplicate_key": {
"name": "duplicate_key",
"level": "error"
},
"empty_constructor_needs_parens": {
"name": "empty_constructor_needs_parens",
"level": "ignore"
},
"cyclomatic_complexity": {
"name": "cyclomatic_complexity",
"value": 10,
"level": "ignore"
},
"newlines_after_classes": {
"name": "newlines_after_classes",
"value": 3,
"level": "ignore"
},
"no_unnecessary_fat_arrows": {
"name": "no_unnecessary_fat_arrows",
"level": "warn"
},
"missing_fat_arrows": {
"name": "missing_fat_arrows",
"level": "ignore"
},
"non_empty_constructor_needs_parens": {
"name": "non_empty_constructor_needs_parens",
"level": "ignore"
}
}
21 changes: 21 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', '.' ]
2 info using [email protected]
3 info using [email protected]
4 error install Couldn't read dependencies
5 error Failed to parse json
5 error Unexpected token }
6 error File: /Users/thelinmichael/workspace/BttrLazyLoading/package.json
7 error Failed to parse package.json data.
7 error package.json must be actual JSON, not just JavaScript.
7 error
7 error This is not a bug in npm.
7 error Tell the package author to fix their package.json file. JSON.parse
8 error System Darwin 13.0.0
9 error command "node" "/usr/local/bin/npm" "install" "."
10 error cwd /Users/thelinmichael/workspace/BttrLazyLoading
11 error node -v v0.10.22
12 error npm -v 1.3.21
13 error file /Users/thelinmichael/workspace/BttrLazyLoading/package.json
14 error code EJSONPARSE
15 verbose exit [ 1, true ]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"devDependencies": {
"coffee-script" : "~1.6",
"uglify-js" : "~2.4",
"clean-css" : "1.x"
"clean-css" : "1.x",
"coffeelint" : "~1.0"
}
}

0 comments on commit 5af83e7

Please sign in to comment.