Skip to content

Commit c184d0b

Browse files
committed
Add prettier
1 parent 319c144 commit c184d0b

File tree

7 files changed

+68
-34
lines changed

7 files changed

+68
-34
lines changed

.eslintrc.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module.exports = {
2-
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
2+
parser: "@typescript-eslint/parser",
33
extends: [
4-
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
5-
"plugin:@typescript-eslint/recommended" // Uses the recommended rules from @typescript-eslint/eslint-plugin
4+
"plugin:react/recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
7+
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
68
],
79
parserOptions: {
810
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features

.prettierrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: "all",
4+
singleQuote: false,
5+
printWidth: 120,
6+
tabWidth: 4,
7+
bracketSpacing: false
8+
};

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"@typescript-eslint/eslint-plugin": "^2.17.0",
5353
"@typescript-eslint/parser": "^2.17.0",
5454
"eslint": "^6.8.0",
55-
"eslint-plugin-react": "^7.18.0"
55+
"eslint-config-prettier": "^6.9.0",
56+
"eslint-plugin-prettier": "^3.1.2",
57+
"eslint-plugin-react": "^7.18.0",
58+
"prettier": "^1.19.1"
5659
}
5760
}

src/app/App.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ const App: React.FC = () => {
88
<header className="App-header">
99
<img src={logo} className="App-logo" alt="logo" />
1010
<p>
11-
Edit <code>src/App.tsx</code> and save to reload.
11+
Edit <code>src/App.tsx</code> and save to reload.
1212
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
13+
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
14+
Learn React
2015
</a>
2116
</header>
2217
</div>

src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const render = (): void => {
1313
<Provider store={store}>
1414
<App />
1515
</Provider>,
16-
document.getElementById("root")
16+
document.getElementById("root"),
1717
);
1818
};
1919

src/serviceWorker.ts

+11-21
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212

1313
const isLocalhost = Boolean(
1414
window.location.hostname === "localhost" ||
15-
// [::1] is the IPv6 localhost address.
16-
window.location.hostname === "[::1]" ||
17-
// 127.0.0.0/8 are considered localhost for IPv4.
18-
window.location.hostname.match(
19-
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20-
)
15+
// [::1] is the IPv6 localhost address.
16+
window.location.hostname === "[::1]" ||
17+
// 127.0.0.0/8 are considered localhost for IPv4.
18+
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),
2119
);
2220

2321
type Config = {
@@ -27,11 +25,8 @@ type Config = {
2725

2826
export function register(config?: Config): void {
2927
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
30-
// The URL constructor is available in all browsers that support SW.
31-
const publicUrl = new URL(
32-
process.env.PUBLIC_URL,
33-
window.location.href
34-
);
28+
// The URL constructor is available in all browsers that support SW.
29+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
3530
if (publicUrl.origin !== window.location.origin) {
3631
// Our service worker won't work if PUBLIC_URL is on a different origin
3732
// from what our page is served on. This might happen if a CDN is used to
@@ -51,7 +46,7 @@ export function register(config?: Config): void {
5146
navigator.serviceWorker.ready.then(() => {
5247
console.log(
5348
"This web app is being served cache-first by a service " +
54-
"worker. To learn more, visit https://bit.ly/CRA-PWA"
49+
"worker. To learn more, visit https://bit.ly/CRA-PWA",
5550
);
5651
});
5752
} else {
@@ -79,7 +74,7 @@ function registerValidSW(swUrl: string, config?: Config): void {
7974
// content until all client tabs are closed.
8075
console.log(
8176
"New content is available and will be used when all " +
82-
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
77+
"tabs for this page are closed. See https://bit.ly/CRA-PWA.",
8378
);
8479

8580
// Execute callback
@@ -109,15 +104,12 @@ function registerValidSW(swUrl: string, config?: Config): void {
109104
function checkValidServiceWorker(swUrl: string, config?: Config): void {
110105
// Check if the service worker can be found. If it can't reload the page.
111106
fetch(swUrl, {
112-
headers: {"Service-Worker": "script"}
107+
headers: {"Service-Worker": "script"},
113108
})
114109
.then(response => {
115110
// Ensure service worker exists, and that we really are getting a JS file.
116111
const contentType = response.headers.get("content-type");
117-
if (
118-
response.status === 404 ||
119-
(contentType != null && contentType.indexOf("javascript") === -1)
120-
) {
112+
if (response.status === 404 || (contentType != null && contentType.indexOf("javascript") === -1)) {
121113
// No service worker found. Probably a different app. Reload the page.
122114
navigator.serviceWorker.ready.then(registration => {
123115
registration.unregister().then(() => {
@@ -130,9 +122,7 @@ function checkValidServiceWorker(swUrl: string, config?: Config): void {
130122
}
131123
})
132124
.catch(() => {
133-
console.log(
134-
"No internet connection found. App is running in offline mode."
135-
);
125+
console.log("No internet connection found. App is running in offline mode.");
136126
});
137127
}
138128

yarn.lock

+36
Original file line numberDiff line numberDiff line change
@@ -5314,6 +5314,13 @@ escodegen@^1.11.0, escodegen@^1.9.1:
53145314
optionalDependencies:
53155315
source-map "~0.6.1"
53165316

5317+
eslint-config-prettier@^6.9.0:
5318+
version "6.9.0"
5319+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.9.0.tgz#430d24822e82f7deb1e22a435bfa3999fae4ad64"
5320+
integrity sha512-k4E14HBtcLv0uqThaI6I/n1LEqROp8XaPu6SO9Z32u5NlGRC07Enu1Bh2KEFw4FNHbekH8yzbIU9kUGxbiGmCA==
5321+
dependencies:
5322+
get-stdin "^6.0.0"
5323+
53175324
eslint-config-react-app@^5.1.0:
53185325
version "5.1.0"
53195326
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-5.1.0.tgz#a37b3f2d4f56f856f93277281ef52bd791273e63"
@@ -5387,6 +5394,13 @@ [email protected]:
53875394
has "^1.0.3"
53885395
jsx-ast-utils "^2.2.1"
53895396

5397+
eslint-plugin-prettier@^3.1.2:
5398+
version "3.1.2"
5399+
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz#432e5a667666ab84ce72f945c72f77d996a5c9ba"
5400+
integrity sha512-GlolCC9y3XZfv3RQfwGew7NnuFDKsfI4lbvRK+PIIo23SFH+LemGs4cKwzAaRa+Mdb+lQO/STaIayno8T5sJJA==
5401+
dependencies:
5402+
prettier-linter-helpers "^1.0.0"
5403+
53905404
eslint-plugin-react-hooks@^1.6.1:
53915405
version "1.7.0"
53925406
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz#6210b6d5a37205f0b92858f895a4e827020a7d04"
@@ -5763,6 +5777,11 @@ fast-deep-equal@^2.0.1:
57635777
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
57645778
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
57655779

5780+
fast-diff@^1.1.2:
5781+
version "1.2.0"
5782+
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
5783+
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
5784+
57665785
fast-glob@^2.0.2:
57675786
version "2.2.7"
57685787
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.7.tgz#6953857c3afa475fff92ee6015d52da70a4cd39d"
@@ -6268,6 +6287,11 @@ get-own-enumerable-property-symbols@^3.0.0:
62686287
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.1.tgz#6f7764f88ea11e0b514bd9bd860a132259992ca4"
62696288
integrity sha512-09/VS4iek66Dh2bctjRkowueRJbY1JDGR1L/zRxO1Qk8Uxs6PnqaNSqalpizPT+CDjre3hnEsuzvhgomz9qYrA==
62706289

6290+
get-stdin@^6.0.0:
6291+
version "6.0.0"
6292+
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
6293+
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
6294+
62716295
get-stream@^4.0.0:
62726296
version "4.1.0"
62736297
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
@@ -10436,6 +10460,18 @@ prepend-http@^1.0.0:
1043610460
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
1043710461
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
1043810462

10463+
prettier-linter-helpers@^1.0.0:
10464+
version "1.0.0"
10465+
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
10466+
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
10467+
dependencies:
10468+
fast-diff "^1.1.2"
10469+
10470+
prettier@^1.19.1:
10471+
version "1.19.1"
10472+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
10473+
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
10474+
1043910475
pretty-bytes@^5.1.0:
1044010476
version "5.3.0"
1044110477
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.3.0.tgz#f2849e27db79fb4d6cfe24764fc4134f165989f2"

0 commit comments

Comments
 (0)