Skip to content

Commit

Permalink
Update eslint and Flow, SyntaxError -> TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jul 13, 2016
1 parent 2462e2d commit 0c1c95a
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 37 deletions.
17 changes: 0 additions & 17 deletions .eslintrc

This file was deleted.

240 changes: 240 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,240 @@
module.exports = {
"env": {
"node": true
},
"extends": "eslint:recommended",
"rules": {
"accessor-pairs": "error",
"array-bracket-spacing": [
"error",
"never"
],
"array-callback-return": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-scoped-var": "off",
"block-spacing": [
"error",
"always"
],
"brace-style": "off",
"callback-return": "error",
"camelcase": "error",
"comma-dangle": "error",
"comma-spacing": [
"error",
{
"after": true,
"before": false
}
],
"comma-style": [
"error",
"last"
],
"complexity": "error",
"computed-property-spacing": [
"error",
"never"
],
"consistent-return": "off",
"consistent-this": "error",
"curly": "off",
"default-case": "error",
"dot-location": [
"error",
"property"
],
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": "error",
"func-names": [
"error",
"never"
],
"func-style": [
"error",
"declaration"
],
"generator-star-spacing": "error",
"global-require": "error",
"guard-for-in": "off",
"handle-callback-err": "error",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": "error",
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "error",
"keyword-spacing": [
"error",
{
"after": true,
"before": true
}
],
"linebreak-style": [
"error",
"unix"
],
"lines-around-comment": "off",
"max-depth": "off",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "off",
"new-cap": "error",
"new-parens": "error",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "error",
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": "error",
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
"no-empty-function": "error",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": [
"error",
"functions"
],
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "off",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": "off",
"no-mixed-requires": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-negated-condition": "off",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "error",
"no-process-exit": "error",
"no-proto": "error",
"no-prototype-builtins": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "error",
"no-ternary": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "off",
"no-undef-init": "error",
"no-undefined": "off",
"no-underscore-dangle": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": "error",
"no-use-before-define": "off",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-var": "off",
"no-void": "error",
"no-warning-comments": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": "off",
"object-curly-spacing": [
"error",
"always"
],
"object-shorthand": "off",
"one-var": "off",
"one-var-declaration-per-line": "off",
"operator-assignment": [
"error",
"always"
],
"operator-linebreak": "error",
"padded-blocks": "off",
"prefer-arrow-callback": "off",
"prefer-const": "error",
"prefer-reflect": "off",
"prefer-rest-params": "off",
"prefer-spread": "off",
"prefer-template": "off",
"quote-props": "off",
"quotes": [
"error",
"single"
],
"radix": "error",
"require-jsdoc": "off",
"rest-spread-spacing": "error",
"semi": "off",
"semi-spacing": [
"error",
{
"after": true,
"before": false
}
],
"sort-imports": "error",
"sort-vars": "off",
"space-before-blocks": "error",
"space-before-function-paren": "off",
"space-in-parens": "off",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "off",
"strict": "error",
"template-curly-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"vars-on-top": "off",
"wrap-iife": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
}
};
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -76,4 +76,4 @@ ss.probit = require('./src/probit');
ss.mixin = require('./src/mixin');

// Root-finding methods
ss.bisect = require('./src/bisect');
ss.bisect = require('./src/bisect');
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -17,13 +17,13 @@
"are-we-flow-yet": "^1.0.0",
"browserify": "^13.0.0",
"bundle-collapser": "^1.0.0",
"eslint": "^2.4.0",
"eslint": "^3.0.1",
"exorcist": "^0.4.0",
"flow-bin": "^0.22.0",
"jsdoctest": "1.6.1",
"flow-bin": "^0.28.0",
"jsdoctest": "1.6.3",
"mocha": "2.5.3",
"random-js": "^1.0.4",
"tap": "^5.7.0",
"tap": "^6.1.1",
"uglify-js": "^2.6.2"
},
"scripts": {
Expand Down
13 changes: 9 additions & 4 deletions src/bisect.js
Expand Up @@ -19,10 +19,16 @@ var sign = require('./sign');
* @example
* bisect(Math.cos,0,4,100,0.003); // => 1.572265625
*/
function bisect(func/*: (x: any) => number */, start/*: number */, end/*: number */, maxIterations/*: number */, errorTolerance/*: number */)/*:number*/ {
function bisect(
func/*: (x: any) => number */,
start/*: number */,
end/*: number */,
maxIterations/*: number */,
errorTolerance/*: number */)/*:number*/ {

if (typeof func !== 'function') throw new TypeError('func must be a function');

for(var i = 0; i < maxIterations; i++) {
for (var i = 0; i < maxIterations; i++) {
var output = (start + end) / 2;

if (func(output) === 0 || Math.abs((end - start) / 2) < errorTolerance) {
Expand All @@ -31,7 +37,6 @@ function bisect(func/*: (x: any) => number */, start/*: number */, end/*: number

if (sign(func(output)) === sign(func(start))) {
start = output;

} else {
end = output;
}
Expand All @@ -40,4 +45,4 @@ function bisect(func/*: (x: any) => number */, start/*: number */, end/*: number
throw new Error('maximum number of iterations exceeded');
}

module.exports = bisect;
module.exports = bisect;
4 changes: 2 additions & 2 deletions src/sign.js
Expand Up @@ -7,6 +7,7 @@
*
* @param {Number} x input value
* @returns {Number} sign value either 1, 0 or -1
* @throws {TypeError} if the input argument x is not a number
*
* @example
* sign(2); // => 1
Expand All @@ -21,9 +22,8 @@ function sign(x/*: number */)/*: number */ {
return 1;
}
} else {
throw new SyntaxError('not a number');
throw new TypeError('not a number');
}

}

module.exports = sign;
4 changes: 2 additions & 2 deletions test/bisect.test.js
Expand Up @@ -6,8 +6,8 @@ var bisect = require('../src/bisect');

test('bisect', function(t) {
t.test('can find root of sin and cos', function(t) {
t.equal(Number(bisect(Math.sin,1,4,100,0.003).toFixed(4)), 3.1416);
t.equal(Number(bisect(Math.cos,0,4,100,0.003).toFixed(4)), 1.5723);
t.equal(Number(bisect(Math.sin, 1, 4, 100, 0.003).toFixed(4)), 3.1416);
t.equal(Number(bisect(Math.cos, 0, 4, 100, 0.003).toFixed(4)), 1.5723);
t.throws(function() {
bisect(0);
}, 'Throws with syntax error f must be a function');
Expand Down
4 changes: 2 additions & 2 deletions test/ckmeans.test.js
Expand Up @@ -21,8 +21,8 @@ test('C k-means', function(t) {
t.deepEqual(example, [[-1, -1, -1, -1], [2, 2, 2], [4, 5, 6]]);
t.deepEqual(cK([1, 2, 3], 3), [[1], [2], [3]]);

t.deepEqual(cK([0, 3, 4], 2), [[0], [3, 4]]),
t.deepEqual(cK([-3, 0, 4], 2), [[-3, 0], [4]]),
t.deepEqual(cK([0, 3, 4], 2), [[0], [3, 4]]);
t.deepEqual(cK([-3, 0, 4], 2), [[-3, 0], [4]]);

t.deepEqual(cK([1, 2, 2, 3], 3), [[1], [2, 2], [3]]);
t.deepEqual(cK([1, 2, 2, 3, 3], 3), [[1], [2, 2], [3, 3]]);
Expand Down
4 changes: 2 additions & 2 deletions test/cumulative.js
Expand Up @@ -20,7 +20,7 @@ test('cumulativeStdNormalProbability', function(t) {
});
t.test('matches errorFunction', function(t) {
for (var i = 0; i < ss.standardNormalTable.length; i++) {
if (!(Math.abs(ss.cumulativeStdNormalProbability(i / 100) - (.5 + .5 * ss.errorFunction(i / 100 / Math.sqrt(2)))) < ss.epsilon)) {
if (!(Math.abs(ss.cumulativeStdNormalProbability(i / 100) - (0.5 + 0.5 * ss.errorFunction(i / 100 / Math.sqrt(2)))) < ss.epsilon)) {
t.fail('error-fn failure on ' + i);
}
}
Expand All @@ -31,7 +31,7 @@ test('cumulativeStdNormalProbability', function(t) {
t.end();
});
t.test('inverse', function(t) {
for (var i = 0; i <= 1 + ss.epsilon; i += .01) {
for (var i = 0; i <= 1 + ss.epsilon; i += 0.01) {
t.equal(Math.abs(ss.cumulativeStdNormalProbability(ss.probit(i)) - i) < 21 * ss.epsilon, true);
}
t.end();
Expand Down
2 changes: 1 addition & 1 deletion test/equal_interval_breaks.test.js
Expand Up @@ -6,7 +6,7 @@ var equalIntervalBreaks = require('../src/equal_interval_breaks');

test('equalIntervalBreaks', function(t) {
t.deepEqual(equalIntervalBreaks([1], 4), [1], '1-length case');
t.deepEqual(equalIntervalBreaks([1, 2, 3, 4, 5, 6], 4), [ 1, 2.25, 3.5, 4.75, 6 ], 'three breaks');
t.deepEqual(equalIntervalBreaks([1, 2, 3, 4, 5, 6], 4), [1, 2.25, 3.5, 4.75, 6], 'three breaks');
t.deepEqual(equalIntervalBreaks([1, 2, 3, 4, 5, 6], 2), [1, 3.5, 6], 'two breaks');
t.deepEqual(equalIntervalBreaks([1, 2, 3, 4, 5, 6], 1), [1, 6], 'one break');
t.end();
Expand Down
2 changes: 1 addition & 1 deletion test/error_function.js
Expand Up @@ -11,7 +11,7 @@ test('errorFunction', function(t) {
});
t.end();
test('inverse', function(t) {
for (var i = -1; i <= 1; i += .01) {
for (var i = -1; i <= 1; i += 0.01) {
t.equal(Math.abs(ss.errorFunction(ss.inverseErrorFunction(i)) - i) < 4 * ss.epsilon, true);
}
t.end();
Expand Down

0 comments on commit 0c1c95a

Please sign in to comment.