Skip to content

Commit

Permalink
fix: eslint react rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ModyQyW committed May 8, 2023
1 parent d2d5aae commit f974f05
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 81 deletions.
4 changes: 3 additions & 1 deletion src/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ const config: Linter.Config = {
enableNext ? 'next/core-web-vitals' : '',
enablePrettier ? 'plugin:prettier/recommended' : '',
].filter((item) => !!item),
rules: reactRules,
rules: {
...(enableReact ? reactRules : {}),
},
},
{
files: ['*.vue'],
Expand Down
157 changes: 77 additions & 80 deletions src/eslint/rules.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,83 @@
import type { Linter } from 'eslint';
import { enableReact } from '../helpers';

export const reactRules: Linter.RulesRecord = enableReact
? {
'react/sort-comp': [
'error',
{
order: [
'static-variables',
'static-methods',
'instance-variables',
'lifecycle',
'/^handle.+$/',
'/^on.+$/',
'getters',
'setters',
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
'instance-methods',
'everything-else',
'rendering',
],
groups: {
lifecycle: [
'displayName',
'propTypes',
'contextTypes',
'childContextTypes',
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'getInitialState',
'state',
'getChildContext',
'getDerivedStateFromProps',
'componentWillMount',
'UNSAFE_componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'UNSAFE_componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'UNSAFE_componentWillUpdate',
'getSnapshotBeforeUpdate',
'componentDidUpdate',
'componentDidCatch',
'componentWillUnmount',
// add miniprogram support
'onLaunch',
'onLoad',
'onUnload',
'onReady',
'componentDidShow',
'componentDidHide',
'onPullDownRefresh',
'onReachBottom',
'onPageScroll',
'onAddToFavorites',
'onShareAppMessage',
'onShareTimeline',
'onResize',
'onTabItemTap',
'onSaveExitState',
'onTitleClick',
'onOptionMenuClick',
'onPopMenuClick',
'onPullIntercept',
],
rendering: ['/^render.+$/', 'render'],
},
},
],
'react-hooks/exhaustive-deps': [
'warn',
{
// recoil
additionalHooks: '(useRecoilCallback|useRecoilTransaction|useRecoilTransaction_UNSTABLE)',
},
export const reactRules: Linter.RulesRecord = {
'react/sort-comp': [
'error',
{
order: [
'static-variables',
'static-methods',
'instance-variables',
'lifecycle',
'/^handle.+$/',
'/^on.+$/',
'getters',
'setters',
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
'instance-methods',
'everything-else',
'rendering',
],
}
: {};
groups: {
lifecycle: [
'displayName',
'propTypes',
'contextTypes',
'childContextTypes',
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'getInitialState',
'state',
'getChildContext',
'getDerivedStateFromProps',
'componentWillMount',
'UNSAFE_componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'UNSAFE_componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'UNSAFE_componentWillUpdate',
'getSnapshotBeforeUpdate',
'componentDidUpdate',
'componentDidCatch',
'componentWillUnmount',
// add miniprogram support
'onLaunch',
'onLoad',
'onUnload',
'onReady',
'componentDidShow',
'componentDidHide',
'onPullDownRefresh',
'onReachBottom',
'onPageScroll',
'onAddToFavorites',
'onShareAppMessage',
'onShareTimeline',
'onResize',
'onTabItemTap',
'onSaveExitState',
'onTitleClick',
'onOptionMenuClick',
'onPopMenuClick',
'onPullIntercept',
],
rendering: ['/^render.+$/', 'render'],
},
},
],
'react-hooks/exhaustive-deps': [
'warn',
{
// recoil
additionalHooks: '(useRecoilCallback|useRecoilTransaction|useRecoilTransaction_UNSTABLE)',
},
],
};

export const vueRules: Linter.RulesRecord = {
// too ideal for business
Expand Down

0 comments on commit f974f05

Please sign in to comment.