Skip to content

Commit 1a8c7d3

Browse files
merge js and ts guides, update deprecated links
Co-authored-by: Dave Iverson <[email protected]>
1 parent e7efd88 commit 1a8c7d3

File tree

9 files changed

+106
-114
lines changed

9 files changed

+106
-114
lines changed

.hound.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ coffeescript:
22
enabled: false
33
eslint:
44
enabled: true
5-
config_file: javascript/.eslintrc.json
5+
config_file: javascript-typescript/.eslintrc.json
66
version: 6.3.0
77
haml:
88
enabled: true

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ programming in style.
4848
- [Haskell](/haskell/)
4949
- [HTML](/html/)
5050
- [Java](/java/)
51-
- [JavaScript](/javascript/)
51+
- [JavaScript & TypeScript](/javascript-typescript/)
5252
- [Objective-C](/objective-c/)
5353
- [Python](/python/)
5454
- [Ruby](/ruby/)
5555
- [Sass](/sass/)
5656
- [Scala](/scala/)
5757
- [Shell](/shell/)
5858
- [Swift](/swift/)
59-
- [TypeScript](/typescript/)
6059

6160
### Frameworks and platforms
6261

File renamed without changes.

javascript-typescript/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# JavaScript & TypeScript
2+
3+
## JavaScript
4+
5+
[Sample](sample.js)
6+
7+
- Use [TypeScript](#typescript)
8+
- Use the latest stable JavaScript syntax with a transpiler, such as [babel].
9+
- Use [ESLint] and [Prettier] for auto-formatting and auto-fixing
10+
- Use [Jest] for unit testing
11+
- Prefer ES6 classes over prototypes.
12+
- Use strict equality checks (`===` and `!==`) except when comparing against
13+
(`null` or `undefined`).
14+
- Prefer [arrow functions] `=>`, over the `function` keyword except when
15+
defining classes or methods.
16+
- Prefer ES6 [destructuring] over object literal notation.
17+
- Use ES6 [spread] and [rest] operator wherever possible for a cleaner code.
18+
- Use `PascalCase` for classes, `lowerCamelCase` for variables and functions,
19+
`SCREAMING_SNAKE_CASE` for constants, `_singleLeadingUnderscore` for private
20+
variables and functions.
21+
- Prefer [template strings] over string concatenation.
22+
- Prefer promises over callbacks.
23+
- Prefer array functions like `forEach`, `map`, `filter` and `reduce` over `for/while` loops.
24+
- Use `const` for declaring variables that will never be re-assigned, and `let`
25+
otherwise.
26+
- Avoid `var` to declare variables.
27+
- Prefer [async/await] over traditional promise syntax
28+
- Use the [Nullish coalescing operator] `??`
29+
30+
## TypeScript
31+
32+
- Use TypeScript in [strict mode]
33+
- Prefer [Functions] over [Classes]
34+
- Use `PascalCase` for [Interfaces] and [Type Aliases]
35+
- Use [readonly] properties where applicable
36+
- Use [const Assertions] where applicable to avoid type widening
37+
- Avoid [Mixins]
38+
- Avoid [Decorators]
39+
- Avoid [Overloading Functions]
40+
- Prefer [Optional Properties] in an interface rather than declaring the
41+
property type as `T | undefined`
42+
- Prefer explicitly defining interfaces over [Extending Interfaces]
43+
- Avoid the use of the [any] type
44+
- Avoid the [Non-null assertion operator]
45+
- Avoid [Type Assertions]
46+
- Prefer the `as`-syntax for [Type Assertions] over the angle-bracket syntax
47+
- Prefer [Type Guards] over [Type Assertions]
48+
- Prefer [Union Types], [Lookup Types], [Mapped Types] and [const Assertions]
49+
over [Enums]
50+
- Prefer [arrow functions] `=>`, over the `function` keyword except when using
51+
[Generics]
52+
53+
## Formatting
54+
55+
- Use [Prettier defaults](https://prettier.io/docs/en/options.html) with the following additional configuration (.prettierrc):
56+
57+
```json
58+
{
59+
"singleQuote": true
60+
}
61+
```
62+
63+
This configuration includes:
64+
- Use semicolons at the end of each statement ([sample](/javascript/sample.js#L5))
65+
- Prefer single quotes ([sample](/javascript/sample.js#L11))
66+
- Use a trailing comma after each item in a multi-line array or object literal, including the last item. ([sample](/javascript/sample.js#L11))
67+
68+
If ESLint is used along with Prettier, the ESLInt plugin [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) should also be used to turn off all ESLint style rules that are already handled by Prettier.
69+
70+
[babel]: https://babeljs.io/
71+
[eslint]: https://eslint.org/
72+
[prettier]: https://prettier.io/
73+
[jest]: /testing-jest/
74+
[template strings]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
75+
[arrow functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
76+
[destructuring]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
77+
[spread]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
78+
[rest]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters
79+
[functions]: https://www.typescriptlang.org/docs/handbook/2/functions.html
80+
[classes]: https://www.typescriptlang.org/docs/handbook/2/classes.html
81+
[readonly]: https://www.typescriptlang.org/docs/handbook/2/objects.html#readonly-properties
82+
[const Assertions]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions
83+
[overloading functions]: https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads
84+
[async/await]: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await
85+
[optional properties]: https://www.typescriptlang.org/docs/handbook/2/objects.html#optional-properties
86+
[extending interfaces]: https://www.typescriptlang.org/docs/handbook/2/objects.html#extending-types
87+
[any]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any
88+
[non-null assertion operator]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator
89+
[type assertions]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions
90+
[Nullish coalescing operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
91+
[Type Guards]: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#typeof-type-guards
92+
[generics]: https://www.typescriptlang.org/docs/handbook/2/generics.html
93+
[strict mode]: https://www.typescriptlang.org/tsconfig/#strict
94+
[mixins]: https://www.typescriptlang.org/docs/handbook/mixins.html
95+
[decorators]: https://www.typescriptlang.org/docs/handbook/decorators.html
96+
[union types]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types
97+
[lookup types]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#keyof-and-lookup-types
98+
[mapped types]: https://www.typescriptlang.org/docs/handbook/2/mapped-types.html
99+
[enums]: https://www.typescriptlang.org/docs/handbook/enums.html
100+
[interfaces]: https://www.typescriptlang.org/docs/handbook/2/objects.html
101+
[type aliases]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-aliases
File renamed without changes.

javascript/README.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

react-native/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# React Native
22

33
- Use React following the [React Guide](/react/)
4-
- Use [TypeScript](/typescript/)
4+
- Use [TypeScript](/javascript-typescript/README.md#typescript)
55
- Prefer using [core components and apis] over writing bespoke components.
66

77
[core components and apis]: https://reactnative.dev/docs/components-and-apis

react/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# React
22

33
- Use React in [Strict Mode]
4-
- Use React with [TypeScript](/typescript/)
4+
- Use React with [TypeScript](/javascript-typescript/README.md#typescript)
55
- Avoid nested routing if using [React Router]
66
- Prefer [Function Components] over [Class Components]
77
- Prefer keeping a single component in each file
@@ -17,6 +17,7 @@
1717
- Prefer the [short syntax] when using [Fragments]
1818
- Prefer [React Contexts] over [Redux]
1919
- Avoid using indexes as the value for [keys]
20+
- Avoid complex conditionals inside component logic
2021
- Prefer [component composition over component inheritance]
2122

2223
[strict mode]: https://reactjs.org/docs/strict-mode.html

typescript/README.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)