Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Refactor #165

Merged
merged 4 commits into from May 14, 2017
Merged

Refactor #165

merged 4 commits into from May 14, 2017

Conversation

robwise
Copy link
Collaborator

@robwise robwise commented May 12, 2017

This is a substantial refactor of the codebase. We had started to amass too many files in the root of the src directory, and the helpers file had become very incohesive. Now, if a certain function is only used once and does not interface with atom or the atom TextEditor object, it stays near the function calling it either in the same file or as a sibling file. Each high-level operation or concern is given its own folder so that the root of src is much cleaner and easier to read.

Other changes of note:

  • moved away from the strict actual/expected syntax for tests as this was unusual for people trying to contribute to the project, and I'm not 100% sold on it personally anyway
  • refactored certain functions to take a more FP approach and avoid local state wherever possible
  • removed flow coverage of test files: flow seems to have terrible jest support, so we were having to put $FlowFixMe annotations everytime we used mockImplementation. That noise was probably hurting more than flow was helping.

@codecov-io
Copy link

codecov-io commented May 12, 2017

Codecov Report

Merging #165 into master will increase coverage by 2.2%.
The diff coverage is 95.86%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #165     +/-   ##
=========================================
+ Coverage   73.43%   75.64%   +2.2%     
=========================================
  Files          10       23     +13     
  Lines         256      312     +56     
  Branches        0       29     +29     
=========================================
+ Hits          188      236     +48     
+ Misses         68       65      -3     
- Partials        0       11     +11
Impacted Files Coverage Δ
src/statusTile/index.js 0% <0%> (ø)
src/main.js 0% <0%> (ø) ⬆️
src/formatOnSave/isFilePathEslintIgnored.js 100% <100%> (ø)
src/displayDebugInfo/index.js 100% <100%> (ø)
...xecutePrettier/executePrettierOnEmbeddedScripts.js 100% <100%> (ø)
src/executePrettier/index.js 100% <100%> (ø)
src/executePrettier/buildPrettierEslintOptions.js 100% <100%> (ø)
src/statusTile/createStatusTile.js 100% <100%> (ø)
src/helpers/index.js 100% <100%> (ø)
...rc/executePrettier/executePrettierOnBufferRange.js 100% <100%> (ø)
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7846ef1...e1a9b39. Read the comment docs.

@robwise
Copy link
Collaborator Author

robwise commented May 12, 2017

@darahak I have Q/A'd this locally, do you think you could check it out too? The changes are so deep that I'm just worried about it because it's like launching from scratch. I'm having some of my coworkers beta test it as well.

@darahak
Copy link
Collaborator

darahak commented May 13, 2017

@robwise Sure, I'll take a look!

@darahak darahak self-requested a review May 14, 2017 12:33
Copy link
Collaborator

@darahak darahak left a comment

Choose a reason for hiding this comment

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

I lack time and I don't have much experience with Jest or FP, so I couldn't go into depth.

I just commented what caught my attention. You will probably catch more with your colleagues beta testing 😄

decls/index.js Outdated
@@ -36,6 +36,8 @@ declare type Atom$Disposable = any;
declare type Atom$View = any;
declare type Atom$Workspace = any;
declare type Atom$Command = { name: string, displayName: string };
declare type Atom$Notifications$Options = { detail?: ?string | ?Error, dismissable?: ?boolean };
Copy link
Collaborator

@darahak darahak May 14, 2017

Choose a reason for hiding this comment

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

I'm wondering if we should stick with the official documentation for these type declarations?
That would mean detail is string only, and we have to explicitly "cast" errors to strings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getPrettierOptions() returns all prettier options 1`] = `undefined`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it supposed to still be here?
It tests against undefined and I don't see it being used in index.test.js.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

roger, I deleted these snapshots and re-wrote from scratch


const getDepPath = (dep: string) => path.join(__dirname, '..', '..', 'node_modules', dep);

const getDebugInfo = () => `
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably nitpicking: this adds newlines at the top and bottom of the message.
But no need to change if the notification looks okay.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. fixed using .trim()

// $$FlowFixMe
prettierPackagePath ? require(prettierPackagePath) : bundledPrettier; // eslint-disable-line

const getPrettierInstance: (editor: TextEditor) => typeof bundledPrettier = _.flow(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line is confusing to me because of (...) => typeof bundledPrettier = ....
Is it specific to Flow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes specific to flow, it's an inline typing of the getPrettierInstance const. Because calling _.flow() returns a function, I don't need to wrap it with another arrow function. However, lodash/fp doesn't have flow-typed support, so I am explicitly defining the API. This says getPrettierInstance is a function that takes a TextEditor as the only argument and returns something that has the same type as the bundledPrettier object.

@robwise
Copy link
Collaborator Author

robwise commented May 14, 2017

@darahak thanks bro! I fixed the stuff you pointed out. Beta testing went well, just one issue due to a typo so far (which I fixed). If you're curious about learning FP, I find it much easier to read if you do it right once you get used to it. Check out this free guide: https://drboolean.gitbooks.io/mostly-adequate-guide/

He uses ramda but _.flow is the same thing as ramda's composeRight.

As the codebase has scaled, the src folder has become increasingly large and unwieldly.
Additionally, helpers and options had become quite extensive and lacked cohesion. This commit
refactors the various concerns into a nested folder structure. Functions that are only needed to
assist a specific domain are contained within that domain's folder. Helpers that interact with atom
are now in an atomInterface folder so that there is a clear interface to atom and so that it is easy
to mock accessing atom during testing. The same goes for helpers that interface with the Atom$Editor
object. Helpers are just those low-level functions that need to be shared between different domains.
We also move away from the strict "actual"/"expected" syntax for tests, although this may still be
used if expectation objects are considerably complex.
@robwise robwise merged commit 93f3b78 into master May 14, 2017
@robwise robwise deleted the robwise/refactoring branch May 14, 2017 15:45
@darahak
Copy link
Collaborator

darahak commented May 14, 2017

@robwise Thanks for the suggestion! I actually used Ramda for one project, so it should be fine.
I agree that it's more readable once you know the concept and what each function does.

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.

None yet

3 participants