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

WIP: replace flow with typescript-jsdoc #4325

Closed
wants to merge 52 commits into from
Closed

WIP: replace flow with typescript-jsdoc #4325

wants to merge 52 commits into from

Conversation

vankop
Copy link
Member

@vankop vankop commented Oct 4, 2019

Which issue, if any, is this issue related to?

#4245

Help wanted 🤗

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2019

Coverage Status

Coverage remained the same at 96.541% when pulling a8dc55f on to-typescript into 859288d on master.

@hudochenkov
Copy link
Member

I see you removed flow directive from all files. You decided to remove all Flow code first, and add JSDoc whenever you can think of? Or Flow is still running?

Could you add TypeScript to npm scripts, please? Can it also be added to pretest npm script so we run TypeScript and Flow together?

@vankop
Copy link
Member Author

vankop commented Oct 4, 2019

Flow is running, but does not lint anything, I did it just for development purpose (don’t think about flow types). We can revert this commit and commit that removes flow-typed later

@hudochenkov
Copy link
Member

Looks like our actual JavaScript got broken in the last commit.

@vankop
Copy link
Member Author

vankop commented Oct 4, 2019

Looks like our actual JavaScript got broken in the last commit.

yes you are correct =) I will revert this for now

@vankop
Copy link
Member Author

vankop commented Oct 4, 2019

If someone wants to help I suggest to write what you are taking here.

I will fix lib/assignDisabledRanges.js
and take

lib/standalone.js
lib/writeOutputFile.js

I think files from this list are prioritize

@vankop
Copy link
Member Author

vankop commented Oct 5, 2019

I have created issue related to ~/lib/assignDisabledRanges #4328

@G-Rath
Copy link

G-Rath commented Oct 5, 2019

FYI I've created a PR for adding definitions for globjoin. They should be merged & published within the week :)

@vankop
Copy link
Member Author

vankop commented Oct 5, 2019

@G-Rath I know how it works =) I just did not realizes that so many packages support both ways. Thanks for deep explanation! (babel as well provides util for both exports _interopRequireDefault)

@vankop
Copy link
Member Author

vankop commented Oct 5, 2019

@G-Rath As I know there is no a lot of typescript in jsdoc examples + it poor documented (if compare with common Typescript), could you suggest any source of examples / rich information about typescript in jsdoc? as I know there are a lot of tests here - https://github.com/microsoft/TypeScript/tree/master/tests/cases/fourslash. However, it hard to find usage some use cases there (folder is pretty large)

@G-Rath
Copy link

G-Rath commented Oct 5, 2019

@vankop sadly not really; you've pretty much summed up the state of the situation.

The two places I'd recommend are looking at tsdoc - It's a project so underway it's not been announced, but I stumbled upon it myself a few months ago when looking for info like you. That can give you a good idea of at least how MS/TS would like JS/TSDocs to endup looking - if you just remember to ignore tags that are not official JSDoc ones, I'd expect their examples to already work in TS.

The other place of information is the handbook.

Finally, the eslint team are actually looking into this same thing, and so you might find interesting code in the PR.


I'm also happy to experiment and mess around with things, so you're welcome to chuck code snippets at me to play w/ if something isn't working as nicely as you'd like, or point me at a file you'd like double-checked or think could be improved :)

@vankop
Copy link
Member Author

vankop commented Oct 6, 2019

@hudochenkov looks like problem with CI still exists

@hudochenkov
Copy link
Member

In a totally new places. Might be that it happens with code changes made in this PR. Though locally nothing fails in this branch.

Copy link
Member

@hudochenkov hudochenkov left a comment

Choose a reason for hiding this comment

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

This PR would be close to impossible to review :(

I've done the following to check not type related changes:

  1. In a separate folder installed npm install @babel/core @babel/cli prettier.

  2. Add config for Prettier from repository and following config for Babel:

    {
    	"generatorOpts": {
    		"comments": false
    	}
    }

    It removes all comments and doesn't do any transpiling.

  3. Run Babel to remove comments and then Prettier. Run on parent commit files, and then on the latest commit files.

    npx babel ../stylelint/lib --out-dir before
    npx prettier "before/**/*.js" --write
    

Then compare two folders in Kaleidoscope.

There are quite few changes to JavaScript itself.

I've notices some changes and commented on them, but I don't think it makes much sense to do this comparison before this PR is ready and has not failing tests.

}

if (cli.flags.version || cli.flags.v) {
if (cli.flags.version) {
Copy link
Member

Choose a reason for hiding this comment

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

-h and -v removed. Please, add them back.

Copy link
Member Author

Choose a reason for hiding this comment

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

as I understand from meow this flags are aliases for help and version so it should work, or there is another behaviour?

let source;

if (postcssResult) {
if (postcssResult && postcssResult.root) {
Copy link
Member

Choose a reason for hiding this comment

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

Why add this check?

Copy link
Member Author

Choose a reason for hiding this comment

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

Root possible undefined


const cached /*: ?postcss$result*/ = stylelint._postcssResultCache.get(options.filePath);
const cached = options.filePath ? stylelint._postcssResultCache.get(options.filePath) : undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Why this ternary?

Copy link
Member Author

@vankop vankop Oct 7, 2019

Choose a reason for hiding this comment

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

You can’t pass undefined in Map get
method

@@ -58,7 +58,7 @@ module.exports = function(stylelint /*: stylelint$internalApi*/) /*: Promise<?Ob
stringify: postcss.stringify,
};
}
} else if (syntax) {
} else if (stylelint._options.syntax) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not use syntax as before?

Copy link
Member Author

Choose a reason for hiding this comment

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

here is a little bit tricky place stylelint._options.syntax is undefined | string so after assigning on line 41 syntax implicitly have type undefined | string, but after we assign to syntax object - {parse: any, stringify: any} as well.

@@ -122,13 +122,23 @@ module.exports = function(stylelint /*: stylelint$internalApi*/) /*: Promise<?Ob
return result;
})
.then((postcssResult) => {
stylelint._postcssResultCache.set(options.filePath, postcssResult);
if (options.filePath) {
Copy link
Member

Choose a reason for hiding this comment

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

Why additional check?

Copy link
Member Author

Choose a reason for hiding this comment

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

options.filePath possible undefined same with get method

@vankop
Copy link
Member Author

vankop commented Oct 7, 2019

This PR would be close to impossible to review :(

Obviously, it is a problematic to review, if you have an idea how to split this, I will be glad to discuss.

I don't think it makes much sense to do this comparison before this PR is ready

Sorry, I did not have time to fix last 20 warnings. All welcome to take a look on them =)

@G-Rath
Copy link

G-Rath commented Oct 7, 2019

if you have an idea how to split this, I will be glad to discuss.

I would recommend focusing on adding the types, rather than removing flow.

For example, there are a lot of files that have been changed b/c you're removed @flow from the top - but there's no reason to do that in this PR, since they're just comments.

Even if flow is generating errors, the whole point of the PR is to move away from flow, so the errors shouldn't matter.

You can also remove the typing files for flow in another PR, as while sure they're not needed anymore, they're also not doing anything and so don't need to be removed in this PR :)

@ntwb
Copy link
Member

ntwb commented Oct 7, 2019

Thanks @G-Rath, and thanks for all your work thus far @vankop, this is all so much out of my wheelhouse, and anything that will help make reviewing this PR easier I'm all for.

So, if we can get away without including the removal of Flow and @flow comments that would be great if possible please.

@vankop
Copy link
Member Author

vankop commented Oct 7, 2019

First I can suggest create separate PR with tsconfig and provided types. I think we can take types folder from this PR, then we can make PRs step by step with or without flow (on your demand).

I would recommend focusing on adding the types, rather than removing flow.

I did it for the reason as described above - just for development reasons. As I see now it is not necessary (however some times flow and ts types are misleading)

You can also remove the typing files for flow in another PR, as while sure they're not needed anymore, they're also not doing anything and so don't need to be removed in this PR :)

Yes you are right, we can revert this commit

Even if flow is generating errors, the whole point of the PR is to move away from flow, so the errors shouldn't matter.

I think the main idea to stay with flow while TS will not cover stylelint' "core"

@vankop
Copy link
Member Author

vankop commented Oct 7, 2019

@hudochenkov after restarting CI still fail for Node.js 12.x.x, maybe it is relates to my changes =)

@ntwb
Copy link
Member

ntwb commented Oct 7, 2019

after restarting CI still fail for Node.js 12.x.x, maybe it is relates to my changes =)

Was thinking this might be something I. could help with... But,I cannot get the logs of the failing jobs to display past line 29 😞

@hudochenkov
Copy link
Member

@ntwb it's a scrollable area. I always keep scrollbar enabled in OS settings :)

@vankop
Copy link
Member Author

vankop commented Oct 11, 2019

types is fine now, I think I will start to split this in several PRs

@G-Rath
Copy link

G-Rath commented Oct 13, 2019

@vankop btw the definitions for globjoin got published :)

I'll circle back during the week and look to create definitions for the other libraries when I have a chance.

Also, table has typings.

@vankop
Copy link
Member Author

vankop commented Oct 28, 2019

Thanks all for your reviews! All this work is done in separate issues 🎉

@vankop vankop closed this Oct 28, 2019
@vankop vankop deleted the to-typescript branch October 28, 2019 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants