4

Need to write a (custom) ESLint rule for this:

Good:

connect((state, props) => {
  return {
     organizations: Organization.getActive(state, props.user),
    ...
    <prop>: Model.scope(state, prop...),  

  };
})(MyComponent);

Bad: All the stuff in there

connect((state, props) => {
  return {
     organizations: state.organizations, //archived? suspended? or really all?
  };
})(MyComponent);

Bad: Filtering in place.

connect((state, props) => {
  return {
     organizations: filter(state.organizations, {
       status: Organization.ACTIVE
     }),
  };
})(MyComponent);

All that should be needed is to disallow state.<something> within the connect function as a starting point and make tweaks as needed.

ruffin
  • 16,507
  • 9
  • 88
  • 138
hakunin
  • 4,041
  • 6
  • 40
  • 57
  • what did you try and didn't work? can you show us some code and we can help you afterwards. – tudor.gergely Feb 22 '20 at 07:29
  • Haven't tried anything yet, hoping this is general / similar enough that someone already knows the right approach. – hakunin Feb 23 '20 at 06:11
  • 1
    How did you mean "Write a JSLint rule for this"? JSLint the tool is [maintained by Douglas Crockford](https://github.com/douglascrockford/JSLint). He writes all the rules. ;) Did you mean a [custom _eslint_ rule](https://eslint.org/docs/developer-guide/working-with-rules)? – ruffin Jul 15 '20 at 16:05
  • Yep I meant a custom one. – hakunin Jul 16 '20 at 05:59
  • I read your question several times, but I don't understand what you want. can you explain more? – AmerllicA Jul 16 '20 at 21:12
  • I want to avoid accessing the state directly via `state.organizations`, I, want people to use class methods instead: `Organization.getActive(state)`. – hakunin Jul 17 '20 at 06:07
  • I've never seen that before. I guess you wanna bring another programming language culture here. When whole the React community are going to FP and easy accessing data, by my thoughts, there is no need Class, OOP, .Net like data accessing. ok. good luck – AmerllicA Jul 17 '20 at 08:14
  • @hakunin Have you considered writing ESLint plugin for your custom rule the way it is outlined in [Writing custom ESLint rules](https://www.kenneth-truyers.net/2016/05/27/writing-custom-eslint-rules/)? – Dan Macak Jul 21 '20 at 19:19

0 Answers0