Skip to content

Commit

Permalink
Add jshint target.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-roemer committed Apr 23, 2012
1 parent fe02976 commit 809fb77
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 8 deletions.
20 changes: 15 additions & 5 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ async = require "async"
cakepop = require "./cakepop.js"
pkg = require "./package.json"
utils = cakepop.utils
style = new cakepop.Style()
builder = new cakepop.CoffeeBuild()
style = new cakepop.Style
js:
config: "dev/jshint.json"

SOURCE = [
CS_SOURCE = [
"Cakefile"
"cakepop.coffee"
]

JS_SOURCE = [
"cakepop.js"
]

BUILD = [
"cakepop.coffee"
]
Expand All @@ -23,17 +29,21 @@ codo = (cb) ->
cakepop.coffee -
HISTORY.md", cb

task "dev:prepublish", "Run everything to get ready for publish.", ->
task "prepublish", "Run everything to get ready for publish.", ->
async.series [
(cb) -> style.coffeelint SOURCE, cb
(cb) -> style.coffeelint CS_SOURCE, cb
(cb) -> builder.build BUILD, cb
(cb) -> style.jshint JS_SOURCE, cb
(cb) -> codo cb
], (err) ->
utils.fail err if err
utils.print "\nPrepublish finished successfully".info

task "dev:coffeelint", "Run CoffeeScript style checks.", ->
style.coffeelint SOURCE
style.coffeelint CS_SOURCE

task "dev:jshint", "Run JavaScript style checks.", ->
style.jshint JS_SOURCE

task "source:build", "Build CoffeeScript to JavaScript.", ->
builder.build BUILD
Expand Down
50 changes: 49 additions & 1 deletion cakepop.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,68 @@ class Style
# bin: "coffeelint"
# suffix: "coffee"
# config: null
# js:
# bin: "jshint"
# suffix: "js"
# config: null
#
# @param [Object] opts Options.
# @option opts [String] coffee.bin coffeelint binary path.
# @option opts [String] coffee.suffix CoffeeScript file suffix.
# @option opts [String] coffee.config Path to coffeelint config file.
# @option opts [String] js.bin jshint binary path.
# @option opts [String] js.suffix JavaScript file suffix.
# @option opts [String] js.config Path to jshint config file.
#
constructor: (opts) ->
defaults =
coffee:
bin: "coffeelint"
suffix: "coffee"
config: null
js:
bin: "jshint"
suffix: "js"
config: null

@coffee = extend defaults.coffee, (opts?.coffee ? {})
@js = extend defaults.js, (opts?.js ? {})

# Run jshint on an array of files, directory paths.
#
# **Note**: The `jshint` binary must be installed separately and
# available to a shell invocation.
#
# @param [Array<String>] paths Array of file / directory paths.
# @param [Function] callback Callback on process end (printCallback).
#
jshint: (paths = [], callback = Utils.printCallback) =>
filesRe = new RegExp ".*\\.#{@js.suffix}$"
config = if @js.config then ["--config", @js.config] else []
files = (f for f in paths when filesRe.test f)
dirs = (f for f in paths when not filesRe.test f)

cbs =
searchDirs: (cb) ->
# No directories to search.
return cb null, [] if dirs.length < 1

Utils.find dirs, filesRe, (err, dirFiles) ->
cb err, dirFiles

runLint: ["searchDirs", (cb, results) =>
dirFiles = results?.searchDirs ? []
args = [files, dirFiles, config].reduce (x, y) -> x.concat y

Utils.spawn "#{@js.bin}", args, (code) ->
err = if code is 0 then null else new Error "jshint failed"
cb err
]

async.auto cbs, (err) ->
Utils.fail "JavaScript style checks failed." if err
Utils.print "JavaScript style checks passed.\n".info
callback err

# Run coffeelint on an array of files, directory paths.
#
Expand All @@ -268,7 +316,7 @@ class Style
# @param [Function] callback Callback on process end (printCallback).
#
coffeelint: (paths = [], callback = Utils.printCallback) =>
filesRe = new RegExp "(Cakefile|.*\.#{@coffee.suffix})$"
filesRe = new RegExp "(Cakefile|.*\\.#{@coffee.suffix})$"
config = if @coffee.config then ["--file", @coffee.config] else []
files = (f for f in paths when filesRe.test f)
dirs = (f for f in paths when not filesRe.test f)
Expand Down
78 changes: 76 additions & 2 deletions cakepop.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions dev/jshint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
// Settings for **generated** (CoffeeScript) files.
// Much more permissive, but this does catch some errors, so here goes...
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.

// Environments (predefined globals).
"browser" : false, // Standard browser globals e.g. `window`,.
"node" : true,
"rhino" : false,
"couch" : false,
"wsh" : false, // Windows Scripting Host.

// Libraries (predefined globals).
"jquery" : false,
"prototypejs" : false,
"mootools" : false,
"dojo" : false,

// Custom globals.
"predef" : [
//"exampleVar",
//"anotherCoolGlobal",
//"iLoveDouglas"
],

// Development.
"debug" : false, // Allow debugger statements.
"devel" : true, // Allow dev. statements e.g. `console.log();`.

// ECMAScript 5.
"es5" : true, // Allow ECMAScript 5 syntax.
"strict" : false, // Require `use strict` pragma in every file.
"globalstrict" : false, // Allow global "use strict"
// (also enables 'strict').

// The Good Parts.
"asi" : false, // Tolerate Automatic Semicolon Insertion.
"laxbreak" : false, // Tolerate unsafe line breaks e.g.
// `return [\n] x` without semicolons.
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"boss" : false, // Tolerate assignments inside if, for & while.
"curly" : false, // Require {} for every new block or scope.
"eqeqeq" : false, // Require triple equals i.e. `===`.
"eqnull" : true, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : false, // Tolerate `for in` loops without
// `hasOwnPrototype`.
"immed" : false, // Require immediate invocations to be wrapped in
// parens e.g. `( function(){}() );`
"latedef" : true, // Prohibit variable use before definition.
"loopfunc" : false, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and
// `arguments.callee`.
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : true, // Tolerate script-targeted URLs.
"shadow" : true, // Allows re-defined variables later in code.
"supernew" : false, // Tolerate `new function () { ... };` and
// `new Object;`.
"undef" : true, // Require all non-global variables be declared
// before they are used.

// Personal styling preferences.
"newcap" : true, // Require capitalization of all constructor
// functions e.g. `new F()`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"nomen" : false, // Prohibit use of initial or trailing underbars.
"onevar" : true, // Allow only one `var` statement per function.
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false, // Tolerate all forms of subscript notation.
"trailing" : true, // Prohibit trailing whitespaces.
"white" : false, // Check against strict whitespace / indent rules.
"maxlen" : 200, // Line length.
"indent" : 2 // Specify indentation spacing
}

0 comments on commit 809fb77

Please sign in to comment.