Skip to content

Commit

Permalink
refactor(prettier): integrate prettier (#360)
Browse files Browse the repository at this point in the history
Closes #336
  • Loading branch information
Undistraction authored and char0n committed Feb 18, 2018
1 parent 3eeec54 commit a3109fc
Show file tree
Hide file tree
Showing 189 changed files with 1,334 additions and 1,142 deletions.
20 changes: 8 additions & 12 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@
}
},
"extends": [
"airbnb-base",
"plugin:ramda/recommended"
"eslint-config-airbnb-base",
"plugin:ramda/recommended",
"prettier"
],
"plugins": ["eslint-plugin-ramda"],
"plugins": ["eslint-plugin-ramda", "prettier"],
"rules": {
"strict": [2, "global"],
"semi": ["error", "always", { "omitLastInOneLineBlock": true}],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "never"
}],
"space-before-function-paren": "off",
"comma-dangle": ["error", "always-multiline"],
"no-underscore-dangle": 0,
"object-curly-newline": 0,
"import/newline-after-import": ["error", { "count": 2 }],
"no-confusing-arrow": "off",
"object-curly-newline": "off",
"ramda/always-simplification": ["error"],
"ramda/compose-simplification": ["error"],
"ramda/eq-by-simplification": ["error"],
Expand Down
Empty file added .prettierignore
Empty file.
25 changes: 25 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
},
{
"files": ".babelrc",
"options": { "parser": "json" }
},
{
"files": ".eslintrc",
"options": { "parser": "json" }
},
{
"files": ".nycrc",
"options": { "parser": "json" }
}
]
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
},
"betterScripts": {
"docs": "jsdoc -c jsdoc.json && node ./scripts/jsdoc-inject-dist.js",
"lint": "eslint ./ && tslint -c tslint.json src/index.d.ts",
"lint:fix": "eslint ./ --fix && tslint --fix -c tslint.json src/index.d.ts",
"lint": "prettier test/**.js src/**.js --write && eslint ./ && tslint -c tslint.json src/index.d.ts",
"changelog": "conventional-changelog -p angular -i ./CHANGELOG.md -s",
"test": "cross-env BABEL_ENV=commonjs mocha",
"test:web": "testem ci",
Expand Down Expand Up @@ -113,9 +112,11 @@
"docdash": "git+https://github.com/char0n/docdash.git#bf4b4eebfdaf042c0ea9038419bc26813f243c94",
"es6-promise": "4.2.4",
"eslint": "4.17.0",
"eslint-config-airbnb-base": "12.1.0",
"eslint-config-airbnb-base": "=12.1.0",
"eslint-config-prettier": "=2.9.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-mocha": "=4.11.0",
"eslint-plugin-prettier": "=2.6.0",
"eslint-plugin-ramda": "=2.4.0",
"fantasy-land": "3.5.0",
"glob": "=7.1.2",
Expand All @@ -130,11 +131,13 @@
"nsp": "3.1.0",
"nyc": "11.4.1",
"phantomjs": "=2.1.7",
"prettier": "=1.10.2",
"ramda": "=0.25.0",
"rimraf": "=2.6.2",
"sinon": "4.3.0",
"testem": "2.0.0",
"tslint": "=5.9.1",
"tslint-config-prettier": "=1.7.0",
"typescript": "2.6.2",
"typescript-definition-tester": "=0.0.5",
"webpack": "3.11.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Y.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
* factorial(5); //=> 120
*/

const Y = le => (f => f(f))(g => le(x => (g(g))(x)));
const Y = le => (f => f(f))(g => le(x => g(g)(x)));

export default Y;
1 change: 0 additions & 1 deletion src/allP.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { bind } from 'ramda';


/* eslint-disable max-len */
/**
* Composable shortcut for `Promise.all`.
Expand Down
1 change: 0 additions & 1 deletion src/appendFlipped.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { append, flip } from 'ramda';


/**
* Returns a new list containing the contents of the given list, followed by the given element.
* Like {@link http://ramdajs.com/docs/#append|R.append} but with argument order reversed.
Expand Down
1 change: 0 additions & 1 deletion src/cata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { curry } from 'ramda';

import isFunction from './isFunction';


/* eslint-disable max-len */
/**
* The catamorphism is a way of folding a type into a value.
Expand Down
1 change: 0 additions & 1 deletion src/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { reject } from 'ramda';

import isFalsy from './isFalsy';


/**
* Creates an array with all falsy values removed.
* The values false, null, 0, "", undefined, and NaN are falsy.
Expand Down
3 changes: 0 additions & 3 deletions src/curryRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { converge, length, identity } from 'ramda';

import curryRightN from './curryRightN';


/**
* Returns a curried equivalent of the provided function.
* This function is like curry, except that the provided arguments order is reversed.
Expand All @@ -24,6 +23,4 @@ import curryRightN from './curryRightN';
*/
const curryRight = converge(curryRightN, [length, identity]);


export default curryRight;

15 changes: 4 additions & 11 deletions src/curryRightN.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { curryN, reverse } from 'ramda';


/**
* Returns a curried equivalent of the provided function, with the specified arity.
* This function is like curryN, except that the provided arguments order is reversed.
Expand All @@ -21,16 +20,10 @@ import { curryN, reverse } from 'ramda';
*
* concatStringCurried('a')('b')('c'); // => 'cba'
*/
const curryRightN = curryN(
2,
(arity, fn) =>
curryN(
arity,
function wrapper(...args) {
return fn.apply(this, reverse(args));
}
)
const curryRightN = curryN(2, (arity, fn) =>
curryN(arity, function wrapper(...args) {
return fn.apply(this, reverse(args));
})
);


export default curryRightN;
5 changes: 3 additions & 2 deletions src/defaultWhen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { curry } from 'ramda';


/**
* Returns the second argument if predicate function returns `true`,
* otherwise the third argument is returned.
Expand All @@ -20,6 +19,8 @@ import { curry } from 'ramda';
* RA.defaultWhen(RA.isNull, 1, null); // => 1
* RA.defaultWhen(RA.isNull, 1, 2); // => 2
*/
const defaultWhen = curry((predicate, defaultVal, val) => (predicate(val) ? defaultVal : val));
const defaultWhen = curry(
(predicate, defaultVal, val) => (predicate(val) ? defaultVal : val)
);

export default defaultWhen;
11 changes: 8 additions & 3 deletions src/fantasy-land/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { empty as emptyR } from 'ramda';

import { aliases } from './util';
import fl from './mapping';
import { applyTrait, functorTrait, setoidTrait, semigroupTrait, chainTrait, ordTrait } from './traits';

import {
applyTrait,
functorTrait,
setoidTrait,
semigroupTrait,
chainTrait,
ordTrait,
} from './traits';

// we do this here for jsdocs generate properly
const { of, ap, map, equals, concat, chain, lte, empty, contramap } = fl;


/**
* The simplest {@link https://github.com/fantasyland/fantasy-land|fantasy-land}
* compatible monad which attaches no information to values.
Expand Down
5 changes: 3 additions & 2 deletions src/fantasy-land/traits.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isString, isNumber, isFunction } from '../index';
import { isSameType } from './util';
import fl from './mapping';


export const functorTrait = {
[fl.map](fn) {
return this.constructor[fl.of](fn(this.value));
Expand Down Expand Up @@ -49,6 +48,8 @@ export const chainTrait = {

export const ordTrait = {
[fl.lte](ord) {
return isSameType(this, ord) && (this.value < ord.value || this[fl.equals](ord));
return (
isSameType(this, ord) && (this.value < ord.value || this[fl.equals](ord))
);
},
};
20 changes: 16 additions & 4 deletions src/fantasy-land/util.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import {
useWith, curry, curryN, toPairs, equals, over, lensIndex, replace, pipe, map, path,
either, complement,
useWith,
curry,
curryN,
toPairs,
equals,
over,
lensIndex,
replace,
pipe,
map,
path,
either,
complement,
} from 'ramda';


// type :: Monad a => a -> String
export const type = either(path(['@@type']), path(['constructor', '@@type']));

// typeEquals :: Monad a => String -> a -> Boolean
export const typeEquals = curry((typeIdent, monad) => type(monad) === typeIdent);
export const typeEquals = curry(
(typeIdent, monad) => type(monad) === typeIdent
);

// isSameType :: (Monad a, Monad b) => a -> b -> Boolean
export const isSameType = curryN(2, useWith(equals, [type, type]));
Expand Down
1 change: 0 additions & 1 deletion src/hasPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ const hasPath = curryN(2, (objPath, obj) => {
return hasPath(tail(objPath), path([prop], obj)); // base case
});


export default hasPath;
17 changes: 11 additions & 6 deletions src/internal/ap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import { ap as apR, curryN, pathSatisfies, both, anyPass } from 'ramda';
import isFunction from '../isFunction';
import fl from '../fantasy-land/mapping';


const isFunctor = anyPass([pathSatisfies(isFunction, ['map']), pathSatisfies(isFunction, [fl.map])]);
const isFunctor = anyPass([
pathSatisfies(isFunction, ['map']),
pathSatisfies(isFunction, [fl.map]),
]);
const isApply = both(
isFunctor,
anyPass([pathSatisfies(isFunction, ['ap']), pathSatisfies(isFunction, [fl.ap])])
anyPass([
pathSatisfies(isFunction, ['ap']),
pathSatisfies(isFunction, [fl.ap]),
])
);


const ap = curryN(2, (applyF, applyX) => {
// return original ramda `ap` if not Apply spec
if (!isApply(applyF) || !isApply(applyX)) { return apR(applyF, applyX) }
if (!isApply(applyF) || !isApply(applyX)) {
return apR(applyF, applyX);
}

try {
// new version of `ap` starting from ramda version > 0.23.0
Expand All @@ -24,5 +30,4 @@ const ap = curryN(2, (applyF, applyX) => {
}
});


export default ap;
1 change: 0 additions & 1 deletion src/isArray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _isArray from 'ramda/src/internal/_isArray';


/**
* Checks if input value is `Array`.
*
Expand Down
27 changes: 19 additions & 8 deletions src/isArrayLike.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { has } from 'ramda';
import isArray from './isArray';
import isString from './isString';


/* eslint-disable max-len */
/**
* Tests whether or not an object is similar to an array.
Expand All @@ -28,13 +27,25 @@ import isString from './isString';
* RA.isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
*/
/* eslint-enable max-len */
const isArrayLike = (val) => {
if (isArray(val)) { return true }
if (!val) { return false }
if (isString(val)) { return false }
if (typeof val !== 'object') { return false }
if (val.nodeType === 1) { return !!val.length }
if (val.length === 0) { return true }
const isArrayLike = val => {
if (isArray(val)) {
return true;
}
if (!val) {
return false;
}
if (isString(val)) {
return false;
}
if (typeof val !== 'object') {
return false;
}
if (val.nodeType === 1) {
return !!val.length;
}
if (val.length === 0) {
return true;
}
if (val.length > 0) {
return has(0, val) && has(val.length - 1, val);
}
Expand Down
3 changes: 2 additions & 1 deletion src/isAsyncFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* RA.isAsyncFunction(() => {}); //=> false
*/
/* eslint-enable max-len */
const isAsyncFunction = val => Object.prototype.toString.call(val) === '[object AsyncFunction]';
const isAsyncFunction = val =>
Object.prototype.toString.call(val) === '[object AsyncFunction]';

export default isAsyncFunction;
1 change: 0 additions & 1 deletion src/isEmptyArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { both, isEmpty } from 'ramda';

import isArray from './isArray';


/**
* Checks if input value is an empty `Array`.
*
Expand Down
1 change: 0 additions & 1 deletion src/isEmptyString.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { equals } from 'ramda';


/**
* Checks if input value is an empty `String`.
*
Expand Down
1 change: 0 additions & 1 deletion src/isEven.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { both, complement } from 'ramda';
import isInteger from './isInteger';
import isOdd from './isOdd';


/**
* Checks if value is even integer number.
* An even number is an integer which is "evenly divisible" by two.
Expand Down
1 change: 0 additions & 1 deletion src/isFalsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { complement } from 'ramda';

import isTruthy from './isTruthy';


/**
* A falsy value is a value that translates to false when evaluated in a Boolean context.
* Falsy values are `false`, `0`, `""`, `null`, `undefined`, and `NaN`.
Expand Down
Loading

0 comments on commit a3109fc

Please sign in to comment.