Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

APIB Serializer #53

Merged
merged 52 commits into from
Dec 19, 2018
Merged

APIB Serializer #53

merged 52 commits into from
Dec 19, 2018

Conversation

pksunkara
Copy link
Contributor

Fixes #33

danielgtaylor and others added 30 commits September 10, 2015 16:34
Fix handling of empty body with description
chore: Upgrade to peasant 1 and release 0.3.0
chore: Upgrade peasant to 1.1.0
kylef and others added 22 commits July 11, 2017 14:42
Add support for some of the data structures produced from the Swagger adapter
…4db3f9b6a21f5892cdfe8d74b9a2d'

git-subtree-dir: packages/fury-adapter-apib-serializer
git-subtree-mainline: 1f4e482
git-subtree-split: cc266e4
@pksunkara pksunkara force-pushed the pksunkara/apibserializer branch from a2a0d7c to b0022be Compare December 19, 2018 05:58
* Indent a piece of multiline text by a number of spaces.
* Setting `first` to `true` will also indent the first line.
*/
const indent = (input, spaces, options = { first: false }) => {
Copy link
Member

@kylef kylef Dec 19, 2018

Choose a reason for hiding this comment

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

@pksunkara why did you make these closures instead of functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we are exporting these in this module. I generally use the rule that if I am exporting functions in ES6, I make them closures

Copy link
Member

@kylef kylef Dec 19, 2018

Choose a reason for hiding this comment

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

This brings inconsistency, against both other packages we maintain and even other files in the same package (function getTypeAttributes(element, attributes, parent) { a few lines down). That said, I believe it should be a named function for numerous reasons, due to scoping, hoisting, and transferring of this. Our style guide is also clear on this, it should be a named function instead of a function declaration:

7.1:

  • 7.1 Use named function expressions instead of function declarations. eslint: func-style

    Why? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to explicitly name the expression, regardless of whether or not the name is inferred from the containing variable (which is often the case in modern browsers or when using compilers such as Babel). This eliminates any assumptions made about the Error’s call stack. (Discussion)

    // bad
    function foo() {
      // ...
    }
    
    // bad
    const foo = function () {
      // ...
    };
    
    // good
    // lexical name distinguished from the variable-referenced invocation(s)
    const short = function longUniqueMoreDescriptiveLexicalFoo() {
      // ...
    };

Arrow functions are function expressions instead of named functions. You cannot declare a named arrow function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been doing this for other packages in the monorepo. I will make a separate PR standardizing this once this is merged.

@kylef kylef merged commit 3010489 into master Dec 19, 2018
@kylef kylef deleted the pksunkara/apibserializer branch December 19, 2018 11:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants