-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
TypeScript, Husky, Prettier and ESLint setup #2
Conversation
Could you remove the |
43e2862
to
d69af6e
Compare
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 |
|
Gotcha. Done! 🎉 |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
@@ -0,0 +1,75 @@ | |||
declare module "figgy-pudding" { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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. 😍 🔥
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
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": [ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #2 (comment).
There was a problem hiding this 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)": [ |
There was a problem hiding this comment.
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"
]
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
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.
@@ -0,0 +1,84 @@ | |||
{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
😉
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
).
"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", | |
}, |
There was a problem hiding this comment.
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. */ |
There was a problem hiding this comment.
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.
// "noEmit": true, /* Do not emit outputs. */ | |
"noEmit": true, /* Do not emit outputs. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #2 (comment).
Nice work @TejasQ!. Excited to see this land. In the meantime, I have to 🛌. 👋 |
.lintstagedrc
Outdated
"*.(jsx|js)": [ | ||
"eslint --fix", | ||
"git add" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
] | |
], | |
"*.md": [ | |
"prettier --write", | |
"git add" | |
] |
@zkat I’ve addressed all the comments. Shall we wait for more feedback or mergy mergy? |
There was a problem hiding this 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!
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 |
This PR adds a nice set of dev tooling around the Entropic JS (now TS) CLI:
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.
🚀