-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Proposal: Convert codebase CoffeeScript => JS => TypeScript #2690
Comments
Decaffeination GuideUse this checklist to make converted JS code more readable. Summary: - [ ] Remove unused variables, arguments, functions
- [ ] Convert to arrow functions
- [ ] Fix weird conditional expressions
- [ ] Move variables close to where they're used
- [ ] Change `switch` to `if` if it has only one case (with `default`)
- [ ] Drag down comments
- [ ] Remove unnecessary `return`s.
- [ ] Remove functions when they're used to assign a value Copy above to check your code. Remove unused variables, arguments, functionsAs CoffeeScript doesn't show which names are unused, we can find a lot of unused variables, arguments, or functions. 👎 Bad:const func = (a, b) => {
const c = 'hi?'
return a + 3
}
const unusedFunc = (a, b, c) => {
// something complicated going on.
}
const d = func(3) 👍 Good:const func = (a) => {
return a + 3
}
const d = func(3) Covert to arrow functions
👎 Bad:const f = function (a, b) {
// do something
} 👍 Good:const f = (a, b) => {
// do something
} Note: If you're a VS Code user, you can do this faster with JS Refactor plugin. Press Fix weird conditional expressionsConverted JS code of CoffeeScript 👎 Bad:x = $el?.length ? 0 const x = ($el != null ? $el.length : undefined) != null ? ($el != null ? $el.length : undefined) : 0 👍 Good:const x = $el != null ? $el.length
// or
const x = $el ? $el.length Note: There are 2 answers here because Move variables close to where it is used.Sometimes, converted JavaScript variables are at the top of the function when those are used at the bottom of the function. Move them near to the line it is used. 👎 Bad:const f = () => {
let x;
// Do something long here.
if (x > 10) {
x = 30;
} else {
x = 3;
}
} 👍 Good:const f = () => {
// Do something long here.
let x;
if (x > 10) {
x = 30;
} else {
x = 3;
}
} Change
|
Instructions for decaffeinating files
|
Goal
Make Cypress' open source repo more accessible to contributors. Improve code quality by implementing types.
Implementation
The text was updated successfully, but these errors were encountered: