Skip to content

Commit

Permalink
Merge pull request #816 from null-a/update-dev-deps
Browse files Browse the repository at this point in the history
Update dev dependencies & switch to eslint
  • Loading branch information
stuhlmueller committed Apr 14, 2017
2 parents f2c965a + 644cc58 commit 7a4f698
Show file tree
Hide file tree
Showing 28 changed files with 184 additions and 129 deletions.
50 changes: 50 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
'root': true,
'env': {
'browser': true,
'node': true
},
'extends': 'eslint:recommended',
'globals': {
Float64Array: true,
ad: true,
T: true
},
'rules': {
'indent': [
'error',
2,
{
SwitchCase: 1,
VariableDeclarator: 2,
ArrayExpression: 'first'
}
],
'linebreak-style': [
'error',
'unix'
],
'max-len': [
'error',
120
],
'no-console': 'off',
'no-constant-condition': [
'error',
{checkLoops: false}
],
'no-empty': [
'error',
{allowEmptyCatch: true}
],
'no-extra-bind': 'error',
'no-redeclare': 'off',
'no-unused-vars': 'off',
'no-warning-comments': 'error',
'quotes': [
'error',
'single',
{avoidEscape: true}
]
}
};
9 changes: 9 additions & 0 deletions .eslintrc.wppl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
'env': {
// required to parse e.g. object literal property short hand.
'es6': true
},
'rules': {
'no-undef': 'off'
}
};
6 changes: 0 additions & 6 deletions .gjslintrc

This file was deleted.

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js

node_js:
- "0.12"
- "4"
- "5"
- "6"
Expand Down
58 changes: 26 additions & 32 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,34 @@ function adSource(fn) {
return fn.slice(0, -3) + '.ad.js';
}

var jslintSettings = {
options: {
flags: ['--flagfile .gjslintrc'],
reporter: {
name: 'console'
},
force: false
},
lib: {
src: [
'Gruntfile.js',
'src/header.wppl',
'src/**/*.js'
],
filter: _.negate(isCodeGenFile)
},
test: {
src: ['tests/**/*.js']
},
wppl: {
src: [
'tests/test-data/**/*.wppl',
'examples/*.wppl'
]
}
};
module.exports = function(grunt) {
grunt.initConfig({
nodeunit: {
all: ['tests/test-*.js']
},
eslint: {
lib: {
src: [
'Gruntfile.js',
'src/**/*.js'
],
filter: _.negate(isCodeGenFile)
},
test: {
src: ['tests/**/*.js']
},
wppl: {
src: [
'src/header.wppl',
'examples/*.wppl',
'tests/test-data/**/*.wppl'
],
options: {
configFile: '.eslintrc.wppl.js'
}
},
options: {fix: "<%= grunt.option('fix') %>"}
},
jshint: {
all: {
src: [
Expand Down Expand Up @@ -80,8 +77,6 @@ module.exports = function(grunt) {
newcap: false
}
},
gjslint: jslintSettings,
fixjsstyle: jslintSettings,
clean: ['bundle/*.js'],
watch: {
ad: {
Expand All @@ -105,17 +100,16 @@ module.exports = function(grunt) {
return pkgArg + ' -t brfs src/browser.js -o bundle/webppl.js -x mongodb';
}

grunt.loadNpmTasks('grunt-gjslint');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['gjslint', 'nodeunit']);
grunt.registerTask('default', ['eslint', 'nodeunit']);
grunt.registerTask('test', ['nodeunit']);
grunt.registerTask('lint', ['gjslint']);
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('hint', ['jshint']);
grunt.registerTask('fixstyle', ['fixjsstyle']);
grunt.registerTask('travis-phantomjs', ['bundle', 'test-phantomjs']);

grunt.registerTask('build-ad', function() {
Expand Down
8 changes: 4 additions & 4 deletions docs/development/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ Linting

To only run the linter::

grunt gjslint
grunt lint

For more semantic linting, try::

grunt hint

If gjslint complains about style errors (like indentation), you can fix
many of them automatically using::
If the linter complains about style errors (like indentation), you can
fix many of them automatically using::

grunt fixjsstyle
grunt lint --fix --force

Browser version
---------------
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
"devDependencies": {
"aws-sdk": "^2.4.1",
"brfs": "^1.4.3",
"closure-linter-wrapper": "^1.0.1",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-gjslint": "^0.2.0",
"eslint": "^3.19.0",
"grunt": "^1.0.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^19.0.0",
"nodeunit": "^0.9.1",
"open": "0.0.5",
"qunit-phantomjs-runner": "^2.1.0",
"qunitjs": "^2.3.1",
"through2": "^2.0.0"
},
"scripts": {
Expand All @@ -59,7 +60,7 @@
"webppl": "./webppl"
},
"engines": {
"node": ">=0.12.4"
"node": ">=4"
},
"keywords": [
"probabilistic",
Expand Down
2 changes: 0 additions & 2 deletions scripts/cdnUpload
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ var fs = require('fs');
var AWS = require('aws-sdk');
var zlib = require('zlib');

// TODO: browserify

var version = require('../src/pkginfo').version(),
fileName = 'webppl-' + version + '.js';

Expand Down
1 change: 0 additions & 1 deletion src/ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var valueRec = function(x) {
var proto = Object.getPrototypeOf(x);
var y = _.mapValues(x, valueRec);
return _.assign(Object.create(proto), y);
return y;
} else {
return x;
}
Expand Down
22 changes: 12 additions & 10 deletions src/errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ function sourceMapJsStackTrace(stackTrace, sourceMap) {
column: entry.columnNumber
});

return positionPopulated(pos) ?
{
fileName: pos.source,
lineNumber: pos.line,
columnNumber: pos.column,
native: entry.native,
webppl: true,
name: filterGensym(pos.name)
} :
null;
if (positionPopulated(pos)) {
return {
fileName: pos.source,
lineNumber: pos.line,
columnNumber: pos.column,
native: entry.native,
webppl: true,
name: filterGensym(pos.name)
};
} else {
return null;
}
} else {
return entry;
}
Expand Down
10 changes: 8 additions & 2 deletions src/guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,19 @@ function paramSpec(type, targetParam) {
case 'array':
if (type.elementType.name === 'any' || type.elementType.name === 'int') {
return {const: targetParam};
} else {
throw paramSpecError(type);
}
default:
var msg = 'Can\'t generate specification for parameter of type "' + type.name + '".';
throw new Error(msg);
throw paramSpecError(type);
}
}

function paramSpecError(type) {
var msg = 'Can\'t generate specification for parameter of type "' + type.name + '".';
return new Error(msg);
}

function dirichletSpec(targetDist) {
var d = ad.value(targetDist.params.alpha).length - 1;
return {
Expand Down
4 changes: 3 additions & 1 deletion src/hashtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* limitations under the License.
*/

var util = require('./util');

var FUNCTION = 'function', STRING = 'string', UNDEFINED = undefined;

// // Require Array.prototype.splice, Object.prototype.hasOwnProperty and encodeURIComponent. In environments not
Expand Down Expand Up @@ -344,7 +346,7 @@ function Hashtable() {
biggestBucket = buckets[0];
var i = buckets.length;
while (i--) {
if (buckets[i].entries.length > biggestBucket.entries.length)
if (buckets[i].entries.length > biggestBucket.entries.length)
biggestBucket = buckets[i];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/inference/asyncpf.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function(env) {
this.oldCoroutine = env.coroutine;
env.coroutine = this;
this.oldStore = _.clone(s); // will be reinstated at the end
};
}

AsyncPF.prototype.run = function(numP) {
// allows for continuing pf
Expand Down
2 changes: 1 addition & 1 deletion src/inference/checkSampleAfterFactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function(env) {
function(i, next) {
return this.wpplFn(_.clone(this.s), function(s, val) {
return next();
}.bind(this), this.a);
}, this.a);
}.bind(this),

// Continuation.
Expand Down
2 changes: 1 addition & 1 deletion src/inference/elbo.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = function(env) {
}
throw new Error(msg);
}
};
}

ELBO.prototype = {

Expand Down
2 changes: 1 addition & 1 deletion src/inference/eubo.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ module.exports = function(env) {
});
return miniBatch;
}
};
}

return function() {
var coroutine = Object.create(EUBO.prototype);
Expand Down
2 changes: 1 addition & 1 deletion src/inference/hmckernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = function(env) {
}
});
return momentum;
};
}

HMCKernel.prototype.leapFrogStep = function(cont, trace) {
return this.positionStep(function(newTrace) {
Expand Down

0 comments on commit 7a4f698

Please sign in to comment.