Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
feat: integrate with eslint-mdx to lint .mdx with ESLint (#1195)
Browse files Browse the repository at this point in the history
* feat: add eslint-mdx support to lint mdx files

* chore: lint examples
  • Loading branch information
JounQin authored and rakannimer committed Oct 24, 2019
1 parent b0caf5e commit 4805737
Show file tree
Hide file tree
Showing 31 changed files with 600 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/**/dist/**
dist
node_modules
4 changes: 2 additions & 2 deletions core/docz-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "yarn cross-env NODE_ENV=production rollup -c",
"dev": "yarn cross-env NODE_ENV=development yarn build -w",
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext .ts,.tsx",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"precommit": "lint-staged",
"prepare": "yarn build",
"test": "yarn jest"
Expand Down Expand Up @@ -61,7 +61,7 @@
"cpy": "^7.3.0",
"cross-env": "^5.2.1",
"docz-rollup": "2.0.0-rc.54",
"eslint": "^6.3.0",
"eslint": "^6.5.1",
"eslint-config-docz-ts": "^2.0.0-rc.1",
"jest": "^24.9.0"
}
Expand Down
4 changes: 3 additions & 1 deletion core/docz-core/src/bundler/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const server = (args: Args) => async () => {
const doczrcFilepath = await findUp(finds('docz'))
const machine = devServerMachine.withContext({ args, doczrcFilepath })
const service = interpret(machine).onTransition(state => {
args.debug && console.log(state.value)
if (args.debug) {
console.log(state.value)
}
})

return {
Expand Down
4 changes: 3 additions & 1 deletion core/docz-core/src/lib/DataServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export class DataServer {

public close(): void {
for (const state of this.states) {
isFunction(state.close) && state.close()
if (isFunction(state.close)) {
state.close()
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/docz-core/src/lib/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export class Plugin<C = any> implements PluginFactory {
if (plugins && plugins.length > 0) {
for (const plugin of plugins) {
const fn = get<Plugin, any>(method, plugin)
isFunction(fn) && fn(...args)
if (isFunction(fn)) {
fn(...args)
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions core/docz-core/src/utils/docgen/externalProptypesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,11 @@ function filterSpecifiers(specifiers: any, computedPropNames: any) {
if (HOP.call(computedPropNames, cp)) {
for (const sp in specifiers) {
if (HOP.call(specifiers, sp) && specifiers[sp].indexOf(cp) > -1) {
filteredSpecifiers[sp]
? filteredSpecifiers[sp].push(cp)
: (filteredSpecifiers[sp] = [cp])
if (filteredSpecifiers[sp]) {
filteredSpecifiers[sp].push(cp)
} else {
filteredSpecifiers[sp] = [cp]
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/docz-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dev": "cross-env NODE_ENV=development yarn build -w",
"build": "trash lib && cross-env NODE_ENV=production rollup -c",
"fix": "yarn lint --fix",
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint . --ext mdx,ts,tsx",
"precommit": "lint-staged"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion core/docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev": "cross-env NODE_ENV=development yarn build -w",
"build": "cross-env NODE_ENV=production rollup -c",
"fix": "yarn lint --fix",
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint . --ext mdx,ts,tsx",
"precommit": "lint-staged"
},
"dependencies": {
Expand Down Expand Up @@ -53,6 +53,7 @@
"@types/react": "^16.8.23",
"@types/react-dom": "^16.8.4",
"docz-rollup": "2.0.0-rc.54",
"eslint": "^6.5.1",
"eslint-config-docz-ts": "^2.0.0-rc.1"
}
}
2 changes: 1 addition & 1 deletion core/gatsby-theme-docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"devDependencies": {
"babel-eslint": "10.0.2",
"eslint": "^6.0.1",
"eslint": "^6.5.1",
"eslint-config-docz-js": "^2.0.0-rc.1"
},
"peerDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions core/gatsby-theme-docz/src/wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as React from 'react'

const Wrapper = ({ children }) => (
<React.Fragment>{children}</React.Fragment>
)
const Wrapper = ({ children }) => <React.Fragment>{children}</React.Fragment>
export default Wrapper
2 changes: 1 addition & 1 deletion core/rehype-docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dev": "cross-env NODE_ENV=development yarn build -w",
"build": "cross-env NODE_ENV=production rollup -c",
"fix": "yarn lint --fix",
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint . --ext mdx,ts,tsx",
"precommit": "lint-staged",
"test": "jest"
},
Expand Down
2 changes: 1 addition & 1 deletion core/remark-docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dev": "cross-env NODE_ENV=development yarn build -w",
"build": "cross-env NODE_ENV=production rollup -c",
"fix": "yarn lint --fix",
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint . --ext mdx,ts,tsx",
"precommit": "lint-staged",
"test": "jest"
},
Expand Down
9 changes: 9 additions & 0 deletions examples/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["docz-js"],
"overrides": [
{
"files": "*.{ts,tsx}",
"extends": ["docz-ts"]
}
]
}
3 changes: 0 additions & 3 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
Expand Down
10 changes: 5 additions & 5 deletions examples/create-react-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import React from 'react'
import logo from './logo.svg'
import './App.css'

function App() {
return (
Expand All @@ -20,7 +20,7 @@ function App() {
</a>
</header>
</div>
);
)
}

export default App;
export default App
14 changes: 7 additions & 7 deletions examples/create-react-app/src/App.test.js
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';
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

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)
})
14 changes: 7 additions & 7 deletions examples/create-react-app/src/index.js
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';
import * as serviceWorker from './serviceWorker';
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
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()
56 changes: 28 additions & 28 deletions examples/create-react-app/src/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ const isLocalhost = Boolean(
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
)

export function register(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.env.PUBLIC_URL, window.location.href);
const publicUrl = new URL(process.env.PUBLIC_URL, 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'
);
});
)
})
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
registerValidSW(swUrl, config)
}
});
})
}
}

Expand All @@ -59,9 +59,9 @@ function registerValidSW(swUrl, 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 @@ -72,64 +72,64 @@ function registerValidSW(swUrl, config) {
console.log(
'New content is available and will be used when all ' +
'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, 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.'
);
});
)
})
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
registration.unregister()
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const kinds = {

type Kind = keyof typeof kinds

type Props = { kind: Kind }
interface Props {
kind: Kind
}

const AlertStyled: React.FC<Props> = ({ children, kind, ...rest }) => (
<div
Expand Down
1 change: 0 additions & 1 deletion examples/react-native/src/components/Alert.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { Alert, Text } from './Alert'
<Playground>
{() => {
const message = 'Hello world'

return (
<Alert><Text>{message}</Text></Alert>
)
Expand Down
9 changes: 5 additions & 4 deletions examples/react-router/src/gatsby-theme-docz/wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { MemoryRouter } from "react-router-dom";
import React from 'react'
import { MemoryRouter } from 'react-router-dom'

// eslint-disable-next-line react/display-name
export default ({ children }) => {
return <MemoryRouter>{children}</MemoryRouter>;
};
return <MemoryRouter>{children}</MemoryRouter>
}
4 changes: 2 additions & 2 deletions examples/typescript/src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { SFC } from 'react'

export type Kind = 'info' | 'positive' | 'negative' | 'warning'
Expand All @@ -19,6 +20,5 @@ export interface AlertProps {
}

export const Alert: SFC<AlertProps> = ({ kind, ...props }) => (
//@ts-ignore
<div className="alert"> </div>
<div className="alert"></div>
)
Loading

0 comments on commit 4805737

Please sign in to comment.