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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript, Husky, Prettier and ESLint setup #2

Merged
merged 12 commits into from
Jul 9, 2019

Conversation

TejasQ
Copy link
Contributor

@TejasQ TejasQ commented Jul 8, 2019

This PR adds a nice set of dev tooling around the Entropic JS (now TS) CLI:

  • TypeScript for type-safety. I polyfilled "figgy-pudding" for now, until it's in definitely typed, or until add typescript definitions聽zkat/figgy-pudding#13 is merged.
  • ESLint for a little more safety on unused things and imports.
  • Prettier for formatting.
  • Husky and lint-staged for precommit checks.

I've broken this PR down into small cherry-pickable commits so we can pick and choose what we want. In case we just want TS without having all the JS files moved over, we can just remove commit eed9c9e and everything should be fine.

馃殌

@zkat
Copy link
Contributor

zkat commented Jul 8, 2019

Could you remove the yarn.lock and install the deps using VCPM? I'd like to keep using that one until we're ready to switch over to ds itself.

@TejasQ TejasQ force-pushed the typescript-prettier-setup branch from 43e2862 to d69af6e Compare July 8, 2019 18:57
@TejasQ
Copy link
Contributor Author

TejasQ commented Jul 8, 2019

Just noticed I had the lockfile in there! Sorry about that. What's VCPM and how do I use it? I was just going to npm i...

@zkat
Copy link
Contributor

zkat commented Jul 8, 2019

VCPM is how we refer to npm over here, sorry. I guess it's an inside joke I should avoid in technical convos 馃槄

@TejasQ
Copy link
Contributor Author

TejasQ commented Jul 8, 2019

Gotcha. Done! 馃帀

Copy link
Contributor

@zkat zkat left a comment

Choose a reason for hiding this comment

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

This is all an amazing amount of work, thank you! I'd like to get some eyeballs from someone with more experience using TypeScript, if possible, and I have a few questions/comments about the stuff that's already there, if that's ok.

馃憦 馃拑

"@typescript-eslint/parser": "^1.11.0",
"eslint": "^6.0.1",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-prettier": "^3.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need eslint if we're using prettier? I thought the point of prettier was to not have to use a linter as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A-ha! We stubbed our toe on this on entropic as well: prettier is only a formatter & won't lint for you. You have to bring in eslint to do the linting step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrisdickinson is correct.

"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2015",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean using require? I'd like to compile down to ESM, since we're using https://npm.im/esm to support native ESM loading.

Copy link
Contributor Author

@TejasQ TejasQ Jul 8, 2019

Choose a reason for hiding this comment

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

Not necessarily. This just means we use language features from ES2015 like const, let, and all of its goodness and don't transpile to an older version of JS. The module configuration is addressed by your next comment. It uses esnext modules which I believe is equivalent to ESM.

Choose a reason for hiding this comment

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

@zkat, the target could be bumped higher if you want. Depends what features you want to support sans transpilation.

// "incremental": true, /* Enable incremental compilation */
"target": "es2015",
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "esnext",
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this answers my above question :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does answer your above question.

tsconfig.json Show resolved Hide resolved
@@ -0,0 +1,75 @@
declare module "figgy-pudding" {
Copy link
Contributor

Choose a reason for hiding this comment

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

this whole module is a heroic effort of types and I can't even read most of it. Amazing!

Copy link
Contributor Author

@TejasQ TejasQ Jul 8, 2019

Choose a reason for hiding this comment

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

This is @forivall's great effort. I merely forked her idea and tweaked it a bit. 馃槏 馃敟

Choose a reason for hiding this comment

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

There's a PR up in the figgy-pudding repo, so I guess see what happens with that. In the interim, including the types for that package here is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly, I no longer own figgy-pudding myself (it belongs to $VCPM), and I need to lock down that particular repo, which is only there for archival purposes.

Choose a reason for hiding this comment

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

In that case, a PR to DefinitelyTyped makes sense. And as mentioned you can test the types, zkat/figgy-pudding#13 (comment)

Copy link

@forivall forivall Jul 9, 2019

Choose a reason for hiding this comment

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

Ive submitted lots of typedefs to definitely typed, and I could take my old pr, update it and submit it there - especially as I've improved in my typedefs writing skills, and I'm sure they'd improvements to make. I've mostly abandoned the pr to figgy-pudding, as I mostly wrote it in my personal efforts to understand the npm cli, and I never ended up using figgy-pudding myself

@static-raccoon
Copy link

This pull request has been mentioned on Entropic. There might be relevant details there:

https://discourse.entropic.dev/t/looking-for-help-setting-up-typescript-prettier-for-ds/194/10

@@ -0,0 +1,15 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
Copy link

Choose a reason for hiding this comment

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

Missing an ending newline on these two JSON files, and their format differs from the others (spaces)

.prettierrc Outdated
@@ -0,0 +1,5 @@
{
"semi": true,
Copy link

Choose a reason for hiding this comment

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

This config differs from what's in github.com/entropic-dev/entropic. Would there be value in keeping them synced up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great idea! I wasn't aware that project had prettier settings! Will update.

then: {},
};

Object.keys(module.exports).forEach(k => {
Copy link

Choose a reason for hiding this comment

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

Why the mixed module types here?

Copy link
Contributor Author

@TejasQ TejasQ Jul 9, 2019

Choose a reason for hiding this comment

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

So I didn't write any of this. 馃槈 I just moved the js to ts. @zkat has the answers to these kinds of questions. I'd say any review on their pre-existing code though is out of the scope of this PR and can be handled in other ones.

Copy link

Choose a reason for hiding this comment

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

Oh right on, good to know.

import mkCmd from "../utils/cmd-handler";
import { Argv } from "yargs";

const Shell = (module.exports = {
Copy link

Choose a reason for hiding this comment

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

More mixed module systems. I've found that this can cause issues for folks who aren't super familiar with the codebase, especially as projects grow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see #2 (comment)

@@ -0,0 +1,50 @@
import fs from "fs";
Copy link

Choose a reason for hiding this comment

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

Should this be import * as fs from 'fs' for correctness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. I've configured typescript for more readable imports like this. 馃槃

Module._extensions[".jsx"] = (module: any, filename: string) => {
const content = fs.readFileSync(filename, "utf8");
if (!babel) {
babel = require("babel-core");
Copy link

Choose a reason for hiding this comment

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

These two babel packages are unmaintained, should probably be @babel/core and @babel/plugin-transform-react-jsx

Choose a reason for hiding this comment

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

Makes sense to upgrade this, but but probably in another PR as it's not related to TS, Husky, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see #2 (comment).

babel = require("babel-core");
}
if (!tsPlugin) {
tsPlugin = require("babel-plugin-transform-typescript");
Copy link

Choose a reason for hiding this comment

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

Same here, there's a @babel/plugin-transform-typescript

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, please see #2 (comment).

export function overrideNode() {
require("./extensions").overrideNode();
}
overrideNode();
Copy link

Choose a reason for hiding this comment

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

Why the extra function wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see #2 (comment).

Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

First pass perusing the code base. I'll grab it locally to dig a little more.

.lintstagedrc Outdated
"prettier --write",
"git add"
],
"*.(tsx|ts)": [
Copy link

Choose a reason for hiding this comment

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

Minor, but this can be one glob, for JS and TS, *.{js,jsx,ts,tsx}. See https://github.com/nickytonline/www.iamdeveloper.com/blob/master/package.json#L38

@zkat, it might be out of the scope of this PR, but prettier handles markdown as well. I'd say let prettier handle as much of the formatting as possible. Thoughts?

"*.md": [
	"prettier --write",
	"git add"
]

Choose a reason for hiding this comment

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

Same goes for rust, but I don't have any experience with rust. Do they have other packages for formatting rust code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say let prettier handle as much of the formatting as possible.

I'm down

@@ -0,0 +1,75 @@
declare module "figgy-pudding" {

Choose a reason for hiding this comment

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

There's a PR up in the figgy-pudding repo, so I guess see what happens with that. In the interim, including the types for that package here is fine.

.gitignore Outdated Show resolved Hide resolved
@@ -0,0 +1,84 @@
{
Copy link

Choose a reason for hiding this comment

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

A future suggestion if more repos for entropic use TypeScript. Consider creating a master tsconfig.json and inherit from it. For an example, see https://github.com/sindresorhus/refined-github/blob/master/tsconfig.json The less code and config to maintain, the better 馃槈

The configuration that Sinder has, is pretty decent. You could even use that one.

Thoughts @zkat @TejasQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, yes, of course but the project is reasonably small now so I'm not sure why we'd do that? As far as I can tell, this is the first tsconfig.json in any entropic project. Naturally, we'll extend a base config if more appear.

Choose a reason for hiding this comment

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

For sure, that's why I prefaced it with A future suggestion... 馃槈

Copy link
Contributor Author

@TejasQ TejasQ Jul 9, 2019

Choose a reason for hiding this comment

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

While I appreciate the suggestion, I suggest we do our best to avoid getting off topic and stick to reviewing the PR according to its scope. 馃挒

@@ -6,6 +6,11 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"

Choose a reason for hiding this comment

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

According to the README, babel is handling the build, but while you're doing dev, it's nice to have the type checker running (npm run type-check:watch). You'd also want the type checker to run as part of the build (npm run type-check).

Suggested change
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"type-check": "tsc",
"type-check:watch": "npm run type-check -- --watch",
},

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 would hold off on this until there's an actual build or start script because right now (for the scope of this PR), it's too early to add such scripts.

// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */

Choose a reason for hiding this comment

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

Since babel is handling the build, we don't need to emit the output. All we care about are the declaration files.

Suggested change
// "noEmit": true, /* Do not emit outputs. */
"noEmit": true, /* Do not emit outputs. */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see #2 (comment).

@nickytonline
Copy link

nickytonline commented Jul 9, 2019

Nice work @TejasQ!. Excited to see this land. In the meantime, I have to 馃泴. 馃憢

.lintstagedrc Outdated
"*.(jsx|js)": [
"eslint --fix",
"git add"
]

Choose a reason for hiding this comment

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

Suggested change
]
],
"*.md": [
"prettier --write",
"git add"
]

@TejasQ
Copy link
Contributor Author

TejasQ commented Jul 9, 2019

@zkat I鈥檝e addressed all the comments. Shall we wait for more feedback or mergy mergy?

Copy link
Contributor

@zkat zkat left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you so much for all the setup, and thanks everyone who took the time to review the PR. I'm excited to merge this now, and I'm sure we can make further adjustments as time goes on. This is an important PR because it means we're unblocked on further development for the Node side.

Thanks again! I hope you'll continue to participate in this project. I appreciate this so much!

@zkat zkat merged commit 4ed8d57 into entropic-dev:latest Jul 9, 2019
@static-raccoon
Copy link

This pull request has been mentioned on Entropic. There might be relevant details there:

https://discourse.entropic.dev/t/looking-for-help-setting-up-typescript-prettier-for-ds/194/13

@TejasQ TejasQ deleted the typescript-prettier-setup branch July 10, 2019 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants