Skip to content

Commit

Permalink
chore: autoformat files before commit
Browse files Browse the repository at this point in the history
Revert eslint changes when facebook/create-react-app#6513
will be merged

Revert to react-scripts when facebook/create-react-app#5829
will be merged
  • Loading branch information
iamandrewluca committed Mar 8, 2019
1 parent 8281cc7 commit 36ba0dc
Show file tree
Hide file tree
Showing 12 changed files with 750 additions and 212 deletions.
34 changes: 34 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"extends": "react-app",
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"warnOnUnsupportedTypeScriptVersion": true
},
"plugins": ["@typescript-eslint"],
"rules": {
"camelcase": "off",
"indent": "off",
"no-array-constructor": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-angle-bracket-type-assertion": "warn",
"@typescript-eslint/no-array-constructor": "warn",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "none",
"ignoreRestSiblings": true
}
]
}
}
]
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "all",
"jsxBracketSameLine": true,
"endOfLine": "lf"
}
12 changes: 12 additions & 0 deletions config/webpack.config.override.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function(config) {
// load eslint from file
// revert on https://github.com/facebook/create-react-app/pull/6513
const eslintRule = config.module.rules[1]
eslintRule.test = /\.(js|mjs|jsx|ts|tsx)$/
const eslintOptions = eslintRule.use[0].options
delete eslintOptions.baseConfig
delete eslintOptions.ignore
delete eslintOptions.useEslintrc

return config
}
39 changes: 26 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "24.0.10",
"@types/node": "11.10.5",
"@types/react": "16.8.7",
"@types/react-dom": "16.8.2",
"@types/storybook__addon-actions": "^3.4.2",
"@types/storybook__addon-links": "^3.3.4",
"@types/storybook__react": "^4.0.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "2.1.8",
"typescript": "3.3.3333"
"@winify/react-scripts": "2.1.5"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -23,9 +15,6 @@
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
Expand All @@ -38,6 +27,30 @@
"@storybook/addon-links": "^5.0.1",
"@storybook/addons": "^5.0.1",
"@storybook/react": "^5.0.1",
"babel-loader": "^8.0.5"
"@types/jest": "24.0.10",
"@types/node": "11.10.5",
"@types/react": "16.8.7",
"@types/react-dom": "16.8.2",
"@types/storybook__addon-actions": "^3.4.2",
"@types/storybook__addon-links": "^3.3.4",
"@types/storybook__react": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2",
"babel-loader": "^8.0.5",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
"prettier": "^1.16.4",
"typescript": "3.3.3333"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --write",
"git add"
]
}
}
14 changes: 7 additions & 7 deletions src/app.component.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './app.component';
import React from 'react'
import ReactDOM from 'react-dom'
import App from './app.component'

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
const div = document.createElement('div')
ReactDOM.render(<App />, div)
ReactDOM.unmountComponentAtNode(div)
})
13 changes: 6 additions & 7 deletions src/app.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './app.component.css';
import React, { Component } from 'react'
import logo from './logo.svg'
import './app.component.css'

class App extends Component {
render() {
Expand All @@ -15,14 +15,13 @@ class App extends Component {
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
rel="noopener noreferrer">
Learn React
</a>
</header>
</div>
);
)
}
}

export default App;
export default App
14 changes: 7 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './app.component';
import * as serviceWorker from './serviceWorker';
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './app.component'
import * as serviceWorker from './serviceWorker'

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(<App />, document.getElementById('root'))

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
serviceWorker.unregister()
2 changes: 1 addition & 1 deletion src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/// <reference types="react-scripts" />
/// <reference types="@winify/react-scripts" />
74 changes: 37 additions & 37 deletions src/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,49 @@ const isLocalhost = Boolean(
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
),
)

type Config = {
onSuccess?: (registration: ServiceWorkerRegistration) => void;
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};
onSuccess?: (registration: ServiceWorkerRegistration) => void
onUpdate?: (registration: ServiceWorkerRegistration) => void
}

export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
(process as { env: { [key: string]: string } }).env.PUBLIC_URL,
window.location.href
);
window.location.href,
)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
return
}

window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
checkValidServiceWorker(swUrl, config)

// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
'worker. To learn more, visit https://bit.ly/CRA-PWA',
)
})
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
registerValidSW(swUrl, config)
}
});
})
}
}

Expand All @@ -67,9 +67,9 @@ function registerValidSW(swUrl: string, config?: Config) {
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
const installingWorker = registration.installing
if (installingWorker == null) {
return;
return
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
Expand All @@ -79,65 +79,65 @@ function registerValidSW(swUrl: string, config?: Config) {
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
)

// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
config.onUpdate(registration)
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log('Content is cached for offline use.')

// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
config.onSuccess(registration)
}
}
}
};
};
}
}
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
console.error('Error during service worker registration:', error)
})
}

function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
const contentType = response.headers.get('content-type')
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
window.location.reload()
})
})
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
registerValidSW(swUrl, config)
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
'No internet connection found. App is running in offline mode.',
)
})
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
registration.unregister()
})
}
}
19 changes: 0 additions & 19 deletions src/stories/index.js

This file was deleted.

23 changes: 23 additions & 0 deletions src/stories/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'

import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import { linkTo } from '@storybook/addon-links'

import { Button, Welcome } from '@storybook/react/demo'

storiesOf('Welcome', module).add('to Storybook', () => (
<Welcome showApp={linkTo('Button')} />
))

storiesOf('Button', module)
.add('with text', () => (
<Button onClick={action('clicked')}>Hello Button</Button>
))
.add('with some emoji', () => (
<Button onClick={action('clicked')}>
<span role="img" aria-label="so cool">
😀 😎 👍 💯
</span>
</Button>
))
Loading

0 comments on commit 36ba0dc

Please sign in to comment.