Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Babel, Webpack, React, Eslint, etc to latest & Clean up linting errors #719

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update eslint to use two spaces
i-r-n00b committed Nov 9, 2017
commit 35c439a93411a3ab1b766b50307904907b99dd37
3 changes: 0 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -6,9 +6,6 @@
"es6": true
},
"rules": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, can we revert this file to include only the single rule. We can perhaps add individual overrides per line.

no-param-reassign can be easily fixed by renaming all the reducers from obj to acc (acc is whitelisted as an acceptable param that can be reassigned)

"indent": [1, 4, {
"SwitchCase": 1
}],
"comma-dangle": [2, "never"],
"arrow-body-style": [2, "always"],
"class-methods-use-this": 0,
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@
"clean": "rimraf lib",
"coverage": "npm run transpile-cover && babel-node node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u exports -R tap --require test/babel test",
"lint": "eslint src components",
"lint-fix": "eslint --fix src components",
"lint-fix": "eslint --fix src test scripts",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

"postversion": "git push && git push --tags",
"prepublish": "npm run lint && npm run build",
"pretest": "npm run clean && npm run transpile",
138 changes: 69 additions & 69 deletions scripts/this-dispatch-to-return.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
const isDispatch = (path) => {
return (
path.value.type === 'CallExpression' &&
return (
path.value.type === 'CallExpression' &&
path.value.callee.type === 'MemberExpression' &&
// path.value.callee.object.type === 'ThisExpression' &&
// commented out so we support var self = this; self.dispatch();
path.value.callee.property.type === 'Identifier' &&
path.value.callee.property.name === 'dispatch'
);
);
};

const isThisActions = (path) => {
return (
path.value.type === 'MemberExpression' &&
return (
path.value.type === 'MemberExpression' &&
path.value.object.type === 'MemberExpression' &&
path.value.object.property.type === 'Identifier' &&
path.value.object.property.name === 'actions'
);
);
};

const updateDispatchToReturn = (j) => {
return (p) => {
j(p).replaceWith(j.returnStatement(p.value.arguments[0] || null));
};
return (p) => {
j(p).replaceWith(j.returnStatement(p.value.arguments[0] || null));
};
};

const updateDispatchToCall = (j) => {
return (p) => {
j(p).replaceWith(j.callExpression(j.identifier('dispatch'), p.value.arguments));
};
return (p) => {
j(p).replaceWith(j.callExpression(j.identifier('dispatch'), p.value.arguments));
};
};

const updateToJustThis = (j) => {
return (p) => {
j(p).replaceWith(j.memberExpression(p.value.object.object, p.value.property));
};
return (p) => {
j(p).replaceWith(j.memberExpression(p.value.object.object, p.value.property));
};
};

const findDispatches = (j, p) => {
return j(p).find(j.CallExpression).filter(isDispatch);
return j(p).find(j.CallExpression).filter(isDispatch);
};

const findThisActionReferences = (j, p) => {
return j(p).find(j.MemberExpression).filter(isThisActions);
return j(p).find(j.MemberExpression).filter(isThisActions);
};

const replaceFunction = (j, p) => {
j(p).replaceWith(j.functionExpression(
null,
p.value.params,
j.blockStatement([
j.returnStatement(
j.functionExpression(
null,
[j.identifier('dispatch')],
j.blockStatement(p.value.body.body)
)
)
])
));
j(p).replaceWith(j.functionExpression(
null,
p.value.params,
j.blockStatement([
j.returnStatement(
j.functionExpression(
null,
[j.identifier('dispatch')],
j.blockStatement(p.value.body.body)
)
)
])
));
};

module.exports = (file, api) => {
const j = api.jscodeshift;
const root = j(file.source);
const j = api.jscodeshift;
const root = j(file.source);

root.find(j.FunctionExpression).forEach((p) => {
root.find(j.FunctionExpression).forEach((p) => {
// ignore constructors
if (p.parent.value.type === 'MethodDefinition' && p.parent.value.kind === 'constructor') {
return;
}
if (p.parent.value.type === 'MethodDefinition' && p.parent.value.kind === 'constructor') {
return;
}

// find all dispatches that are inside the function
const dispatches = findDispatches(j, p).size();
const withinParent = findDispatches(j, p).filter((x) => {
return x.parent.parent.parent.value === p.value;
}).size();
// find all dispatches that are inside the function
const dispatches = findDispatches(j, p).size();
const withinParent = findDispatches(j, p).filter((x) => {
return x.parent.parent.parent.value === p.value;
}).size();

if (withinParent === 0 && dispatches > 0) {
replaceFunction(j, p);
findDispatches(j, p).forEach(updateDispatchToCall(j));
} else if (dispatches === 0) {
const hasReturn = j(p).find(j.ReturnStatement).size() > 0;
if (hasReturn) {
console.warn('Could not transform function because it returned', 'at line', p.parent.value.loc.start.line);
} else {
console.warn('This function does not dispatch?', 'at line', p.parent.value.loc.start.line);
}
if (withinParent === 0 && dispatches > 0) {
replaceFunction(j, p);
findDispatches(j, p).forEach(updateDispatchToCall(j));
} else if (dispatches === 0) {
const hasReturn = j(p).find(j.ReturnStatement).size() > 0;
if (hasReturn) {
console.warn('Could not transform function because it returned', 'at line', p.parent.value.loc.start.line);
} else {
console.warn('This function does not dispatch?', 'at line', p.parent.value.loc.start.line);
}

// if there are multiple dispatches happening then we'll need to return a
// dispatch function and update this.dispatch to a dispatch call
} else if (dispatches > 1) {
replaceFunction(j, p);
findDispatches(j, p).forEach(updateDispatchToCall(j));
// if there's a single dispatch then it's ok to return to dispatch
} else if (p.value.body.body.length === 1) {
// if its the only statement within the function
findDispatches(j, p).forEach(updateDispatchToReturn(j));
} else {
// otherwise lets run the function
replaceFunction(j, p);
findDispatches(j, p).forEach(updateDispatchToCall(j));
}
// if there are multiple dispatches happening then we'll need to return a
// dispatch function and update this.dispatch to a dispatch call
} else if (dispatches > 1) {
replaceFunction(j, p);
findDispatches(j, p).forEach(updateDispatchToCall(j));
// if there's a single dispatch then it's ok to return to dispatch
} else if (p.value.body.body.length === 1) {
// if its the only statement within the function
findDispatches(j, p).forEach(updateDispatchToReturn(j));
} else {
// otherwise lets run the function
replaceFunction(j, p);
findDispatches(j, p).forEach(updateDispatchToCall(j));
}

// Also find any mentions to `this.actions`
findThisActionReferences(j, p).forEach(updateToJustThis(j));
});
// Also find any mentions to `this.actions`
findThisActionReferences(j, p).forEach(updateToJustThis(j));
});

return root.toSource({ quote: 'single' });
return root.toSource({ quote: 'single' });
};
80 changes: 40 additions & 40 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -3,46 +3,46 @@ import * as fn from '../functions';
import * as utils from '../utils/AltUtils';

export default function makeAction(alt, namespace, name, implementation, obj) {
const id = utils.uid(alt._actionsRegistry, `${namespace}.${name}`);
const id = utils.uid(alt._actionsRegistry, `${namespace}.${name}`);
alt._actionsRegistry[id] = 1; //eslint-disable-line

const data = { id, namespace, name };

const dispatch = (payload) => { return alt.dispatch(id, payload, data); };

// the action itself
const action = (...args) => {
const invocationResult = implementation.apply(obj, args);
let actionResult = invocationResult;

// async functions that return promises should not be dispatched
if (invocationResult !== undefined && !isPromise(invocationResult)) {
if (fn.isFunction(invocationResult)) {
// inner function result should be returned as an action result
actionResult = invocationResult(dispatch, alt);
} else {
dispatch(invocationResult);
}
}

if (invocationResult === undefined) {
utils.warn('An action was called but nothing was dispatched');
}

return actionResult;
};
action.defer = (...args) => { return setTimeout(() => { return action(...args); }); };
action.id = id;
action.data = data;

// ensure each reference is unique in the namespace
const container = alt.actions[namespace];
const namespaceId = utils.uid(container, name);
container[namespaceId] = action;

// generate a constant
const constant = utils.formatAsConstant(namespaceId);
container[constant] = id;

return action;
const data = { id, namespace, name };

const dispatch = (payload) => { return alt.dispatch(id, payload, data); };

// the action itself
const action = (...args) => {
const invocationResult = implementation.apply(obj, args);
let actionResult = invocationResult;

// async functions that return promises should not be dispatched
if (invocationResult !== undefined && !isPromise(invocationResult)) {
if (fn.isFunction(invocationResult)) {
// inner function result should be returned as an action result
actionResult = invocationResult(dispatch, alt);
} else {
dispatch(invocationResult);
}
}

if (invocationResult === undefined) {
utils.warn('An action was called but nothing was dispatched');
}

return actionResult;
};
action.defer = (...args) => { return setTimeout(() => { return action(...args); }); };
action.id = id;
action.data = data;

// ensure each reference is unique in the namespace
const container = alt.actions[namespace];
const namespaceId = utils.uid(container, name);
container[namespaceId] = action;

// generate a constant
const constant = utils.formatAsConstant(namespaceId);
container[constant] = id;

return action;
}
22 changes: 11 additions & 11 deletions src/functions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const isFunction = (x) => { return typeof x === 'function'; };

export function isMutableObject(target) {
const Ctor = target.constructor;
const Ctor = target.constructor;

return (
!!target
return (
!!target
&&
Object.prototype.toString.call(target) === '[object Object]'
&&
@@ -13,20 +13,20 @@ export function isMutableObject(target) {
!Object.isFrozen(target)
&&
(Ctor instanceof Ctor || target.type === 'AltStore')
);
);
}

export function eachObject(f, o) {
o.forEach((from) => {
Object.keys(Object(from)).forEach((key) => {
f(key, from[key]);
});
o.forEach((from) => {
Object.keys(Object(from)).forEach((key) => {
f(key, from[key]);
});
});
}

export function assign(target, ...source) {
eachObject((key, value) => {
eachObject((key, value) => {
target[key] = value; //eslint-disable-line
}, source);
return target;
}, source);
return target;
}
Loading