diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index fc5072ef7c..31e4a1db66 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -6,59 +6,52 @@ "eslint:recommended" ], "rules": { - "indent": [ - "warn", - 2, - { "SwitchCase": 1 } - ], - "default-case": "off", - "linebreak-style": [ - "warn", - "unix" - ], - "quotes": [ - "warn", - "single" - ], - "semi": [ - "warn", - "always" - ], - + "jsx-a11y/anchor-is-valid": "off", + "react-hooks/exhaustive-deps": "off", + "no-loop-func": "off", "eqeqeq": "off", + "default-case": "off", + "jsx-a11y/anchor-has-content": "off", + "no-mixed-operators": "off", + "no-useless-concat": "off", "no-useless-constructor": "off", - "no-restricted-globals": "off", "no-unused-expressions": "off", - "no-case-declarations": "warn", - "no-cond-assign": "warn", - "no-redeclare": "warn", + "no-prototype-builtins": "off", + "no-restricted-globals": "off", + "brace-style": "off", + "no-console": "off", + "no-cond-assign": "off", + "no-var": "off", + "no-case-declarations": "off", + "no-redeclare": "off", + "indent": ["warn", 2, { + "SwitchCase": 1, + "ignoreComments": false + }], + "linebreak-style": ["warn", "unix"], + "quotes": ["warn", "single"], + "semi": ["warn", "always"], "no-unreachable": "warn", "no-class-assign": "warn", "no-unused-vars": "warn", + "no-useless-escape": "off", "no-irregular-whitespace": "warn", - "no-console": "warn", - "no-self-assign": ["error", {"props": false}], - "no-useless-escape": "warn", "no-trailing-spaces": "warn", - "react/jsx-indent": ["warn", 2], - "react/prop-types": "warn", - "react/display-name": "warn", - "no-mixed-operators": "off", - "no-useless-concat": "off", - "jsx-a11y/anchor-has-content": "off", - "jsx-a11y/href-no-hash": "off", - "jsx-a11y/anchor-is-valid": "off", - "space-before-blocks": ["warn", "always"], - "space-in-parens": ["warn", "never"], - "keyword-spacing": ["warn", { - "before": true, - "after": true, - "overrides": { - "if" : { - "after": true - } - } - }] + "eol-last": "error", + "space-before-function-paren": ["warn", {"named": "never"}], + "array-bracket-spacing": ["warn", "never"], + "object-curly-spacing": ["warn", "always"], + "spaced-comment": "warn", + "keyword-spacing": ["warn", {"before": true}], + "space-infix-ops": "error", + "key-spacing": ["error", { "beforeColon": false }], + "arrow-spacing": ["error", { "before": true, "after": true }], + "comma-spacing": ["error", { "before": false, "after": true }], + "no-duplicate-imports": "error", + "one-var": ["error", "never"], + "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }], + "no-multi-spaces": "error", + "react/jsx-closing-tag-location": "error" } } diff --git a/frontend/src/app.js b/frontend/src/app.js index 33cf841504..afad459feb 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -68,7 +68,7 @@ class App extends Component { onpopstate = (event) => { if (event.state && event.state.currentTab && event.state.pathPrefix) { let { currentTab, pathPrefix } = event.state; - this.setState({currentTab, pathPrefix}); + this.setState({ currentTab, pathPrefix }); } }; @@ -80,12 +80,12 @@ class App extends Component { } } - navigateClientUrlToLib = () =>{ + navigateClientUrlToLib = () => { if (window.location.hash && window.location.hash.indexOf('common/lib') != -1) { let splitUrlArray = window.location.hash.split('/'); let repoID = splitUrlArray[splitUrlArray.length - 2]; let url = siteRoot + 'library/' + repoID + '/'; - navigate(url, {repalce: true}); + navigate(url, { repalce: true }); } }; @@ -102,7 +102,7 @@ class App extends Component { let href = window.location.href.split('/'); currentTab = href[href.length - 2]; } - this.setState({currentTab: currentTab}); + this.setState({ currentTab: currentTab }); } onCloseSidePanel = () => { @@ -119,9 +119,9 @@ class App extends Component { onSearchedClick = (selectedItem) => { if (selectedItem.is_dir === true) { - this.setState({currentTab: '', pathPrefix: []}); + this.setState({ currentTab: '', pathPrefix: [] }); let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path; - navigate(url, {repalce: true}); + navigate(url, { repalce: true }); } else { let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path); let isWeChat = Utils.isWeChat(); @@ -135,7 +135,7 @@ class App extends Component { }; onGroupChanged = (groupID) => { - setTimeout(function() { + setTimeout(function () { let url; if (groupID) { url = siteRoot + 'group/' + groupID + '/'; @@ -157,7 +157,7 @@ class App extends Component { pathPrefix: pathPrefix }, () => { let { currentTab, pathPrefix } = this.state; - window.history.replaceState({currentTab: currentTab, pathPrefix: pathPrefix}, null); + window.history.replaceState({ currentTab: currentTab, pathPrefix: pathPrefix }, null); }); if (!Utils.isDesktop() && !this.state.isSidePanelClosed) { this.setState({ isSidePanelClosed: true }); diff --git a/frontend/src/components/btn-qr-code.js b/frontend/src/components/btn-qr-code.js index 9ea10ee93e..1c0c4d402e 100644 --- a/frontend/src/components/btn-qr-code.js +++ b/frontend/src/components/btn-qr-code.js @@ -17,7 +17,7 @@ class ButtonQR extends React.Component { isPopoverOpen: false }; - this.btnID = 'btn-' + Math.random().toString().substr(2,5); + this.btnID = 'btn-' + Math.random().toString().substr(2, 5); } togglePopover = () => { @@ -35,7 +35,7 @@ class ButtonQR extends React.Component { -

{gettext('Scan the QR code to view the shared content directly')}

+

{gettext('Scan the QR code to view the shared content directly')}

diff --git a/frontend/src/components/common/account.js b/frontend/src/components/common/account.js index 7afc6c23f3..13ab2f413a 100644 --- a/frontend/src/components/common/account.js +++ b/frontend/src/components/common/account.js @@ -94,7 +94,7 @@ class Account extends Component { }); this.isFirstMounted = false; } else { - this.setState({showInfo: !this.state.showInfo}); + this.setState({ showInfo: !this.state.showInfo }); } }; @@ -153,7 +153,7 @@ class Account extends Component { {this.renderAvatar()} -
+
@@ -165,7 +165,7 @@ class Account extends Component {

{gettext('Used:')}{' '}{this.state.quotaUsage} / {this.state.quotaTotal}

-
+
{gettext('Settings')} diff --git a/frontend/src/components/common/event-bus-type.js b/frontend/src/components/common/event-bus-type.js index 18960d493c..ff04767358 100644 --- a/frontend/src/components/common/event-bus-type.js +++ b/frontend/src/components/common/event-bus-type.js @@ -29,9 +29,9 @@ export const EVENT_BUS_TYPE = { // modify view MODIFY_FILTERS: 'modify_filters', - MODIFY_SORTS:'modify_sorts', - MODIFY_GROUPBYS:'modify_groupbys', - MODIFY_HIDDEN_COLUMNS:'modify_hidden_columns', + MODIFY_SORTS: 'modify_sorts', + MODIFY_GROUPBYS: 'modify_groupbys', + MODIFY_HIDDEN_COLUMNS: 'modify_hidden_columns', // change VIEW_CHANGED: 'view_changed', diff --git a/frontend/src/components/common/logout.js b/frontend/src/components/common/logout.js index fa197ab2f1..6f87ec608b 100644 --- a/frontend/src/components/common/logout.js +++ b/frontend/src/components/common/logout.js @@ -4,7 +4,7 @@ import { siteRoot, gettext } from '../../utils/constants'; export default function Logout() { return ( - + ); } diff --git a/frontend/src/components/common/notice-item.js b/frontend/src/components/common/notice-item.js index 58d5a3f74f..f1f94b53e2 100644 --- a/frontend/src/components/common/notice-item.js +++ b/frontend/src/components/common/notice-item.js @@ -25,7 +25,7 @@ const MSG_TYPE_REPO_SHARE_PERM_DELETE = 'repo_share_perm_delete'; class NoticeItem extends React.Component { - generatorNoticeInfo () { + generatorNoticeInfo() { let noticeItem = this.props.noticeItem; let noticeType = noticeItem.type; let detail = noticeItem.detail; @@ -48,7 +48,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{user_link}', userLink); notice = notice.replace('{group_link}', groupLink); - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_REPO_SHARE) { @@ -58,7 +58,7 @@ class NoticeItem extends React.Component { let shareFrom = detail.share_from_user_name; let repoName = detail.repo_name; - let repoUrl = siteRoot + 'library/' + detail.repo_id + '/' + repoName + '/'; + let repoUrl = siteRoot + 'library/' + detail.repo_id + '/' + repoName + '/'; let path = detail.path; let notice = ''; @@ -78,7 +78,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{tagA}', ``); notice = notice.replace('{/tagA}', ''); - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_REPO_SHARE_PERM_CHANGE) { @@ -87,7 +87,7 @@ class NoticeItem extends React.Component { let shareFrom = detail.share_from_user_name; let permission = detail.permission; let repoName = detail.repo_name; - let repoUrl = siteRoot + 'library/' + detail.repo_id + '/' + repoName + '/'; + let repoUrl = siteRoot + 'library/' + detail.repo_id + '/' + repoName + '/'; let path = detail.path; let notice = ''; // 1. handle translate @@ -107,7 +107,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{tagA}', ``); notice = notice.replace('{/tagA}', ''); - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_REPO_SHARE_PERM_DELETE) { @@ -128,7 +128,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{share_from}', shareFrom); notice = notice.replace('{repo_name}', repoName); notice = Utils.HTMLescape(notice); - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_REPO_SHARE_TO_GROUP) { @@ -147,9 +147,9 @@ class NoticeItem extends React.Component { let notice = ''; // 1. handle translate if (path === '/') { - notice = gettext('{share_from} has shared a library named {repo_link} to group {group_link}.'); + notice = gettext('{share_from} has shared a library named {repo_link} to group {group_link}.'); } else { - notice = gettext('{share_from} has shared a folder named {repo_link} to group {group_link}.'); + notice = gettext('{share_from} has shared a folder named {repo_link} to group {group_link}.'); } // 2. handle xss(cross-site scripting) @@ -163,7 +163,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{/tagA}', ''); notice = notice.replace('{tagB}', ``); notice = notice.replace('{/tagB}', ''); - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_REPO_TRANSFER) { @@ -185,7 +185,7 @@ class NoticeItem extends React.Component { // 3. add jump link notice = notice.replace('{tagA}', ``); notice = notice.replace('{/tagA}', ''); - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_FILE_UPLOADED) { @@ -218,7 +218,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{upload_file_link}', `${fileName}`); notice = Utils.HTMLescape(notice); } - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_FOLDER_UPLOADED) { @@ -251,7 +251,7 @@ class NoticeItem extends React.Component { notice = notice.replace('{upload_folder_link}', `${folderName}`); notice = Utils.HTMLescape(notice); } - return {avatar_url, notice}; + return { avatar_url, notice }; } if (noticeType === MSG_TYPE_REPO_MONITOR) { @@ -348,21 +348,21 @@ class NoticeItem extends React.Component { let notice = gettext('Your library {libraryName} has recently deleted a large number of files.'); notice = notice.replace('{libraryName}', repoLink); - return { avatar_url : null, notice }; + return { avatar_url: null, notice }; } if (noticeType === MSG_TYPE_SAML_SSO_FAILED) { const { error_msg } = detail; let notice = gettext(error_msg); - return { avatar_url : null, notice }; + return { avatar_url: null, notice }; } // if (noticeType === MSG_TYPE_GUEST_INVITATION_ACCEPTED) { // } - return {avatar_url : null, notice : null}; + return { avatar_url: null, notice: null }; } onNoticeItemClick = () => { @@ -387,7 +387,7 @@ class NoticeItem extends React.Component { -

+

{moment(noticeItem.time).fromNow()} @@ -398,7 +398,7 @@ class NoticeItem extends React.Component {
-

+

{moment(noticeItem.time).fromNow()}

diff --git a/frontend/src/components/common/notification.js b/frontend/src/components/common/notification.js index ed318ce0ce..fca7dd4520 100644 --- a/frontend/src/components/common/notification.js +++ b/frontend/src/components/common/notification.js @@ -20,7 +20,7 @@ class Notification extends React.Component { componentDidMount() { seafileAPI.getUnseenNotificationCount().then(res => { - this.setState({unseenCount: res.data.unseen_count}); + this.setState({ unseenCount: res.data.unseen_count }); }); } @@ -34,7 +34,7 @@ class Notification extends React.Component { }); } else { this.loadNotices(); - this.setState({showNotice: true}); + this.setState({ showNotice: true }); } }; @@ -43,7 +43,7 @@ class Notification extends React.Component { let perPage = 5; seafileAPI.listNotifications(page, perPage).then(res => { let noticeList = res.data.notification_list; - this.setState({noticeList: noticeList}); + this.setState({ noticeList: noticeList }); }); }; @@ -71,11 +71,11 @@ class Notification extends React.Component { onNotificationDialogToggle = () => { let newSearch = this.state.isShowNotificationDialog ? null : 'all'; Utils.updateSearchParameter('notifications', newSearch); - this.setState({isShowNotificationDialog: !this.state.isShowNotificationDialog}); + this.setState({ isShowNotificationDialog: !this.state.isShowNotificationDialog }); }; onNotificationListToggle = () => { - this.setState({showNotice: false}); + this.setState({ showNotice: false }); }; onMarkAllNotifications = () => { diff --git a/frontend/src/components/common/search-input.js b/frontend/src/components/common/search-input.js index 428089010f..ecf26b9fc6 100644 --- a/frontend/src/components/common/search-input.js +++ b/frontend/src/components/common/search-input.js @@ -40,7 +40,7 @@ class SearchInput extends Component { UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.value !== this.props.value) { - this.setState({searchValue: nextProps.value}); + this.setState({ searchValue: nextProps.value }); } } @@ -58,7 +58,7 @@ class SearchInput extends Component { this.timer && clearTimeout(this.timer); const { onChange, wait } = this.props; let text = e.target.value; - this.setState({searchValue: text || ''}, () => { + this.setState({ searchValue: text || '' }, () => { if (this.isInputtingChinese) return; this.timer = setTimeout(() => { onChange && onChange(this.state.searchValue.trim()); @@ -73,7 +73,7 @@ class SearchInput extends Component { clearSearch = () => { const { clearValue } = this.props; - this.setState({searchValue: ''}, () => { + this.setState({ searchValue: '' }, () => { clearValue && clearValue(); }); }; @@ -98,7 +98,7 @@ class SearchInput extends Component { if (!isClearable || !searchValue) return null; const { ClearIndicator } = components; if (React.isValidElement(ClearIndicator)) { - return React.cloneElement(ClearIndicator, {clearValue: this.clearSearch}); + return React.cloneElement(ClearIndicator, { clearValue: this.clearSearch }); } else if (this.isFunction(ClearIndicator)) { return ; } diff --git a/frontend/src/components/common/select/no-group-message.js b/frontend/src/components/common/select/no-group-message.js index 7a9abcc9fa..362f72a5e3 100644 --- a/frontend/src/components/common/select/no-group-message.js +++ b/frontend/src/components/common/select/no-group-message.js @@ -4,7 +4,7 @@ import { gettext } from '../../../utils/constants'; const NoGroupMessage = (props) => { return ( -
{gettext('Group not found')}
+
{gettext('Group not found')}
); }; diff --git a/frontend/src/components/common/select/seahub-select-style.js b/frontend/src/components/common/select/seahub-select-style.js index e86c7e6474..f7722afb4b 100644 --- a/frontend/src/components/common/select/seahub-select-style.js +++ b/frontend/src/components/common/select/seahub-select-style.js @@ -16,7 +16,7 @@ const MenuSelectStyle = { cursor: 'pointer', lineHeight: '1.5', }), - menuPortal: base => ({ ...base, zIndex: 9999 }), + menuPortal: base => ({ ...base, zIndex: 9999 }), indicatorSeparator: () => {}, }; diff --git a/frontend/src/components/common/switch/index.js b/frontend/src/components/common/switch/index.js index 938c206bb0..fbf4d700c3 100644 --- a/frontend/src/components/common/switch/index.js +++ b/frontend/src/components/common/switch/index.js @@ -6,7 +6,7 @@ import '../../../css/switch.css'; function Switch(props) { const { onChange, checked, placeholder, disabled, className, size, textPosition, setRef } = props; - return( + return (