diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..ac16d553d --- /dev/null +++ b/.prettierignore @@ -0,0 +1,10 @@ +node_modules +client/build +client/node_modules +client/package-lock.json +client/package.json + +*.enc +.all-contributorsrc +package-lock.json +package.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 000000000..420ef54b3 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,58 @@ +{ + "arrowParens": "always", + "bracketSpacing": true, + "endOfLine": "lf", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "requirePragma": false, + "semi": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false, + "vueIndentScriptAndStyle": false, + "parser": "babel", + "overrides": [ + { + "files": "*.json", + "options": { + "parser": "json" + } + }, + { + "files": "*.css", + "options": { + "parser": "css" + } + }, + { + "files": "*.scss", + "options": { + "parser": "scss" + } + }, + { + "files": "*.md", + "options": { + "parser": "markdown" + } + }, + { + "files": "*.html", + "options": { + "parser": "html" + } + }, + { + "files": ["*.yml", "*.yaml"], + "options": { + "parser": "yaml" + } + } + ] +} diff --git a/client/README.md b/client/README.md index b8c0b74df..4e86ce084 100644 --- a/client/README.md +++ b/client/README.md @@ -99,8 +99,8 @@ You can find the most recent version of this guide [here](https://github.com/fac Create React App is divided into two packages: -* `create-react-app` is a global command-line utility that you use to create new projects. -* `react-scripts` is a development dependency in the generated projects (including this one). +- `create-react-app` is a global command-line utility that you use to create new projects. +- `react-scripts` is a development dependency in the generated projects (including this one). You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`. @@ -139,8 +139,8 @@ my-app/ For the project to build, **these files must exist with exact filenames**: -* `public/index.html` is the page template; -* `src/index.js` is the JavaScript entry point. +- `public/index.html` is the page template; +- `src/index.js` is the JavaScript entry point. You can delete or rename the other files. @@ -195,12 +195,12 @@ You don’t have to ever use `eject`. The curated feature set is suitable for sm This project supports a superset of the latest JavaScript standard.
In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports: -* [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016). -* [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017). -* [Object Rest/Spread Properties](https://github.com/sebmarkbage/ecmascript-rest-spread) (stage 3 proposal). -* [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal) -* [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (part of stage 3 proposal). -* [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flowtype.org/) syntax. +- [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016). +- [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017). +- [Object Rest/Spread Properties](https://github.com/sebmarkbage/ecmascript-rest-spread) (stage 3 proposal). +- [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal) +- [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (part of stage 3 proposal). +- [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flowtype.org/) syntax. Learn more about [different proposal stages](https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-). @@ -208,9 +208,9 @@ While we recommend using experimental proposals with some caution, Facebook heav Note that **the project only includes a few ES6 [polyfills](https://en.wikipedia.org/wiki/Polyfill)**: -* [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) via [`object-assign`](https://github.com/sindresorhus/object-assign). -* [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) via [`promise`](https://github.com/then/promise). -* [`fetch()`](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) via [`whatwg-fetch`](https://github.com/github/fetch). +- [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) via [`object-assign`](https://github.com/sindresorhus/object-assign). +- [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) via [`promise`](https://github.com/then/promise). +- [`fetch()`](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) via [`whatwg-fetch`](https://github.com/github/fetch). If you use any other ES6+ features that need **runtime support** (such as `Array.from()` or `Symbol`), make sure you are including the appropriate polyfills manually, or that the browsers you are targeting already support them. @@ -220,8 +220,8 @@ To configure the syntax highlighting in your favorite text editor, head to the [ ## Displaying Lint Output in the Editor ->Note: this feature is available with `react-scripts@0.2.0` and higher.
->It also only works with npm 3 or higher. +> Note: this feature is available with `react-scripts@0.2.0` and higher.
+> It also only works with npm 3 or higher. Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint. @@ -256,19 +256,22 @@ Then add the block below to your `launch.json` file and put it inside the `.vsco ```json { "version": "0.2.0", - "configurations": [{ - "name": "Chrome", - "type": "chrome", - "request": "launch", - "url": "http://localhost:3000", - "webRoot": "${workspaceRoot}/src", - "sourceMapPathOverrides": { - "webpack:///src/*": "${webRoot}/*" + "configurations": [ + { + "name": "Chrome", + "type": "chrome", + "request": "launch", + "url": "http://localhost:3000", + "webRoot": "${workspaceRoot}/src", + "sourceMapPathOverrides": { + "webpack:///src/*": "${webRoot}/*" + } } - }] + ] } ``` ->Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration). + +> Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration). Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor. @@ -280,11 +283,11 @@ You would need to have [WebStorm](https://www.jetbrains.com/webstorm/) and [JetB In the WebStorm menu `Run` select `Edit Configurations...`. Then click `+` and select `JavaScript Debug`. Paste `http://localhost:3000` into the URL field and save the configuration. ->Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration). +> Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration). Start your app by running `npm start`, then press `^D` on macOS or `F9` on Windows and Linux or click the green debug icon to start debugging in WebStorm. -The same way you can debug your application in IntelliJ IDEA Ultimate, PhpStorm, PyCharm Pro, and RubyMine. +The same way you can debug your application in IntelliJ IDEA Ultimate, PhpStorm, PyCharm Pro, and RubyMine. ## Formatting Code Automatically @@ -302,9 +305,9 @@ Alternatively you may use `yarn`: yarn add husky lint-staged prettier ``` -* `husky` makes it easy to use githooks as if they are npm scripts. -* `lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8). -* `prettier` is the JavaScript formatter we will run before commits. +- `husky` makes it easy to use githooks as if they are npm scripts. +- `lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8). +- `prettier` is the JavaScript formatter we will run before commits. Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root. @@ -372,7 +375,7 @@ For example: ### `Button.js` ```js -import React, { Component } from 'react'; +import React, { Component } from "react"; class Button extends Component { render() { @@ -385,10 +388,9 @@ export default Button; // Don’t forget to use export default! ### `DangerButton.js` - ```js -import React, { Component } from 'react'; -import Button from './Button'; // Import a component from another file +import React, { Component } from "react"; +import Button from "./Button"; // Import a component from another file class DangerButton extends Component { render() { @@ -407,9 +409,9 @@ Named exports are useful for utility modules that export several functions. A mo Learn more about ES6 modules: -* [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281) -* [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html) -* [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules) +- [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281) +- [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html) +- [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules) ## Code Splitting @@ -422,22 +424,23 @@ Here is an example: ### `moduleA.js` ```js -const moduleA = 'Hello'; +const moduleA = "Hello"; export { moduleA }; ``` + ### `App.js` ```js -import React, { Component } from 'react'; +import React, { Component } from "react"; class App extends Component { handleClick = () => { - import('./moduleA') + import("./moduleA") .then(({ moduleA }) => { // Use moduleA }) - .catch(err => { + .catch((err) => { // Handle failure }); }; @@ -477,8 +480,8 @@ This project setup uses [Webpack](https://webpack.js.org/) for handling all asse ### `Button.js` ```js -import React, { Component } from 'react'; -import './Button.css'; // Tell Webpack that Button.js uses these styles +import React, { Component } from "react"; +import "./Button.css"; // Tell Webpack that Button.js uses these styles class Button extends Component { render() { @@ -517,11 +520,11 @@ becomes this: display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; - -ms-flex-direction: row; - flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; + -ms-flex-align: center; + align-items: center; } ``` @@ -556,13 +559,13 @@ Then in `package.json`, add the following lines to `scripts`: "test": "react-scripts test --env=jsdom", ``` ->Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation. +> Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation. Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`. The watcher will find every Sass file in `src` subdirectories, and create a corresponding CSS file next to it, in our case overwriting `src/App.css`. Since `src/App.js` still imports `src/App.css`, the styles become a part of your application. You can now edit `src/App.scss`, and `src/App.css` will be regenerated. To share variables between Sass files, you can use Sass imports. For example, `src/App.scss` and other component style files could include `@import "./shared.scss";` with variable definitions. -To enable importing files without using relative paths, you can add the `--include-path` option to the command in `package.json`. +To enable importing files without using relative paths, you can add the `--include-path` option to the command in `package.json`. ``` "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/", @@ -572,8 +575,8 @@ To enable importing files without using relative paths, you can add the `--incl This will allow you to do imports like ```scss -@import 'styles/_colors.scss'; // assuming a styles directory under src/ -@import 'nprogress/nprogress'; // importing a css file from the nprogress node module +@import "styles/_colors.scss"; // assuming a styles directory under src/ +@import "nprogress/nprogress"; // importing a css file from the nprogress node module ``` At this point you might want to remove all CSS files from the source control, and add `src/**/*.css` to your `.gitignore` file. It is generally a good practice to keep the build products outside of the source control. @@ -613,13 +616,13 @@ Now running `npm start` and `npm run build` also builds Sass files. `node-sass` has been reported as having the following issues: -- `node-sass --watch` has been reported to have *performance issues* in certain conditions when used in a virtual machine or with docker. +- `node-sass --watch` has been reported to have _performance issues_ in certain conditions when used in a virtual machine or with docker. - Infinite styles compiling [#1939](https://github.com/facebookincubator/create-react-app/issues/1939) - `node-sass` has been reported as having issues with detecting new files in a directory [#1891](https://github.com/sass/node-sass/issues/1891) - `node-sass-chokidar` is used here as it addresses these issues. +`node-sass-chokidar` is used here as it addresses these issues. ## Adding Images, Fonts, and Files @@ -632,8 +635,8 @@ To reduce the number of requests to the server, importing images that are less t Here is an example: ```js -import React from 'react'; -import logo from './logo.png'; // Tell Webpack this JS file uses this image +import React from "react"; +import logo from "./logo.png"; // Tell Webpack this JS file uses this image console.log(logo); // /logo.84287d09.png @@ -664,7 +667,7 @@ An alternative way of handling static assets is described in the next section. ## Using the `public` Folder ->Note: this feature is available with `react-scripts@0.5.0` and higher. +> Note: this feature is available with `react-scripts@0.5.0` and higher. ### Changing the HTML @@ -679,18 +682,18 @@ Note that we normally encourage you to `import` assets in JavaScript files inste For example, see the sections on [adding a stylesheet](#adding-a-stylesheet) and [adding images and fonts](#adding-images-fonts-and-files). This mechanism provides a number of benefits: -* Scripts and stylesheets get minified and bundled together to avoid extra network requests. -* Missing files cause compilation errors instead of 404 errors for your users. -* Result filenames include content hashes so you don’t need to worry about browsers caching their old versions. +- Scripts and stylesheets get minified and bundled together to avoid extra network requests. +- Missing files cause compilation errors instead of 404 errors for your users. +- Result filenames include content hashes so you don’t need to worry about browsers caching their old versions. However there is an **escape hatch** that you can use to add an asset outside of the module system. -If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`. +If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`. Inside `index.html`, you can use it like this: ```html - + ``` Only files inside the `public` folder will be accessible by `%PUBLIC_URL%` prefix. If you need to use a file from `src` or `node_modules`, you’ll have to copy it there to explicitly specify your intention to make this file a part of the build. @@ -710,19 +713,19 @@ render() { Keep in mind the downsides of this approach: -* None of the files in `public` folder get post-processed or minified. -* Missing files will not be called at compilation time, and will cause 404 errors for your users. -* Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change. +- None of the files in `public` folder get post-processed or minified. +- Missing files will not be called at compilation time, and will cause 404 errors for your users. +- Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change. ### When to Use the `public` Folder Normally we recommend importing [stylesheets](#adding-a-stylesheet), [images, and fonts](#adding-images-fonts-and-files) from JavaScript. The `public` folder is useful as a workaround for a number of less common cases: -* You need a file with a specific name in the build output, such as [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest). -* You have thousands of images and need to dynamically reference their paths. -* You want to include a small script like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code. -* Some library may be incompatible with Webpack and you have no other option but to include it as a `