From 8ae9b5fa961217101c70a4d25fcdf6367022d754 Mon Sep 17 00:00:00 2001 From: Pedr Browne Date: Sun, 4 Feb 2018 20:03:35 +0000 Subject: [PATCH] style: add eslint-plugin-ramda (#335) Closes #306 --- .codeclimate.yml | 1 + .eslintrc | 10 ++++++++-- package.json | 1 + src/internal/polyfills/Number.MAX_SAFE_INTEGER.js | 5 +---- src/internal/polyfills/Number.MIN_SAFE_INTEGER.js | 5 +---- src/isArray.js | 3 +-- src/isFinite.js | 4 +--- src/isGeneratorFunction.js | 4 +--- src/isInteger.js | 4 +--- src/isNaN.js | 4 +--- test/liftFN.js | 4 ++-- test/neither.js | 4 ++-- test/notBoth.js | 4 ++-- 13 files changed, 23 insertions(+), 30 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index d3d54432e2..8230fba416 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -7,6 +7,7 @@ engines: - javascript eslint: enabled: true + channel: "eslint-4" checks: import/extensions: enabled: false diff --git a/.eslintrc b/.eslintrc index 48d65779f6..e15e0c4235 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,8 +10,10 @@ } }, "extends": [ - "airbnb-base" + "airbnb-base", + "plugin:ramda/recommended" ], + "plugins": ["eslint-plugin-ramda"], "rules": { "strict": [2, "global"], "semi": ["error", "always", { "omitLastInOneLineBlock": true}], @@ -24,6 +26,10 @@ }], "no-underscore-dangle": 0, "object-curly-newline": 0, - "import/newline-after-import": ["error", { "count": 2 }] + "import/newline-after-import": ["error", { "count": 2 }], + "ramda/always-simplification": ["error"], + "ramda/compose-simplification": ["error"], + "ramda/eq-by-simplification": ["error"], + "ramda/prefer-complement": ["error"] } } diff --git a/package.json b/package.json index a3482e0a43..60df5a50a2 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "eslint-config-airbnb-base": "12.1.0", "eslint-plugin-import": "2.8.0", "eslint-plugin-mocha": "=4.11.0", + "eslint-plugin-ramda": "=2.4.0", "fantasy-land": "3.5.0", "glob": "=7.1.2", "istanbul": "=0.4.5", diff --git a/src/internal/polyfills/Number.MAX_SAFE_INTEGER.js b/src/internal/polyfills/Number.MAX_SAFE_INTEGER.js index ec3897c89b..37854c5a7f 100644 --- a/src/internal/polyfills/Number.MAX_SAFE_INTEGER.js +++ b/src/internal/polyfills/Number.MAX_SAFE_INTEGER.js @@ -1,6 +1,3 @@ -import { or } from 'ramda'; - - -const MAX_SAFE_INTEGER = or(Number.MAX_SAFE_INTEGER, (2 ** 53) - 1); +const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || (2 ** 53) - 1; export default MAX_SAFE_INTEGER; diff --git a/src/internal/polyfills/Number.MIN_SAFE_INTEGER.js b/src/internal/polyfills/Number.MIN_SAFE_INTEGER.js index e077cb6928..4f6a4b98e5 100644 --- a/src/internal/polyfills/Number.MIN_SAFE_INTEGER.js +++ b/src/internal/polyfills/Number.MIN_SAFE_INTEGER.js @@ -1,6 +1,3 @@ -import { or } from 'ramda'; - - -const MIN_SAFE_INTEGER = or(Number.MIN_SAFE_INTEGER, -(2 ** 53) - 1); +const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -(2 ** 53) - 1; export default MIN_SAFE_INTEGER; diff --git a/src/isArray.js b/src/isArray.js index f21e228586..91f964e85a 100644 --- a/src/isArray.js +++ b/src/isArray.js @@ -1,5 +1,4 @@ import _isArray from 'ramda/src/internal/_isArray'; -import { or } from 'ramda'; /** @@ -19,6 +18,6 @@ import { or } from 'ramda'; * RA.isArray(null); //=> false * RA.isArray({}); //=> false */ -const isArray = or(Array.isArray, _isArray); +const isArray = Array.isArray || _isArray; export default isArray; diff --git a/src/isFinite.js b/src/isFinite.js index ddee236647..c36ad40707 100644 --- a/src/isFinite.js +++ b/src/isFinite.js @@ -1,5 +1,3 @@ -import { or } from 'ramda'; - import polyfill from './internal/polyfills/Number.isFinite'; /** @@ -27,6 +25,6 @@ import polyfill from './internal/polyfills/Number.isFinite'; * RA.isFinite(null); // => false * // would've been true with global isFinite(null) */ -const _isFinite = or(Number.isFinite, polyfill); +const _isFinite = Number.isFinite || polyfill; export default _isFinite; diff --git a/src/isGeneratorFunction.js b/src/isGeneratorFunction.js index b99ac63fb1..18ca10e957 100644 --- a/src/isGeneratorFunction.js +++ b/src/isGeneratorFunction.js @@ -1,5 +1,3 @@ -import { or } from 'ramda'; - import isNotNull from './isNotNull'; @@ -33,7 +31,7 @@ const isGeneratorFunction = (val) => { const toStringCheck = Object.prototype.toString.call(val) === '[object GeneratorFunction]'; const legacyConstructorCheck = isNotNull(GeneratorFunction) && val instanceof GeneratorFunction; - return or(toStringCheck, legacyConstructorCheck); + return toStringCheck || legacyConstructorCheck; }; export default isGeneratorFunction; diff --git a/src/isInteger.js b/src/isInteger.js index 1f96279c53..f36e0467b1 100644 --- a/src/isInteger.js +++ b/src/isInteger.js @@ -1,5 +1,3 @@ -import { or } from 'ramda'; - import polyfill from './internal/polyfills/Number.isInteger'; /** @@ -30,6 +28,6 @@ import polyfill from './internal/polyfills/Number.isInteger'; * RA.isInteger(false); //=> false * RA.isInteger([1]); //=> false */ -const isInteger = or(Number.isInteger, polyfill); +const isInteger = Number.isInteger || polyfill; export default isInteger; diff --git a/src/isNaN.js b/src/isNaN.js index c709f1f3ea..a088d90790 100644 --- a/src/isNaN.js +++ b/src/isNaN.js @@ -1,5 +1,3 @@ -import { or } from 'ramda'; - import polyfill from './internal/polyfills/Number.isNaN'; /** @@ -35,6 +33,6 @@ import polyfill from './internal/polyfills/Number.isNaN'; * RA.isNaN(''); // => false * RA.isNaN(' '); // => false */ -const _isNaN = or(Number.isNaN, polyfill); +const _isNaN = Number.isNaN || polyfill; export default _isNaN; diff --git a/test/liftFN.js b/test/liftFN.js index 709789a845..d0e5bc8605 100644 --- a/test/liftFN.js +++ b/test/liftFN.js @@ -1,13 +1,13 @@ +import * as R from 'ramda'; import chai from 'chai'; import { Maybe } from 'monet'; -import { add, reduce } from 'ramda'; import * as RA from '../src/index'; import eq from './shared/eq'; import Identity from '../src/fantasy-land/Identity'; -const addN = (...args) => reduce(add, 0, args); +const addN = (...args) => R.sum(args); const add3 = (a, b, c) => a + b + c; describe('liftFN', function () { diff --git a/test/neither.js b/test/neither.js index b48c28d5aa..27103c7728 100644 --- a/test/neither.js +++ b/test/neither.js @@ -1,3 +1,4 @@ +import * as R from 'ramda'; import { Just, Nothing } from 'monet'; import sinon from 'sinon'; @@ -40,10 +41,9 @@ describe('neither', function () { context('when the result of first function is true', function () { specify('should not evaluate the second expression', function () { - const f = () => true; const z = sinon.spy(); - RA.neither(f, z)(); + RA.neither(R.T, z)(); eq(z.notCalled, true); }); }); diff --git a/test/notBoth.js b/test/notBoth.js index 0ce0949009..9cd6afe8af 100644 --- a/test/notBoth.js +++ b/test/notBoth.js @@ -1,3 +1,4 @@ +import * as R from 'ramda'; import { Just, Nothing } from 'monet'; import sinon from 'sinon'; @@ -40,10 +41,9 @@ describe('notBoth', function () { context('when the first function returns false', function () { specify('should not evaluate the second function', function () { - const f = () => false; const z = sinon.spy(); - RA.notBoth(f, z)(); + RA.notBoth(R.F, z)(); eq(z.notCalled, true); }); });