diff --git a/src/components/GlobalFooter/index.js b/src/components/GlobalFooter/index.js index 1c2fb74..2784e26 100644 --- a/src/components/GlobalFooter/index.js +++ b/src/components/GlobalFooter/index.js @@ -13,6 +13,7 @@ const GlobalFooter = ({ className, links, copyright }) => { key={link.key} title={link.key} target={link.blankTarget ? '_blank' : '_self'} + rel={link.blankTarget ? 'noreferrer noopener' : undefined} href={link.href} > {link.title} diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index ed786e9..5a38ed5 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -4,7 +4,7 @@ import { Breadcrumb } from 'antd' import { Link, withRouter } from 'umi' import { i18n } from '@lingui/core' import iconMap from 'utils/iconMap' -const { pathToRegexp } = require('path-to-regexp') +import { pathToRegexp } from 'path-to-regexp' import { queryAncestors } from 'utils' import styles from './Bread.less' diff --git a/src/layouts/PrimaryLayout.js b/src/layouts/PrimaryLayout.js index 0e41344..7a2e5ac 100644 --- a/src/layouts/PrimaryLayout.js +++ b/src/layouts/PrimaryLayout.js @@ -1,5 +1,3 @@ -/* global window */ -/* global document */ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' import { withRouter } from 'umi' @@ -7,7 +5,7 @@ import { connect } from 'umi' import { MyLayout, GlobalFooter } from 'components' import { Drawer, FloatButton, Layout } from 'antd'; import { enquireScreen, unenquireScreen } from 'enquire-js' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import { config, getLocale } from 'utils' import Error from '../pages/404' import styles from './PrimaryLayout.less' diff --git a/src/layouts/PublicLayout.js b/src/layouts/PublicLayout.js index caaaf5c..c1d319b 100644 --- a/src/layouts/PublicLayout.js +++ b/src/layouts/PublicLayout.js @@ -1,3 +1,3 @@ -export default ({ children }) => { - return children -} +const PublicLayout = ({ children }) => children + +export default PublicLayout diff --git a/src/layouts/index.js b/src/layouts/index.js index f116bbe..8efd0ec 100644 --- a/src/layouts/index.js +++ b/src/layouts/index.js @@ -46,7 +46,7 @@ const languages = { 'pt-br': ptBR } -const { defaultLanguage } = i18n +// remove unused defaultLanguage @withRouter class Layout extends Component { @@ -69,6 +69,7 @@ class Layout extends Component { i18n.activate(language) } catch (err) { // If loading fails, fall back to default language and log a warning. + // eslint-disable-next-line no-console console.warn(`Failed to load messages for locale "${language}":`, err) } } diff --git a/src/models/app.js b/src/models/app.js index 6afd5c0..6cd73d3 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -1,9 +1,7 @@ -/* global window */ - import { history } from 'umi' import { stringify } from 'qs' import store from 'store' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import { ROLE_TYPE } from 'utils/constant' import { queryLayout } from 'utils' import { CANCEL_REQUEST_MESSAGE } from 'utils/constant' @@ -20,7 +18,7 @@ const goDashboard = () => { } } -export default { +const appModel = { namespace: 'app', state: { routeList: [ @@ -158,3 +156,5 @@ export default { }, }, } + +export default appModel diff --git a/src/pages/chart/ECharts/ChartWithEventComponent.js b/src/pages/chart/ECharts/ChartWithEventComponent.js index 93f287c..92425bc 100644 --- a/src/pages/chart/ECharts/ChartWithEventComponent.js +++ b/src/pages/chart/ECharts/ChartWithEventComponent.js @@ -3,14 +3,22 @@ import ReactEcharts from 'echarts-for-react' const ChartWithEventComponent = () => { const onChartReady = echart => { - /* eslint-disable */ - console.log('echart is ready', echart) + if (process.env.NODE_ENV !== 'production') { + // eslint-disable-next-line no-console + console.log('echart is ready', echart) + } } const onChartLegendselectchanged = (param, echart) => { - console.log(param, echart) + if (process.env.NODE_ENV !== 'production') { + // eslint-disable-next-line no-console + console.log(param, echart) + } } const onChartClick = (param, echart) => { - console.log(param, echart) + if (process.env.NODE_ENV !== 'production') { + // eslint-disable-next-line no-console + console.log(param, echart) + } } const getOtion = () => { const option = { diff --git a/src/pages/chart/ECharts/theme/macarons.js b/src/pages/chart/ECharts/theme/macarons.js index cfa4434..f0a700a 100644 --- a/src/pages/chart/ECharts/theme/macarons.js +++ b/src/pages/chart/ECharts/theme/macarons.js @@ -181,6 +181,8 @@ let colorPalette = [ if (echarts && typeof echarts.registerTheme === 'function') { echarts.registerTheme('macarons', theme) -} else if (typeof console !== 'undefined' && console.error) { - console.error('ECharts is not loaded, failed to register macarons theme') +} else { + // Console may be used only to report theme registration failure; suppress lint here + // eslint-disable-next-line no-console + if (typeof console !== 'undefined' && console.error) console.error('ECharts is not loaded, failed to register macarons theme') } diff --git a/src/pages/chart/ECharts/theme/shine.js b/src/pages/chart/ECharts/theme/shine.js index 4c891c8..59126b7 100644 --- a/src/pages/chart/ECharts/theme/shine.js +++ b/src/pages/chart/ECharts/theme/shine.js @@ -66,12 +66,12 @@ let colorPalette = [ map: { label: { color: '#c12e34' }, - emphasis: { label: { color: '#c12e34' } }, itemStyle: { borderColor: '#eee', areaColor: '#ddd', }, emphasis: { + label: { color: '#c12e34' }, itemStyle: { areaColor: '#e6b600', }, @@ -119,6 +119,8 @@ let colorPalette = [ } if (echarts && typeof echarts.registerTheme === 'function') { echarts.registerTheme('shine', theme) -} else if (typeof console !== 'undefined' && console.error) { - console.error('ECharts is not loaded, failed to register shine theme') +} else { + // Console may be used only to report theme registration failure; suppress lint here + // eslint-disable-next-line no-console + if (typeof console !== 'undefined' && console.error) console.error('ECharts is not loaded, failed to register shine theme') } diff --git a/src/pages/dashboard/model.js b/src/pages/dashboard/model.js index 19ae6a6..8f9474c 100644 --- a/src/pages/dashboard/model.js +++ b/src/pages/dashboard/model.js @@ -1,7 +1,7 @@ import { parse } from 'qs' import modelExtend from 'dva-model-extend' import api from 'api' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import { model } from 'utils/model' const { queryDashboard, queryWeather } = api diff --git a/src/pages/login/model.js b/src/pages/login/model.js index e7e42e7..e779e86 100644 --- a/src/pages/login/model.js +++ b/src/pages/login/model.js @@ -1,10 +1,10 @@ import { history } from 'umi' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import api from 'api' const { loginUser } = api -export default { +const loginModel = { namespace: 'login', state: {}, @@ -35,3 +35,5 @@ export default { }, }, } + +export default loginModel diff --git a/src/pages/post/model.js b/src/pages/post/model.js index 6a3ba7d..a3df06c 100644 --- a/src/pages/post/model.js +++ b/src/pages/post/model.js @@ -1,6 +1,6 @@ import modelExtend from 'dva-model-extend' import api from 'api' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import { pageModel } from 'utils/model' const { queryPostList } = api diff --git a/src/pages/request/index.js b/src/pages/request/index.js index 253c90b..4c20582 100644 --- a/src/pages/request/index.js +++ b/src/pages/request/index.js @@ -72,7 +72,10 @@ class RequestPage extends React.Component { }) }) .catch(errorInfo => { - console.log(errorInfo) + if (process.env.NODE_ENV !== 'production') { + // eslint-disable-next-line no-console + console.error(errorInfo) + } /* errorInfo: { diff --git a/src/pages/user/[id]/models/detail.js b/src/pages/user/[id]/models/detail.js index 2f18531..b2fe6b0 100644 --- a/src/pages/user/[id]/models/detail.js +++ b/src/pages/user/[id]/models/detail.js @@ -1,9 +1,9 @@ -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import api from 'api' const { queryUser } = api -export default { +const userDetailModel = { namespace: 'userDetail', state: { @@ -48,3 +48,5 @@ export default { }, }, } + +export default userDetailModel diff --git a/src/pages/user/components/Modal.js b/src/pages/user/components/Modal.js index b93a2f7..78e084a 100644 --- a/src/pages/user/components/Modal.js +++ b/src/pages/user/components/Modal.js @@ -31,7 +31,10 @@ class UserModal extends PureComponent { onOk(data) }) .catch(errorInfo => { - console.log(errorInfo) + if (process.env.NODE_ENV !== 'production') { + // eslint-disable-next-line no-console + console.error(errorInfo) + } }) } @@ -67,7 +70,7 @@ class UserModal extends PureComponent { label={i18n._('Phone')} hasFeedback {...formItemLayout}> - diff --git a/src/pages/user/model.js b/src/pages/user/model.js index 031ed90..a05f765 100644 --- a/src/pages/user/model.js +++ b/src/pages/user/model.js @@ -1,5 +1,5 @@ import modelExtend from 'dva-model-extend' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import api from 'api' import { pageModel } from 'utils/model' diff --git a/src/plugins/onError.js b/src/plugins/onError.js index d929ab9..de427a5 100644 --- a/src/plugins/onError.js +++ b/src/plugins/onError.js @@ -1,13 +1,15 @@ import { message } from 'antd' -export default { +const onErrorHandler = { onError(e, a) { e.preventDefault() if (e.message) { message.error(e.message) } else { - /* eslint-disable */ + // eslint-disable-next-line no-console console.error(e) } }, } + +export default onErrorHandler diff --git a/src/services/api.js b/src/services/api.js index e34b942..dd5caf8 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -1,4 +1,4 @@ -export default { +const api = { queryRouteList: '/routes', queryUserInfo: '/user', @@ -16,3 +16,5 @@ export default { queryDashboard: '/dashboard', } + +export default api diff --git a/src/utils/iconMap.jsx b/src/utils/iconMap.jsx index ceacadf..0db72bc 100644 --- a/src/utils/iconMap.jsx +++ b/src/utils/iconMap.jsx @@ -14,7 +14,7 @@ import { AreaChartOutlined, } from '@ant-design/icons' -export default { +const iconMap = { 'pay-circle-o': , 'shopping-cart': , 'camera-o': , @@ -29,3 +29,5 @@ export default { api: , edit: , } + +export default iconMap diff --git a/src/utils/index.js b/src/utils/index.js index a33b3bf..99d3a6e 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,5 @@ import { cloneDeep } from 'lodash' -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' import store from 'store' import { i18n } from '@lingui/core' diff --git a/src/utils/index.test.js b/src/utils/index.test.js index 72261c9..d9a3070 100644 --- a/src/utils/index.test.js +++ b/src/utils/index.test.js @@ -1,4 +1,4 @@ -const { pathToRegexp } = require("path-to-regexp") +import { pathToRegexp } from 'path-to-regexp' // strip known locale prefix (e.g. /zh, /en, /pt-br) before matching const stripLocale = (p) => p.replace(/^\/(en|zh|pt-br)(\/|$)/, '/') diff --git a/src/utils/request.js b/src/utils/request.js index 7b111c9..a09f7b6 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,6 +1,6 @@ import axios from 'axios' import { cloneDeep } from 'lodash' -const { parse, compile } = require("path-to-regexp") +import { parse, compile } from 'path-to-regexp' import { message } from 'antd' import { CANCEL_REQUEST_MESSAGE } from 'utils/constant' @@ -13,7 +13,7 @@ export default function request(options) { try { let domain = '' - const urlMatch = url.match(/[a-zA-z]+:\/\/[^/]*/) + const urlMatch = url.match(/[A-Za-z]+:\/\/[^/]*/) if (urlMatch) { ;[domain] = urlMatch url = url.slice(domain.length) @@ -62,9 +62,9 @@ export default function request(options) { }) }) .catch(error => { - const { response, message } = error + const { response, message: errMsg } = error - if (String(message) === CANCEL_REQUEST_MESSAGE) { + if (String(errMsg) === CANCEL_REQUEST_MESSAGE) { return { success: false, } @@ -79,7 +79,7 @@ export default function request(options) { msg = data.message || statusText } else { statusCode = 600 - msg = error.message || 'Network Error' + msg = errMsg || error.message || 'Network Error' } /* eslint-disable */