diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..9c283d6 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,7 @@ +coverage/ +demo/ +dist/ +node_modules +support/demo_template/sample.js +benchmark/implementations/ +test/browser diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..b9e2f83 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,118 @@ +env: + node: true + browser: false + +plugins: + - nodeca + +rules: + # block-scoped-var: 2 + # brace-style: [ 2, '1tbs', { allowSingleLine: true } ] + # comma-spacing: 2 + comma-style: 2 + consistent-this: [ 2, self ] + consistent-return: 2 + curly: 2 + # default-case: 2 + dot-notation: 2 + eol-last: 2 + eqeqeq: 2 + # guard-for-in: 2 + handle-callback-err: 2 + # max-depth: [ 1, 6 ] + max-nested-callbacks: [ 1, 4 ] + # string can exceed 80 chars, but should not overflow github website :) + # max-len: [ 2, 120, 1000 ] + # new-cap: 2 + new-parens: 2 + no-alert: 2 + no-array-constructor: 2 + # no-bitwise: 2 + no-caller: 2 + no-catch-shadow: 2 + no-comma-dangle: 2 + no-cond-assign: 2 + # no-console: 1 + no-constant-condition: 2 + no-control-regex: 2 + no-debugger: 2 + no-delete-var: 2 + no-dupe-keys: 2 + no-div-regex: 2 + # no-empty: 2 + no-empty-class: 2 + no-empty-label: 2 + no-else-return: 2 + no-eq-null: 2 + no-ex-assign: 2 + no-extend-native: 2 + no-extra-bind: 2 + no-extra-boolean-cast: 2 + no-extra-semi: 2 + no-extra-strict: 2 + no-eval: 2 + no-floating-decimal: 2 + no-func-assign: 2 + no-implied-eval: 2 + no-inner-declarations: 2 + no-invalid-regexp: 2 + no-irregular-whitespace: 2 + no-label-var: 2 + # no-labels: 2 + no-lone-blocks: 2 + no-lonely-if: 2 + no-loop-func: 2 + no-mixed-requires: 2 + no-mixed-spaces-and-tabs: 2 + no-multi-str: 2 + no-native-reassign: 2 + no-negated-in-lhs: 2 + no-new: 2 + no-new-func: 2 + no-new-object: 2 + no-new-require: 2 + no-new-wrappers: 2 + no-obj-calls: 2 + no-octal: 2 + no-octal-escape: 2 + no-path-concat: 2 + no-redeclare: 2 + no-regex-spaces: 2 + no-reserved-keys: 2 + no-return-assign: 2 + no-script-url: 2 + no-sequences: 2 + no-shadow: 2 + no-shadow-restricted-names: 2 + # no-space-before-semi: 2 + no-sparse-arrays: 2 + no-trailing-spaces: 2 + no-undef: 2 + no-undef-init: 2 + no-undefined: 2 + no-unreachable: 2 + no-unused-expressions: 2 + no-unused-vars: 2 + no-use-before-define: 2 + no-with: 2 + no-wrap-func: 2 + quotes: [ 2, single, avoid-escape ] + radix: 2 + semi: 2 + space-after-keywords: [ 2, always, , { "checkFunctionKeyword": true } ] + space-before-blocks: 2 + # space-in-brackets: [ 2, always, { propertyName: false } ] + space-in-parens: [ 2, never ] + # space-infix-ops: 2 + space-return-throw-case: 2 + space-unary-ops: 2 + # spaced-line-comment: [ 2, always, { exceptions: [ '/' ] } ] + strict: 2 + use-isnan: 2 + yoda: 2 + valid-typeof: 2 + + # + # Our custom rules + # + nodeca/indent: [ 2, spaces, 2 ] diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index 5073f1d..0000000 --- a/.jshintignore +++ /dev/null @@ -1,6 +0,0 @@ -.git/ -node_modules/ -benchmark/implementations -coverage/ -dist/ -test/browser/pako.js diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 367f4f5..0000000 --- a/.jshintrc +++ /dev/null @@ -1,78 +0,0 @@ -{ - // Enforcing Options ///////////////////////////////////////////////////////// - - "bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.). - "camelcase" : false, // true: Identifiers must be in camelCase - "curly" : true, // Require {} for every new block or scope. - "eqeqeq" : true, // Require triple equals i.e. `===`. - "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. - "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` - "indent" : 2, // Specify indentation spacing - "latedef" : true, // Prohibit hariable use before definition. - "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. - "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. - "noempty" : true, // Prohibit use of empty blocks. - "nonew" : true, // Prohibit use of constructors for side-effects. - "plusplus" : false, // Prohibit use of `++` & `--`. - "quotmark" : "single", // Quotation mark consistency: - // false : do nothing (default) - // true : ensure whatever is used is consistent - // "single" : require single quotes - // "double" : require double quotes - "undef" : true, // Require all non-global variables be declared before they are used. - "unused" : true, // Warns when you define and never use your variables - "strict" : true, // Require `use strict` pragma in every file. - "trailing" : true, // Prohibit trailing whitespaces. - - // Relaxing Options ////////////////////////////////////////////////////////// - - "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). - "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. - "debug" : false, // Allow debugger statements e.g. browser breakpoints. - "eqnull" : false, // Tolerate use of `== null`. - //"es5" : true, // Allow ECMAScript 5 syntax. - "esnext" : false, // Allow ES.next specific features such as const and let - "evil" : false, // Tolerate use of `eval`. - "expr" : false, // Tolerate `ExpressionStatement` as Programs. - "funcscope" : false, // Tolerate declaring variables inside of control structures while accessing them later - "globalstrict" : true, // Allow global "use strict" (also enables 'strict'). - "iterator" : false, // Allow usage of __iterator__ property. - "lastsemic" : false, // Tolerate semicolon omited for the last statement. - "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. - "laxcomma" : true, // This option suppresses warnings about comma-first coding style - "loopfunc" : false, // Allow functions to be defined within loops. - "multistr" : false, // Tolerate multi-line strings. - "proto" : false, // Allow usage of __proto__ property. - "scripturl" : false, // Tolerate script-targeted URLs. - "smarttabs" : false, // Allow mixed tabs and spaces when the latter are used for alignmnent only. - "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. - "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. - "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`. - "validthis" : false, // true: Tolerate using this in a non-constructor function - - // Environments ////////////////////////////////////////////////////////////// - - "browser" : false, // Defines globals exposed by modern browsers - "couch" : false, // Defines globals exposed by CouchDB - "devel" : false, // Allow developments statements e.g. `console.log();`. - "dojo" : false, // Defines globals exposed by the Dojo Toolkit - "jquery" : false, // Defines globals exposed by the jQuery - "mootools" : false, // Defines globals exposed by the MooTools - "node" : true, // Defines globals exposed when running under Node.JS - "nonstandard" : false, // Defines non-standard but widely adopted globals such as escape and unescape - "prototypejs" : false, // Defines globals exposed by the Prototype - "rhino" : false, // Defines globals exposed when running under Rhino - "wsh" : false, // Defines globals exposed when running under WSH - "yui" : false, // Yahoo User Interface - - // Legacy //////////////////////////////////////////////////////////////////// - - "nomen" : false, // Prohibit use of initial or trailing underbars in names. - "onevar" : false, // Allow only one `var` statement per function. - "passfail" : false, // Stop on first error. - "white" : false, // Check against strict whitespace and indentation rules. - - // Custom globals /////////////////////////////////////////////////////////// - - "globals" : { } -} diff --git a/.travis.yml b/.travis.yml index 7e5df6e..edd6497 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: node_js node_js: - "0.10" -before_script: "npm install" script: make $COMMAND env: matrix: diff --git a/Makefile b/Makefile index 0914ae8..4c8f4b8 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ help: lint: - jshint . --show-non-errors + eslint --reset . test: lint diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 92c945d..d04ea3e 100755 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -20,8 +20,8 @@ var IMPLS = []; fs.readdirSync(IMPLS_DIRECTORY).sort().forEach(function (name) { - var file = path.join(IMPLS_DIRECTORY, name), - code = require(file); + var file = path.join(IMPLS_DIRECTORY, name); + var code = require(file); IMPLS_PATHS[name] = file; IMPLS.push({ @@ -85,7 +85,7 @@ fs.readdirSync(SAMPLES_DIRECTORY).sort().forEach(function (sample) { defer: !!impl.code.async, fn: function (deferred) { - if (!!impl.code.async) { + if (impl.code.async) { impl.code.run(content, LEVEL, function() { deferred.resolve(); return; diff --git a/benchmark/profile.js b/benchmark/profile.js index 190317b..de6f7ea 100644 --- a/benchmark/profile.js +++ b/benchmark/profile.js @@ -1,9 +1,10 @@ 'use strict'; var fs = require('fs'); +var path = require('path'); var pako = require('../index.js'); -var data = new Uint8Array(fs.readFileSync(__dirname +'/samples/lorem_1mb.txt')); +var data = new Uint8Array(fs.readFileSync(path.join(__dirname, '/samples/lorem_1mb.txt'))); var deflated = pako.deflate(data, { level: 6/*, to: 'string'*/ }); diff --git a/index.js b/index.js index 46cf736..cd07251 100644 --- a/index.js +++ b/index.js @@ -11,4 +11,4 @@ var pako = {}; assign(pako, deflate, inflate, constants); -module.exports = pako; \ No newline at end of file +module.exports = pako; diff --git a/lib/deflate.js b/lib/deflate.js index bec7c57..9cd0392 100644 --- a/lib/deflate.js +++ b/lib/deflate.js @@ -361,4 +361,4 @@ function gzip(input, options) { exports.Deflate = Deflate; exports.deflate = deflate; exports.deflateRaw = deflateRaw; -exports.gzip = gzip; \ No newline at end of file +exports.gzip = gzip; diff --git a/lib/utils/common.js b/lib/utils/common.js index 6a41f20..67aaba1 100644 --- a/lib/utils/common.js +++ b/lib/utils/common.js @@ -12,7 +12,7 @@ exports.assign = function (obj /*from1, from2, from3, ...*/) { var source = sources.shift(); if (!source) { continue; } - if (typeof(source) !== 'object') { + if (typeof source !== 'object') { throw new TypeError(source + 'must be non-object'); } @@ -43,7 +43,7 @@ var fnTyped = { return; } // Fallback to ordinary array - for(var i=0; i= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1); +for (var q=0; q<256; q++) { + _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1); } _utf8len[254]=_utf8len[254]=1; // Invalid sequence start @@ -91,7 +91,7 @@ function buf2binstring(buf, len) { } var result = ''; - for(var i=0; i < len; i++) { + for (var i=0; i < len; i++) { result += String.fromCharCode(buf[i]); } return result; @@ -107,7 +107,7 @@ exports.buf2binstring = function(buf) { // Convert binary string (typed, when possible) exports.binstring2buf = function(str) { var buf = new utils.Buf8(str.length); - for(var i=0, len=buf.length; i < len; i++) { + for (var i=0, len=buf.length; i < len; i++) { buf[i] = str.charCodeAt(i); } return buf; diff --git a/lib/zlib/adler32.js b/lib/zlib/adler32.js index cb93380..dcefe93 100644 --- a/lib/zlib/adler32.js +++ b/lib/zlib/adler32.js @@ -5,9 +5,9 @@ // Small size is preferable. function adler32(adler, buf, len, pos) { - var s1 = (adler & 0xffff) |0 - , s2 = ((adler >>> 16) & 0xffff) |0 - , n = 0; + var s1 = (adler & 0xffff) |0, + s2 = ((adler >>> 16) & 0xffff) |0, + n = 0; while (len !== 0) { // Set limit ~ twice less than 5552, to keep @@ -29,4 +29,4 @@ function adler32(adler, buf, len, pos) { } -module.exports = adler32; \ No newline at end of file +module.exports = adler32; diff --git a/lib/zlib/constants.js b/lib/zlib/constants.js index 74bc8d8..f32af66 100644 --- a/lib/zlib/constants.js +++ b/lib/zlib/constants.js @@ -44,4 +44,4 @@ module.exports = { /* The deflate compression method */ Z_DEFLATED: 8 //Z_NULL: null // Use -1 or null inline, depending on var type -}; \ No newline at end of file +}; diff --git a/lib/zlib/crc32.js b/lib/zlib/crc32.js index bfce100..767aa80 100644 --- a/lib/zlib/crc32.js +++ b/lib/zlib/crc32.js @@ -9,9 +9,9 @@ function makeTable() { var c, table = []; - for(var n =0; n < 256; n++){ + for (var n =0; n < 256; n++) { c = n; - for(var k =0; k < 8; k++){ + for (var k =0; k < 8; k++) { c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); } table[n] = c; @@ -25,12 +25,12 @@ var crcTable = makeTable(); function crc32(crc, buf, len, pos) { - var t = crcTable - , end = pos + len; + var t = crcTable, + end = pos + len; crc = crc ^ (-1); - for (var i = pos; i < end; i++ ) { + for (var i = pos; i < end; i++) { crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF]; } @@ -38,4 +38,4 @@ function crc32(crc, buf, len, pos) { } -module.exports = crc32; \ No newline at end of file +module.exports = crc32; diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index b8c62f4..ff0bb06 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -1534,7 +1534,7 @@ function deflate(strm, flush) { put_byte(s, val); } while (val !== 0); - if (s.gzhead.hcrc && s.pending > beg){ + if (s.gzhead.hcrc && s.pending > beg) { strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); } if (val === 0) { @@ -1762,4 +1762,4 @@ exports.deflateParams = deflateParams; exports.deflatePending = deflatePending; exports.deflatePrime = deflatePrime; exports.deflateTune = deflateTune; -*/ \ No newline at end of file +*/ diff --git a/lib/zlib/gzheader.js b/lib/zlib/gzheader.js index 477a139..300bdee 100644 --- a/lib/zlib/gzheader.js +++ b/lib/zlib/gzheader.js @@ -17,7 +17,7 @@ function GZheader() { // but leave for few code modifications // - // Setup limits is not necessary because in js we should not preallocate memory + // Setup limits is not necessary because in js we should not preallocate memory // for inflate use constant limit in 65536 bytes // @@ -37,4 +37,4 @@ function GZheader() { this.done = false; } -module.exports = GZheader; \ No newline at end of file +module.exports = GZheader; diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js index e4bb3be..a92af63 100644 --- a/lib/zlib/inflate.js +++ b/lib/zlib/inflate.js @@ -1500,4 +1500,4 @@ exports.inflateSetDictionary = inflateSetDictionary; exports.inflateSync = inflateSync; exports.inflateSyncPoint = inflateSyncPoint; exports.inflateUndermine = inflateUndermine; -*/ \ No newline at end of file +*/ diff --git a/lib/zlib/inftrees.js b/lib/zlib/inftrees.js index 4d2b22d..1852df2 100644 --- a/lib/zlib/inftrees.js +++ b/lib/zlib/inftrees.js @@ -194,18 +194,20 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta // poor man optimization - use if-else instead of switch, // to avoid deopts in old v8 if (type === CODES) { - base = extra = work; /* dummy value--not used */ - end = 19; + base = extra = work; /* dummy value--not used */ + end = 19; + } else if (type === LENS) { - base = lbase; - base_index -= 257; - extra = lext; - extra_index -= 257; - end = 256; + base = lbase; + base_index -= 257; + extra = lext; + extra_index -= 257; + end = 256; + } else { /* DISTS */ - base = dbase; - extra = dext; - end = -1; + base = dbase; + extra = dext; + end = -1; } /* initialize opts for loop */ diff --git a/lib/zlib/messages.js b/lib/zlib/messages.js index 4c171da..75bd583 100644 --- a/lib/zlib/messages.js +++ b/lib/zlib/messages.js @@ -10,4 +10,4 @@ module.exports = { '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */ '-5': 'buffer error', /* Z_BUF_ERROR (-5) */ '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ -}; \ No newline at end of file +}; diff --git a/lib/zlib/trees.js b/lib/zlib/trees.js index e807c17..a2a5f66 100644 --- a/lib/zlib/trees.js +++ b/lib/zlib/trees.js @@ -431,7 +431,7 @@ function tr_static_init() { } //Assert (dist == 256, "tr_static_init: dist != 256"); dist >>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { + for (; code < D_CODES; code++) { base_dist[code] = dist << 7; for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { _dist_code[256 + dist++] = code; @@ -1196,4 +1196,4 @@ exports._tr_init = _tr_init; exports._tr_stored_block = _tr_stored_block; exports._tr_flush_block = _tr_flush_block; exports._tr_tally = _tr_tally; -exports._tr_align = _tr_align; \ No newline at end of file +exports._tr_align = _tr_align; diff --git a/lib/zlib/zstream.js b/lib/zlib/zstream.js index a7e1556..2d93a39 100644 --- a/lib/zlib/zstream.js +++ b/lib/zlib/zstream.js @@ -26,4 +26,4 @@ function ZStream() { this.adler = 0; } -module.exports = ZStream; \ No newline at end of file +module.exports = ZStream; diff --git a/package.json b/package.json index c8110bb..e1be902 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,9 @@ "benchmark": "*", "ansi": "*", "browserify":"*", + "eslint": "0.17.1", + "eslint-plugin-nodeca": "~1.0.3", "uglify-js": "*", - "jshint": "*", "istanbul": "*", "ndoc": "*", "lodash": "*", diff --git a/test/deflate_cover.js b/test/deflate_cover.js index 2dc51d3..e101868 100644 --- a/test/deflate_cover.js +++ b/test/deflate_cover.js @@ -93,4 +93,4 @@ describe('Deflate states', function() { ret = zlib_deflate.deflateEnd(strm); assert(ret === c.Z_STREAM_ERROR); }); -}); \ No newline at end of file +}); diff --git a/test/gzip_specials.js b/test/gzip_specials.js index b3b4c95..06d746f 100644 --- a/test/gzip_specials.js +++ b/test/gzip_specials.js @@ -82,4 +82,4 @@ describe('Gzip special cases', function() { assert(i === 2, 'invalid blobs count'); }); -}); \ No newline at end of file +}); diff --git a/test/helpers.js b/test/helpers.js index 7b7eb3e..fb1f31d 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -168,4 +168,4 @@ function testInflate(samples, inflateOptions, deflateOptions, callback) { exports.cmpBuf = cmpBuf; exports.testSamples = testSamples; exports.testInflate = testInflate; -exports.loadSamples = loadSamples; \ No newline at end of file +exports.loadSamples = loadSamples; diff --git a/test/inflate_cover_ported.js b/test/inflate_cover_ported.js index 711d3ea..0174920 100644 --- a/test/inflate_cover_ported.js +++ b/test/inflate_cover_ported.js @@ -18,7 +18,7 @@ var pako = require('../index'); function h2b(hex) { - return hex.split(' ').map(function(hex) { return parseInt(hex, 16); }); + return hex.split(' ').map(function(hx) { return parseInt(hx, 16); }); } @@ -243,4 +243,4 @@ describe('Inflate support', function() { it('bad window size', function() { testInflate('', -15, c.Z_OK); }); -}); \ No newline at end of file +}); diff --git a/test/strings.js b/test/strings.js index 39ed57f..2fa9fd2 100644 --- a/test/strings.js +++ b/test/strings.js @@ -18,13 +18,12 @@ function fixedFromCharCode(code) { if (code > 0xffff) { code -= 0x10000; - var surrogate1 = 0xd800 + (code >> 10) - , surrogate2 = 0xdc00 + (code & 0x3ff); + var surrogate1 = 0xd800 + (code >> 10), + surrogate2 = 0xdc00 + (code & 0x3ff); return String.fromCharCode(surrogate1, surrogate2); - } else { - return String.fromCharCode(code); } + return String.fromCharCode(code); } // Converts array of codes / chars / strings to utf16 string @@ -123,4 +122,4 @@ describe('Deflate/Inflate strings', function () { assert.equal(data, sampleString); }); -}); \ No newline at end of file +});