Skip to content

Commit f12145e

Browse files
committed
- add linting step for framework development
1 parent a3f2c57 commit f12145e

19 files changed

+135
-53
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
2-
node_modules
2+
node_modules
3+
npm-debug.log

.jshintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
src/node_modules
3+
src/all/node_modules
4+
src/all/app/public
5+
.git

.jshintrc

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
// Global settings
3+
"passfail": false // Stop on first error.
4+
, "browser": false
5+
, "node": true
6+
7+
// framework globals
8+
, "predef": ["klass", "v"] // klass and Valentine
9+
10+
// Development.
11+
, "devel": true // Allow developments statements e.g. `console.log();`.
12+
, "es5": true // Allow ECMAScript 5 syntax.
13+
14+
// Core
15+
, "asi": true // Tolerate Automatic Semicolon Insertion (no semicolons).
16+
, "laxbreak": true // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
17+
, "laxcomma": true // Tolerate leading commas.
18+
, "bitwise": false // Prohibit bitwise operators (&, |, ^, etc.).
19+
, "boss": true // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
20+
, "curly": false // Require {} for every new block or scope.
21+
, "eqeqeq": false // Require triple equals i.e. `===`.
22+
, "eqnull": true // Tolerate use of `== null`.
23+
, "evil": false // Tolerate use of `eval`.
24+
, "forin": false // Tolerate `for in` loops without `hasOwnPrototype`.
25+
, "immed": false // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
26+
, "latedef": false // Prohipit variable use before definition.
27+
, "loopfunc": true // Allow functions to be defined within loops.
28+
, "noarg": true // Prohibit use of `arguments.caller` and `arguments.callee`.
29+
, "regexp": false // Prohibit `.` and `[^...]` in regular expressions.
30+
, "expr": true // allow boss style expressions (foo && foo())
31+
, "regexdash": true // Tolerate unescaped last dash i.e. `[-...]`.
32+
, "shadow": false // Allows re-define variables later in code e.g. `var x=1; x=2;`.
33+
, "supernew": false // Tolerate `new function () { ... };` and `new Object;`.
34+
, "undef": true // Require all non-global variables be declared before they are used.
35+
36+
// Personal styles
37+
, "newcap": true // Require capitalization of all constructor functions e.g. `new F()`.
38+
, "noempty": false // Prohibit use of empty blocks.
39+
, "nonew": false // Prohibit use of constructors for side-effects.
40+
, "onevar": false // Allow only one `var` statement per function.
41+
, "plusplus": false // Prohibit use of `++` & `--`.
42+
, "sub": true // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
43+
, "trailing": true // Prohibit trailing whitespaces.
44+
, "white": true // Check against strict whitespace and indentation rules.
45+
, "indent": 2 // Specify indentation spacing
46+
, "whitespace": true
47+
, "smarttabs": false // no mixed tabs and spaces! use spaces!
48+
}

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,13 @@ The Valentine module is included as a simple tool giving you type checking, func
258258
$ matador controller [name]
259259
$ matador model [name]
260260

261-
# Todo
262-
There are always things to do. Our short-list currently includes the following:
263-
264-
* ~~build more scaffolding commands (for models, controllers, helpers)~~
265-
* ~~better view partials support~~
266-
* official docs
267-
268-
269-
# Contributing
261+
# Contributing & Development
270262

271263
Questions, pull requests, bug reports are all welcome. Submit them here on Github.
264+
When submitting pull requests, please run through the linter to conform to the framework style
265+
266+
$ npm install -d
267+
$ npm run-script lint
272268

273269
# Authors
274270

dev/reporter.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
reporter: function reporter(results) {
3+
var len = results.length
4+
, str = ''
5+
, file
6+
, error
7+
8+
results.forEach(function (result) {
9+
file = result.file
10+
error = result.error
11+
str += file + ': line ' + error.line + ', col ' +
12+
error.character + ', ' + error.reason + '\n'
13+
})
14+
15+
if (str) {
16+
process.stdout.write(str + "\n" + len + ' error' + ((len === 1) ? '' : 's') + "\n")
17+
}
18+
else {
19+
process.stdout.write('Rock on. No Errors!\n')
20+
}
21+
}
22+
}

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@
2828
, "hogan.js": "*"
2929
, "optimist": "*"
3030
}
31+
, "devDependencies": {
32+
"jshint": "0.5.8"
33+
}
34+
, "scripts": {
35+
"lint": "node_modules/jshint/bin/hint src/ --reporter dev/reporter.js"
36+
}
3137
}

src/BaseController.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ var fs = require('fs')
33
module.exports = function (app) {
44
var viewCache = {}
55

6-
return Class(function () {
6+
return klass(function () {
77
this._paths = [app.set('base_dir')]
88
this.beforeFilters = {}
99
this.excludeFilters = {}
1010
var viewOptions = app.set('view options')
1111
this.layout = (viewOptions && typeof viewOptions.layout !== 'undefined') ? viewOptions.layout : 'layout'
1212
})
1313
.methods({
14-
addBeforeFilter: function (actions, fn) {
15-
if (!fn) { fn = actions, actions = '*' }
14+
addBeforeFilter: function (actions, fn) {
15+
if (!fn) {
16+
fn = actions
17+
actions = '*'
18+
}
1619
v(v.is.arr(actions) ? actions : [actions]).each(function (action) {
1720
if (typeof this.beforeFilters[action] === 'undefined') this.beforeFilters[action] = []
1821
this.beforeFilters[action].push(fn)
@@ -21,7 +24,7 @@ module.exports = function (app) {
2124

2225
, addExcludeFilter: function (actions, fn) {
2326
v(v.is.arr(actions) ? actions : [actions]).each(function (action) {
24-
if(typeof this.excludeFilters[action] === 'undefined') this.excludeFilters[action] = []
27+
if (typeof this.excludeFilters[action] === 'undefined') this.excludeFilters[action] = []
2528
this.excludeFilters[action].push(fn)
2629
}, this)
2730
}
@@ -37,7 +40,7 @@ module.exports = function (app) {
3740
, render: function (res, view, data, fn) {
3841
if (!viewCache[view]) {
3942
var suffix = '.' + app.set('view engine')
40-
v.find(this._paths, function(p) {
43+
v.find(this._paths, function (p) {
4144
try {
4245
var viewFile = p + '/views/' + view
4346
fs.statSync(viewFile + suffix)
@@ -55,7 +58,8 @@ module.exports = function (app) {
5558
layout: this.layout
5659
, locals: data
5760
, partials: app.getPartials(this._paths)
58-
}, fn)
61+
}, fn
62+
)
5963
}
6064
})
6165
}

src/StaticController.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs')
22
, path = require('path')
33

44
function Cache() {
5-
this._ = {}
5+
this._ = {}
66
}
77
Cache.prototype = {
88
get: function (k) {
@@ -15,7 +15,7 @@ Cache.prototype = {
1515
}
1616

1717
var cache = new Cache()
18-
module.exports = function(app, config) {
18+
module.exports = function (app, config) {
1919
return app.controllers.Base.extend(function () {
2020
this.layout = false
2121
})
@@ -36,8 +36,8 @@ module.exports = function(app, config) {
3636
return '<a href="' + f + '">' + f + '</a>'
3737
})
3838
this.render(response, 'directory', {
39-
directory: req
40-
, files: files
39+
directory: req
40+
, files: files
4141
})
4242
}
4343
})

src/StubController.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
module.exports = function(app,config) {
2-
3-
return app.getController("Application",true).extend()
1+
module.exports = function (app, config) {
2+
3+
return app.getController("Application", true).extend()
44
.methods({
55
index: function (req, res) {
66

77
}
88
})
9-
9+
1010
}

src/StubModel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module.exports = function(app,config) {
1+
module.exports = function (app, config) {
22

3-
return app.getModel("Application",true).extend()
3+
return app.getModel("Application", true).extend()
44

55
}

src/all/app/config/development.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
models: {}
3-
, services: {}
4-
, controllers: {}
2+
models: {}
3+
, services: {}
4+
, controllers: {}
55
}

src/all/app/config/production.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
models: {}
3-
, services: {}
4-
, controllers: {}
2+
models: {}
3+
, services: {}
4+
, controllers: {}
55
}

src/all/app/config/routes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function(app) {
1+
module.exports = function (app) {
22
return {
33
root: [
44
['get', '/', 'Home']

src/all/app/controllers/HomeController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function(app, config) {
1+
module.exports = function (app, config) {
22
return app.getController("Application", true).extend()
33
.methods({
44
index: function (req, res) {
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = function(app,config) {
2-
return app.getModel('Base',true).extend()
1+
module.exports = function (app, config) {
2+
return app.getModel('Base', true).extend()
33
}

src/all/app/models/BaseModel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = function(app,config) {
2-
return Class()
1+
module.exports = function (app, config) {
2+
return klass()
33
}

src/all/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var matador = require('matador')
22
, env = process.env.NODE_ENV || 'development'
33
, argv = matador.argv
4-
, config = require("./app/config/" + env)
4+
, config = require('./app/config/' + env)
55
, app = matador.createApp(__dirname, config, {})
66
, port = argv.port || 3000
77

src/matador.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs')
22
, express = module.exports = require('express')
33
, path = require('path')
44
, hogan = require('hogan.js')
5-
, Class = global.Class = require('klass')
5+
, klass = global.klass = require('klass')
66
, v = global.v = require('valentine')
77
, router = require('./router')
88
, argv = module.exports.argv = require('optimist').argv
@@ -12,9 +12,9 @@ module.exports.createApp = function (baseDir, configuration, options) {
1212
options = options || {}
1313

1414
var appDir = baseDir + "/app"
15-
, fileCache = {'services':{},'helpers':{},'models':{}, 'controllers':{}}
16-
, objCache = {'services':{},'helpers':{},'models':{}, 'controllers':{}}
17-
, pathCache = {'services':{},'helpers':{},'models':{}, 'controllers':{}}
15+
, fileCache = {'services': {}, 'helpers': {}, 'models': {}, 'controllers': {}}
16+
, objCache = {'services': {}, 'helpers': {}, 'models': {}, 'controllers': {}}
17+
, pathCache = {'services': {}, 'helpers': {}, 'models': {}, 'controllers': {}}
1818
, partialCache = {}
1919
, appDirs = [appDir].concat(v(function () {
2020
var dir = appDir + '/modules'
@@ -35,18 +35,18 @@ module.exports.createApp = function (baseDir, configuration, options) {
3535
return false
3636
}
3737
fileCache[subdir][name] = require(filename)(app, (configuration[subdir] && configuration[subdir][name] ? configuration[subdir][name] : {}))
38-
pathCache[subdir][name] = dir === appDir ? [appDir] : [dir,appDir]
38+
pathCache[subdir][name] = dir === appDir ? [appDir] : [dir, appDir]
3939
return true
4040
})
4141
if (!dir) throw new Error("Unable to find " + subdir + "/" + name)
4242

4343
return fileCache[subdir][name]
4444
}
4545
, loadClass = function (subdir, name, definitionOnly) {
46-
if(definitionOnly) return loadFile(subdir, name)
46+
if (definitionOnly) return loadFile(subdir, name)
4747
if (!objCache[subdir][name]) {
48-
var file = loadFile(subdir, name)
49-
objCache[subdir][name] = new file
48+
var File = loadFile(subdir, name)
49+
objCache[subdir][name] = new File()
5050
objCache[subdir][name]._paths = pathCache[subdir][name]
5151
}
5252
return objCache[subdir][name]
@@ -93,7 +93,7 @@ module.exports.createApp = function (baseDir, configuration, options) {
9393
v.each(appDirs, function (dir) {
9494
try {
9595
v.each(fs.readdirSync(dir + "/" + type), function (file) {
96-
if(file.substr(file.length - 3) === '.js') file = file.substr(0, file.length - 3)
96+
if (file.substr(file.length - 3) === '.js') file = file.substr(0, file.length - 3)
9797
loadFile(type, file, dir)
9898
})
9999
}
@@ -126,7 +126,7 @@ module.exports.createApp = function (baseDir, configuration, options) {
126126
v.each(fs.readdirSync(fullPath), function (partial) {
127127
var viewFile = localDir
128128
+ (localDir.length ? "/" : "")
129-
+ partial.substr(0,partial.length-viewSuffix.length)
129+
+ partial.substr(0, partial.length - viewSuffix.length)
130130
, partialContent = fs.readFileSync(fullPath + "/" + partial, 'utf8')
131131

132132
pathPartials[viewFile] = hogan.compile(partialContent)
@@ -143,7 +143,7 @@ module.exports.createApp = function (baseDir, configuration, options) {
143143

144144
v.each(objs, function (obj) {
145145
v.each(obj, function (name, partial) {
146-
if(!partials[name]) partials[name] = partial
146+
if (!partials[name]) partials[name] = partial
147147
})
148148
})
149149
return partials
@@ -155,7 +155,7 @@ module.exports.createApp = function (baseDir, configuration, options) {
155155

156156
app.getController = function (name, definitionOnly) {
157157
if (app.controllers[name]) {
158-
return definitionOnly ? app.controllers[name] : new app.controllers[name]
158+
return definitionOnly ? app.controllers[name] : new app.controllers[name]()
159159
}
160160
else {
161161
return loadClass('controllers', name + "Controller", definitionOnly)

src/router.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function match(app, prefix, method, route, middleware, controllerName, action) {
1010
if (filters.length) {
1111
middleware = typeof Controller.excludeFilters[action] === 'undefined' ?
1212
filters.concat(middleware) :
13-
v(filters).filter(function(filter){
13+
v(filters).filter(function (filter) {
1414
return !v.inArray(Controller.excludeFilters[action], filter)
1515
}).concat(middleware)
1616
}
@@ -23,7 +23,7 @@ function match(app, prefix, method, route, middleware, controllerName, action) {
2323
module.exports.init = function (app, routes) {
2424
// static directory server
2525
routes.root.push(['get', /(.+)/, 'Static'])
26-
v.each(routes, function(key, value) {
26+
v.each(routes, function (key, value) {
2727
v(value).each(function (tuple) {
2828
var tupleLen = tuple.length
2929
, numOptionalArgs = tupleLen - 2

0 commit comments

Comments
 (0)