Skip to content

Commit

Permalink
Update & ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Oct 17, 2020
1 parent 70a4c4c commit ab25964
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 178 deletions.
17 changes: 12 additions & 5 deletions .eslintrc.json
Expand Up @@ -4,7 +4,7 @@
"browser": true,
"es6": true
},
"parser": "typescript-eslint-parser",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
Expand All @@ -14,12 +14,19 @@
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".jsx", ".tsx"] }],
"import/no-unresolved": 0,
"import/extensions": 0,
"import/extensions": 0,
"import/no-extraneous-dependencies": 0,
"no-continue": 0,
"no-dupe-args": 0,
"no-undef": 0,
"no-unused-vars": 0,
"no-undef": 0,
"no-redeclare": 0,
"no-shadow": 0,
"no-use-before-define": 0,
"no-unused-vars": 0,
"no-useless-constructor": 0,
"no-empty-function": 0,
"react/prop-types": 0,
"react/jsx-props-no-spreading": 0,
"react/sort-comp": [2, {
"order": [
"displayName",
Expand All @@ -42,6 +49,6 @@
"/^render.+$/",
"render"
]
}]
}]
}
}
48 changes: 24 additions & 24 deletions package.json
Expand Up @@ -14,58 +14,58 @@
"test": "eslint *.js src/**/*.ts*"
},
"dependencies": {
"@material-ui/core": "^3.9.3",
"katex": "^0.10.2",
"plotly.js": "^1.56.0",
"react": "^16.13.1",
"@material-ui/core": "^4.11.0",
"katex": "^0.12.0",
"plotly.js": "^1.57.0",
"react": "^16.14.0",
"react-did-catch": "^0.2.1",
"react-dom": "^16.13.1",
"react-dom": "^16.14.0",
"react-katex": "^2.0.2",
"react-plotly.js": "^2.5.0",
"react-redux": "^5.1.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"redux": "^4.0.4",
"react-redux": "^7.2.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"typed-jsx": "^0.1.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"@types/autoprefixer": "^9.7.2",
"@types/detect-browser": "^4.0.0",
"@types/glob": "^7.1.1",
"@types/markdown-it": "^10.0.2",
"@types/react": "^16.9.50",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"@types/react-plotly.js": "^2.2.4",
"@types/react-router-dom": "^5.1.5",
"@types/react-router-dom": "^5.1.6",
"@types/rollup-plugin-json": "^3.0.2",
"@types/rollup-plugin-node-builtins": "^2.1.1",
"@types/rollup-plugin-postcss": "^2.0.1",
"@typescript-eslint/parser": "^4.4.1",
"@wessberg/rollup-plugin-ts": "^1.3.5",
"autoprefixer": "^9.8.6",
"eslint": "^7.10.0",
"autoprefixer": "^10.0.1",
"eslint": "^7.11.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-flying-sheep": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-no-foreach": "^1.0.0",
"eslint-plugin-react": "^7.21.3",
"markdown-it": "^11.0.1",
"matched": "^4.0.0",
"eslint-plugin-react": "^7.21.4",
"markdown-it": "^12.0.0",
"matched": "^5.0.0",
"resolve": "^1.17.0",
"restructured": "^0.0.11",
"rollup": "^2.28.2",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"rollup": "^2.32.0",
"rollup-plugin-analyzer": "^3.3.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-postcss-modules": "^2.0.2",
"rollup-plugin-serve": "^1.0.4",
"rollup-watch": "^4.3.1",
"ts-node": "^9.0.0",
"tslib": "^2.0.1",
"typescript": "^4.0.3",
"typescript-eslint-parser": "^22.0.0"
"tslib": "^2.0.3",
"typescript": "^4.0.3"
}
}
3 changes: 1 addition & 2 deletions rollup.config.ts
Expand Up @@ -16,7 +16,6 @@ import * as autoprefixer from 'autoprefixer'

import renderdoc from './src/build-tools/rollup-plugin-renderdoc'


const NODE_ENV = process.env.NODE_ENV || 'development'
const isDev = NODE_ENV === 'development'

Expand All @@ -41,7 +40,7 @@ export default {
plugins: [
analyze({
writeTo(formatted) {
fs.writeFile('dist/bundle.log', formatted, e => (e !== null ? console.error(e) : {}))
fs.writeFile('dist/bundle.log', formatted, (e) => (e !== null ? console.error(e) : {}))
},
}),
postcss({
Expand Down
4 changes: 2 additions & 2 deletions src/build-tools/rollup-plugin-renderdoc.ts
Expand Up @@ -31,7 +31,7 @@ export default function renderdoc(config: Partial<Config> = {}) {
const converters = config.converters ?? DEFAULT_CONVERTERS
const include: string[] = typeof config.include === 'string' ? [config.include] : config.include || []
const exclude: string[] = typeof config.exclude === 'string' ? [config.exclude] : config.exclude || []
const patterns = include.concat(exclude.map(pattern => `!${pattern}`))
const patterns = include.concat(exclude.map((pattern) => `!${pattern}`))

async function doGlob(id: string): Promise<string[]> {
const stats = await fs.stat(id)
Expand All @@ -58,7 +58,7 @@ export default function renderdoc(config: Partial<Config> = {}) {
const convert = converters[path.extname(p)]
return convert(content)
}))
const map = zipObject(paths.map(p => path.basename(p)), contents)
const map = zipObject(paths.map((p) => path.basename(p)), contents)
return `export default ${JSON.stringify(map)}`
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Plotly.tsx
Expand Up @@ -32,7 +32,7 @@ export default class Plotly extends React.Component<PlotlyProps, Partial<Figure>
throw new Error(r.statusText)
}).then(({ layout, data }) => {
this.setState({ layout, data })
}).catch(e => console.error(e))
}).catch((e) => console.error(e))
this.handleOnClickLink = this.handleOnClickLink.bind(this)
}

Expand Down
108 changes: 8 additions & 100 deletions src/components/markup/Markup.tsx
@@ -1,14 +1,8 @@
import * as React from 'react'

import { Typography } from '@material-ui/core'
import { ThemeStyle } from '@material-ui/core/styles/createTypography'
import { InlineMath } from 'react-katex'

import ASTErrorMessage, { ASTErrorMessageProps } from './ASTErrorMessage'
import { Document, Node, Elem, Type, Bullet } from '../../markup/MarkupDocument'
import ASTError from '../../markup/AstError'
import Plotly from '../Plotly'

import { Document, Node } from '../../markup/MarkupDocument'
import { ASTErrorMessageProps } from './ASTErrorMessage'
import MarkupNodeComponent from './MarkupNodeComponent'

export interface MarkupProps {
doc: Document
Expand All @@ -23,109 +17,23 @@ export default class Markup extends React.Component {
const { doc } = props
this.title = doc.title
this.children = doc.children // DEBUG
this.state = { errorMessage: null }
}

static getDerivedStateFromError(error: Error) {
return { errorMessage: error.message }
}

render(): React.ReactElement<any> {
const nodes = convertChildren(this, 0)
const nodes = this.children.map((e) => <MarkupNodeComponent node={e} level={0}/>)
const body = React.Children.toArray(nodes)
if (process.env.NODE_ENV === 'development') {
return (
<article>
{nodes}
<pre>{JSON.stringify(nodes, undefined, '\t')}</pre>
{body}
<pre>{JSON.stringify(this.children, undefined, '\t')}</pre>
</article>
)
}
return <article>{nodes}</article>
}
}

export interface MarkupElementProps {
node: Node
level: number
}

export interface MarkupElementState {
errorMessage: string | null
}

function convertChildren(elem: Elem | Document | Markup, level: number): React.ReactNode[] {
const children = elem.children.map(e => <MarkupNodeComponent node={e} level={level}/>)
return React.Children.toArray(children)
}

export class MarkupNodeComponent extends React.Component
<MarkupElementProps, MarkupElementState> {
constructor(props: MarkupElementProps) {
super(props)
this.state = { errorMessage: null }
}

static getDerivedStateFromError(error: Error) {
return { errorMessage: error.message }
}

render(): React.ReactNode {
const { node, level } = this.props
const { errorMessage } = this.state
if (errorMessage !== null) {
return <ASTErrorMessage node={node}>{errorMessage}</ASTErrorMessage>
}
if (typeof node === 'string') return `${node}\n`
switch (node.type) {
case Type.LineBreak:
return <br/>
case Type.Link: {
if ('name' in node.ref) throw new ASTError(`Unresolved reference ${node.ref.name}`, node)
return <a href={node.ref.href}>{convertChildren(node, level)}</a>
}
case Type.Section:
return <section>{convertChildren(node, level + 1)}</section>
case Type.Title: {
if (level < 1) throw new ASTError(`Header with level ${level} < 1`, node)
const hLevel = Math.min(level, 6)
return <Typography variant={`h${hLevel}` as ThemeStyle}>{convertChildren(node, level)}</Typography>
}
case Type.Paragraph:
return <Typography paragraph>{convertChildren(node, level)}</Typography>
case Type.Code:
return <code>{convertChildren(node, level)}</code>
case Type.Emph:
return <em>{convertChildren(node, level)}</em>
case Type.Strong:
return <strong>{convertChildren(node, level)}</strong>
case Type.BulletList: {
const listStyleType = node.bullet == Bullet.text ? node.text : node.bullet
return <ul style={{listStyleType}}>{convertChildren(node, level)}</ul>
}
case Type.EnumList:
return <ul style={{listStyleType: node.enumeration}}>{convertChildren(node, level)}</ul>
case Type.ListItem:
return <li>{convertChildren(node, level)}</li>
case Type.InlineMath:
return <InlineMath math={node.math}/>
case Type.CodeBlock:
return <pre><code>{convertChildren(node, level)}</code></pre>
case Type.Table:
return (
<figure>
<table>{convertChildren(node, level)}</table>
{node.caption && <figcaption>{node.caption}</figcaption>}
</figure>
)
case Type.Row:
return <tr>{convertChildren(node, level)}</tr>
case Type.Cell:
return <td>{convertChildren(node, level)}</td>
// custom
case Type.Plotly: {
const props = Object.assign({type: undefined}, node)
return <Plotly {...props}/>
}
}
return <article>{body}</article>
}
}

0 comments on commit ab25964

Please sign in to comment.