grafana/contribute/style-guides/frontend.md

370 lines
7.8 KiB
Markdown
Raw Normal View History

# Frontend style guide
Grafana Labs follows the [Airbnb React/JSX Style Guide](https://github.com/airbnb/javascript/tree/master/react) in matters pertaining to React. This guide provides highlights of the style rules we follow.
## Basic rules
- Try to keep files small and focused.
- Break large components up into sub-components.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Use spaces for indentation.
## Naming conventions
Follow these guidelines when naming elements of your code.
### Class names
Use PascalCase. For example:
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```typescript
// bad
class dataLink {
//...
}
// good
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
class DataLink {
//...
}
```
### Constants
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Use ALL CAPS for constants. For example:
```typescript
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// bad
const constantValue = "This string won't change";
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// bad
const constant_value = "This string won't change";
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// good
const CONSTANT_VALUE = "This string won't change";
```
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
### Emotion class names
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Use camelCase. For example:
```typescript
const getStyles = (theme: GrafanaTheme2) => ({
// bad
ElementWrapper: css`...`,
// bad
['element-wrapper']: css`...`,
// good
elementWrapper: css({
padding: theme.spacing(1, 2),
background: theme.colors.background.secondary,
}),
});
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```
Use hook useStyles2(getStyles) to memoize the styles generation and try to avoid passing props to the getStyles function and instead compose classes using Emotion CX function.
### Enums
Use PascalCase. For example:
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```
// bad
enum buttonVariant {
//...
}
// good
enum ButtonVariant {
//...
}
```
### Files and directories
Name files according to the primary export:
- When the primary export is a class or React component, use PascalCase.
- When the primary export is a function, use camelCase.
For files that export multiple utility functions, use the name that describes the responsibility of grouped utilities. For example, a file that exports math utilities should be named `math.ts`.
- Use `constants.ts` for files that export constants.
- Use `actions.ts` for files that export Redux actions.
- Use `reducers.ts` for Redux reducers.
- Use `*.test.ts(x)` for test files.
For directory names, use dash-case (sometimes called kebab-case).
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Use `features/new-important-feature/utils.ts`
### Functions
Use PascalCase. For example:
Use camelCase.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```typescript
// bad
const CalculatePercentage = () => { ... }
// bad
const calculate_percentage = () => { ... }
// good
const calculatePercentage = () => { ... }
```
### Interfaces
Use PascalCase. For example:
```
// bad
interface buttonProps {
//...
}
// bad
interface button_props {
//...
}
// bad
interface IButtonProps {
//...
}
// good
interface ButtonProps {
//...
}
// bad
type requestInfo = ...
// bad
type request_info = ...
// good
type RequestInfo = ...
```
### Methods
Use PascalCase. For example:
Use camelCase.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```typescript
class DateCalculator {
// bad
CalculateTimeRange () {...}
}
class DateCalculator {
// bad
calculate_time_range () {...}
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
}
class DateCalculator {
// good
calculateTimeRange () {...}
}
```
### React components
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Follow these guidelines for naming React components.
#### React callback props and handlers
Name callback props and handlers with an _on_ prefix. For example:
```tsx
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// bad
handleChange = () => {
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
};
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
render() {
return (
<MyComponent changed={this.handleChange} />
);
}
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// good
onChange = () => {
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
};
render() {
return (
<MyComponent onChange={this.onChange} />
);
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
}
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```
#### React component constructor
Use the following convention when implementing these React components:
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```typescript
// bad
constructor(props) {...}
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// good
constructor(props: Props) {...}
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```
#### React component defaultProps
Use the following convention when implementing these React components:
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```typescript
// bad
static defaultProps = { ... }
// good
static defaultProps: Partial<Props> = { ... }
```
#### React component definitions
Use the following convention when implementing these React components:
```jsx
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// bad
export class YourClass extends PureComponent { ... }
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// good
export class YourClass extends PureComponent<{},{}> { ... }
```
#### React state and properties
Use camelCase. For example:
```typescript
interface ModalState {
// bad
IsActive: boolean;
// bad
is_active: boolean;
// good
isActive: boolean;
}
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```
### SASS
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
SASS styles are deprecated. You should migrate to Emotion whenever you need to modify SASS styles.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
### Types
In general, you should let TypeScript infer the types so that there's no need to explicitly define the type for each variable.
There are some exceptions to this:
```typescript
// TypeScript needs to know the type of arrays or objects; otherwise, it infers type as an array of any
// bad
const stringArray = [];
// good
const stringArray: string[] = [];
```
Build: Upgrade Webpack 5 (#36444) * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * revert(webpack): remove include from babel-loader so symlinks (enterprise) work as before * refactor(webpack): fix deprecation warnings in prod builds * fix(storybook): fix failing builds due to replacing css-optimise webpack plugin * fix(storybook): use raw-loader for svg icons * build(webpack): fix dev script colors error * chore(webpack): bump css-loader and react-refresh-webpack-plugin to latest versions Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2021-08-31 05:55:05 -05:00
Specify function return types explicitly in new code. This improves readability by being able to tell what a function returns just by looking at the signature. It also prevents errors when a function's return type is broader than expected by the author.
> **Note:** Linting is not enabled for this issue because there is old code that needs to be fixed first.
```typescript
// bad
function transform(value?: string) {
if (!value) {
Build: Upgrade Webpack 5 (#36444) * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * revert(webpack): remove include from babel-loader so symlinks (enterprise) work as before * refactor(webpack): fix deprecation warnings in prod builds * fix(storybook): fix failing builds due to replacing css-optimise webpack plugin * fix(storybook): use raw-loader for svg icons * build(webpack): fix dev script colors error * chore(webpack): bump css-loader and react-refresh-webpack-plugin to latest versions Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2021-08-31 05:55:05 -05:00
return undefined;
}
Build: Upgrade Webpack 5 (#36444) * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * revert(webpack): remove include from babel-loader so symlinks (enterprise) work as before * refactor(webpack): fix deprecation warnings in prod builds * fix(storybook): fix failing builds due to replacing css-optimise webpack plugin * fix(storybook): use raw-loader for svg icons * build(webpack): fix dev script colors error * chore(webpack): bump css-loader and react-refresh-webpack-plugin to latest versions Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2021-08-31 05:55:05 -05:00
return applyTransform(value);
}
// good
function transform(value?: string): TransformedValue | undefined {
if (!value) {
Build: Upgrade Webpack 5 (#36444) * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * revert(webpack): remove include from babel-loader so symlinks (enterprise) work as before * refactor(webpack): fix deprecation warnings in prod builds * fix(storybook): fix failing builds due to replacing css-optimise webpack plugin * fix(storybook): use raw-loader for svg icons * build(webpack): fix dev script colors error * chore(webpack): bump css-loader and react-refresh-webpack-plugin to latest versions Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2021-08-31 05:55:05 -05:00
return undefined;
}
Build: Upgrade Webpack 5 (#36444) * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * build(webpack): bump to v5 and successful yarn start compilation * build(webpack): update postcss dependencies * build(webpack): silence warnings about hash renamed to fullhash * build(webpack): enable persistent cache to store generated webpack modules / chunks * build(webpack): prefer eslintWebpackPlugin over tschecker so eslint doesn't block typechecking * chore(yarn): run yarn-deduplicate to clean up dependencies * chore(yarn): refresh lock file after clean install * build(webpack): prefer output.clean over CleanWebpackPlugin * build(webpack): prefer esbuild over babel-loader for dev config * build(babel): turn off cache compression to improve build performance * build(webpack): get production builds working * build(webpack): remove phantomJS (removed from grafana in v7) specific loader * build(webpack): put back babel for dev builds no performance gain in using esbuild in webpack * build(webpack): prefer terser and optimise css plugins for prod. slower but smaller bundles * build(webpack): clean up redundant code. inform postcss about node_modules * build(webpack): remove deprecation warnings flag * build(webpack): bump packages, dev performance optimisations, attempt to get hot working * chore(storybook): use webpack 5 for dev and production builds * build(storybook): speed up dev build * chore(yarn): refresh lock file * chore(webpack): bump webpack and related deps to latest * refactor(webpack): put back inline-source-map, move start scripts out of grafana toolkit * feat(webpack): prefer react-refresh over react-hot-loader * build(webpack): update webpack.hot to use react-refresh * chore: remove react-hot-loader from codebase * refactor(queryeditorrow): fix circular dependency causing react-fast-refresh errors * revert(webpack): remove stats.errorDetails from common config * revert(webpack): remove include from babel-loader so symlinks (enterprise) work as before * refactor(webpack): fix deprecation warnings in prod builds * fix(storybook): fix failing builds due to replacing css-optimise webpack plugin * fix(storybook): use raw-loader for svg icons * build(webpack): fix dev script colors error * chore(webpack): bump css-loader and react-refresh-webpack-plugin to latest versions Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2021-08-31 05:55:05 -05:00
return applyTransform(value);
}
```
### Variables
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Use PascalCase. For example:
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Use camelCase.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
```typescript
// bad
const QueryTargets = [];
// bad
const query_targets = [];
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
// good
const queryTargets = [];
```
## Code organization
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Organize your code in a directory that encloses feature code:
- Put Redux state and domain logic code in the `state` directory (for example, `features/my-feature/state/actions.ts`).
- Put React components in the `components` directory (for example, `features/my-feature/components/ButtonPeopleDreamOf.tsx`).
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Put test files next to the test subject.
- Put containers (pages) in the feature root (for example, `features/my-feature/DashboardPage.tsx`).
- Put API function calls that aren't a Redux thunk in an `api.ts` file within the same directory.
- Subcomponents should live in the component folders. Small components don't need their own folder.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Component SASS styles should live in the same folder as component code.
For code that needs to be used by an external plugin:
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Put components and types in `@grafana/ui`.
- Put data models and data utilities in `@grafana/data`.
- Put runtime services interfaces in `@grafana/runtime`.
### Exports
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Use named exports for all code you want to export from a file.
- Use declaration exports (that is, `export const foo = ...`).
- Avoid using default exports (for example, `export default foo`).
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Export only the code that is meant to be used outside the module.
### Code comments
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
- Use [TSDoc](https://github.com/microsoft/tsdoc) comments to document your code.
- Use [react-docgen](https://github.com/reactjs/react-docgen) comments (`/** ... */`) for props documentation.
- Use inline comments for comments inside functions, classes, etc.
- Please try to follow the [code comment guidelines](./code-comments.md) when adding comments.
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
## Linting
Docs: Update front-end style guide (#22197) * Update front end style guide * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md * Add code samples after review * Update contribute/style-guides/frontend.md * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Review * Review * Update contribute/style-guides/frontend.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
2020-02-21 00:35:54 -06:00
Linting is performed using [@grafana/eslint-config](https://github.com/grafana/eslint-config-grafana).
## Functional components
Use function declarations instead of function expressions when creating a new React functional component. For example:
```typescript
// bad
export const Component = (props: Props) => { ... }
// bad
export const Component: React.FC<Props> = (props) => { ... }
// good
export function Component(props: Props) { ... }
```
## State management
- Don't mutate state in reducers or thunks.
- Use `createSlice`. See [Redux Toolkit](https://redux-toolkit.js.org/) for more details.
- Use `reducerTester` to test reducers. See [Redux framework](redux.md) for more details.
- Use state selectors to access state instead of accessing state directly.