diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..636843b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*.js] +indent_style=tab +trim_trailing_whitespace=true \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..4a6159c --- /dev/null +++ b/.eslintrc @@ -0,0 +1,24 @@ +{ + "env": { + "node": true + }, + "rules": { + "strict": 0, + "camelcase": 0, + "curly": 0, + "indent": [2, "tab", { "SwitchCase": 1 }], + "eol-last": 1, + "no-shadow": 0, + "no-redeclare": 2, + "no-extra-bind": 1, + "no-empty": 0, + "no-process-exit": 1, + "no-underscore-dangle": 0, + "no-use-before-define": 0, + "no-unused-vars": 0, + "consistent-return": 0, + "no-inner-declarations": 1, + "no-loop-func": 1, + "space-before-function-paren": [2, "never"] + } +} \ No newline at end of file diff --git a/.jsbeautifyrc b/.jsbeautifyrc new file mode 100644 index 0000000..79b0498 --- /dev/null +++ b/.jsbeautifyrc @@ -0,0 +1,25 @@ +{ + "js": { + "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"], + "brace_style": "collapse", + "break_chained_methods": false, + "e4x": true, + "eval_code": false, + "end_with_newline": true, + "indent_char": "\t", + "indent_level": 0, + "indent_size": 1, + "indent_with_tabs": true, + "jslint_happy": false, + "jslint_happy_align_switch_case": true, + "space_after_anon_function": false, + "keep_array_indentation": false, + "keep_function_indentation": false, + "max_preserve_newlines": 2, + "preserve_newlines": true, + "space_before_conditional": false, + "space_in_paren": false, + "unescape_strings": false, + "wrap_line_length": 0 + } +} \ No newline at end of file diff --git a/index.js b/index.js index 49c1a40..f8dc4e1 100644 --- a/index.js +++ b/index.js @@ -6,14 +6,14 @@ var webpack = require("webpack"); var SingleEntryDependency = require("webpack/lib/dependencies/SingleEntryDependency"); function Plugin( - /* config.webpack */webpackOptions, - /* config.webpackServer */webpackServerOptions, - /* config.webpackMiddleware */webpackMiddlewareOptions, - /* config.basePath */basePath, - /* config.files */files, - /* config.frameworks */frameworks, - customFileHandlers, - emitter) { + webpackOptions, /* config.webpack */ + webpackServerOptions, /* config.webpackServer */ + webpackMiddlewareOptions, /* config.webpackMiddleware */ + basePath, /* config.basePath */ + files, /* config.files */ + frameworks, /* config.frameworks */ + customFileHandlers, + emitter) { webpackOptions = _.clone(webpackOptions) || {}; webpackMiddlewareOptions = _.clone(webpackMiddlewareOptions || webpackServerOptions) || {}; @@ -97,7 +97,7 @@ function Plugin( } }); - emitter.on("exit", function (done) { + emitter.on("exit", function(done) { middleware.close(); done(); }); @@ -117,7 +117,7 @@ Plugin.prototype.addFile = function(entry) { Plugin.prototype.make = function(compilation, callback) { async.forEach(this.files.slice(), function(file, callback) { var entry = file; - if (this.wrapMocha) { + if(this.wrapMocha) { entry = require.resolve("./mocha-env-loader") + "!" + entry; } @@ -159,22 +159,22 @@ Plugin.prototype.readFile = function(file, callback) { if(!this.waiting) doRead(); else - // Retry to read once a build is finished - // do it on process.nextTick to catch changes while building + // Retry to read once a build is finished + // do it on process.nextTick to catch changes while building this.waiting.push(process.nextTick.bind(process, this.readFile.bind(this, file, callback))); }; -function createPreprocesor(/* config.basePath */basePath, webpackPlugin) { +function createPreprocesor( /* config.basePath */ basePath, webpackPlugin) { return function(content, file, done) { - if (webpackPlugin.addFile(file.path)) { + if(webpackPlugin.addFile(file.path)) { // recompile as we have an asset that we have not seen before webpackPlugin.middleware.invalidate(); } // read blocks until bundle is done webpackPlugin.readFile(path.relative(basePath, file.path), function(err, content) { - if (err) { + if(err) { throw err; } diff --git a/mocha-env-loader.js b/mocha-env-loader.js index ee60406..fcca33c 100644 --- a/mocha-env-loader.js +++ b/mocha-env-loader.js @@ -21,7 +21,7 @@ module.exports = function(content, map) { var concatSrc = new SourceNode(); concatSrc.add([ - "describe(" + JSON.stringify(id) + ", function() {\n", + "describe(" + JSON.stringify(id) + ", function() {\n", sourceNode, "\n});" ]); diff --git a/package.json b/package.json index bea9489..c5b1608 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,19 @@ "webpack-dev-middleware": "^1.0.11" }, "devDependencies": { + "beautify-lint": "^1.0.4", + "coffee-loader": "~0.7.2", + "eslint": "^3.1.1", + "jsbeautify": "^0.3.6", "karma": ">=0.13.2 < 1", - "karma-mocha": "~0.1.9", "karma-chrome-launcher": "~0.1.5", - "karma-spec-reporter": "~0.0.16", - "coffee-loader": "~0.7.2" + "karma-mocha": "~0.1.9", + "karma-spec-reporter": "~0.0.16" + }, + "scripts": { + "pretest": "npm run lint && npm run beautify-lint", + "lint": "eslint lib", + "beautify-lint": "beautify-lint *.js" }, "license": "MIT", "homepage": "http://github.com/webpack/karma-webpack",