/
home
/
techb158
/
balavpn.abdallabala.com
/
node_modules
/
eslint-plugin-react
/
lib
/
rules
/
/home/techb158/balavpn.abdallabala.com/node_modules/eslint-plugin-react/lib/rules
mkdir
upload
Name
Size
Mode
Actions
boolean-prop-naming.d.ts
126
0666
edit
dl
rm
boolean-prop-naming.d.ts.map
161
0666
edit
dl
rm
boolean-prop-naming.js
13286
0666
edit
dl
rm
button-has-type.d.ts
122
0666
edit
dl
rm
button-has-type.d.ts.map
153
0666
edit
dl
rm
button-has-type.js
4528
0666
edit
dl
rm
checked-requires-onchange-or-readonly.d.ts
144
0666
edit
dl
rm
checked-requires-onchange-or-readonly.d.ts.map
197
0666
edit
dl
rm
checked-requires-onchange-or-readonly.js
3547
0666
edit
dl
rm
default-props-match-prop-types.d.ts
137
0666
edit
dl
rm
default-props-match-prop-types.d.ts.map
183
0666
edit
dl
rm
default-props-match-prop-types.js
3468
0666
edit
dl
rm
destructuring-assignment.d.ts
131
0666
edit
dl
rm
destructuring-assignment.d.ts.map
171
0666
edit
dl
rm
destructuring-assignment.js
9888
0666
edit
dl
rm
display-name.d.ts
119
0666
edit
dl
rm
display-name.d.ts.map
147
0666
edit
dl
rm
display-name.js
9130
0666
edit
dl
rm
forbid-component-props.d.ts
129
0666
edit
dl
rm
forbid-component-props.d.ts.map
167
0666
edit
dl
rm
forbid-component-props.js
7769
0666
edit
dl
rm
forbid-dom-props.d.ts
123
0666
edit
dl
rm
forbid-dom-props.d.ts.map
155
0666
edit
dl
rm
forbid-dom-props.js
3190
0666
edit
dl
rm
forbid-elements.d.ts
122
0666
edit
dl
rm
forbid-elements.d.ts.map
153
0666
edit
dl
rm
forbid-elements.js
3200
0666
edit
dl
rm
forbid-foreign-prop-types.d.ts
132
0666
edit
dl
rm
forbid-foreign-prop-types.d.ts.map
172
0666
edit
dl
rm
forbid-foreign-prop-types.js
3714
0666
edit
dl
rm
forbid-prop-types.d.ts
124
0666
edit
dl
rm
forbid-prop-types.d.ts.map
157
0666
edit
dl
rm
forbid-prop-types.js
8859
0666
edit
dl
rm
forward-ref-uses-ref.d.ts
127
0666
edit
dl
rm
forward-ref-uses-ref.d.ts.map
163
0666
edit
dl
rm
forward-ref-uses-ref.js
3133
0666
edit
dl
rm
function-component-definition.d.ts
136
0666
edit
dl
rm
function-component-definition.d.ts.map
181
0666
edit
dl
rm
function-component-definition.js
8413
0666
edit
dl
rm
hook-use-state.d.ts
121
0666
edit
dl
rm
hook-use-state.d.ts.map
151
0666
edit
dl
rm
hook-use-state.js
7365
0666
edit
dl
rm
iframe-missing-sandbox.d.ts
129
0666
edit
dl
rm
iframe-missing-sandbox.d.ts.map
167
0666
edit
dl
rm
iframe-missing-sandbox.js
4022
0666
edit
dl
rm
index.d.ts
6479
0666
edit
dl
rm
index.d.ts.map
224
0666
edit
dl
rm
index.js
6337
0666
edit
dl
rm
jsx-boolean-value.d.ts
124
0666
edit
dl
rm
jsx-boolean-value.d.ts.map
157
0666
edit
dl
rm
jsx-boolean-value.js
4515
0666
edit
dl
rm
jsx-child-element-spacing.d.ts
132
0666
edit
dl
rm
jsx-child-element-spacing.d.ts.map
173
0666
edit
dl
rm
jsx-child-element-spacing.js
2915
0666
edit
dl
rm
jsx-closing-bracket-location.d.ts
135
0666
edit
dl
rm
jsx-closing-bracket-location.d.ts.map
179
0666
edit
dl
rm
jsx-closing-bracket-location.js
11006
0666
edit
dl
rm
jsx-closing-tag-location.d.ts
131
0666
edit
dl
rm
jsx-closing-tag-location.d.ts.map
171
0666
edit
dl
rm
jsx-closing-tag-location.js
3766
0666
edit
dl
rm
jsx-curly-brace-presence.d.ts
131
0666
edit
dl
rm
jsx-curly-brace-presence.d.ts.map
171
0666
edit
dl
rm
jsx-curly-brace-presence.js
13890
0666
edit
dl
rm
jsx-curly-newline.d.ts
124
0666
edit
dl
rm
jsx-curly-newline.d.ts.map
157
0666
edit
dl
rm
jsx-curly-newline.js
6128
0666
edit
dl
rm
jsx-curly-spacing.d.ts
124
0666
edit
dl
rm
jsx-curly-spacing.d.ts.map
157
0666
edit
dl
rm
jsx-curly-spacing.js
14795
0666
edit
dl
rm
jsx-equals-spacing.d.ts
125
0666
edit
dl
rm
jsx-equals-spacing.d.ts.map
159
0666
edit
dl
rm
jsx-equals-spacing.js
3621
0666
edit
dl
rm
jsx-filename-extension.d.ts
129
0666
edit
dl
rm
jsx-filename-extension.d.ts.map
167
0666
edit
dl
rm
jsx-filename-extension.js
3240
0666
edit
dl
rm
jsx-first-prop-new-line.d.ts
130
0666
edit
dl
rm
jsx-first-prop-new-line.d.ts.map
169
0666
edit
dl
rm
jsx-first-prop-new-line.js
2734
0666
edit
dl
rm
jsx-fragments.d.ts
120
0666
edit
dl
rm
jsx-fragments.d.ts.map
149
0666
edit
dl
rm
jsx-fragments.js
7043
0666
edit
dl
rm
jsx-handler-names.d.ts
124
0666
edit
dl
rm
jsx-handler-names.d.ts.map
157
0666
edit
dl
rm
jsx-handler-names.js
6347
0666
edit
dl
rm
jsx-indent-props.d.ts
123
0666
edit
dl
rm
jsx-indent-props.d.ts.map
155
0666
edit
dl
rm
jsx-indent-props.js
6579
0666
edit
dl
rm
jsx-indent.d.ts
117
0666
edit
dl
rm
jsx-indent.d.ts.map
143
0666
edit
dl
rm
jsx-indent.js
14681
0666
edit
dl
rm
jsx-key.d.ts
114
0666
edit
dl
rm
jsx-key.d.ts.map
137
0666
edit
dl
rm
jsx-key.js
10172
0666
edit
dl
rm
jsx-max-depth.d.ts
120
0666
edit
dl
rm
jsx-max-depth.d.ts.map
149
0666
edit
dl
rm
jsx-max-depth.js
4133
0666
edit
dl
rm
jsx-max-props-per-line.d.ts
129
0666
edit
dl
rm
jsx-max-props-per-line.d.ts.map
167
0666
edit
dl
rm
jsx-max-props-per-line.js
4162
0666
edit
dl
rm
jsx-newline.d.ts
118
0666
edit
dl
rm
jsx-newline.d.ts.map
145
0666
edit
dl
rm
jsx-newline.js
5044
0666
edit
dl
rm
jsx-no-bind.d.ts
118
0666
edit
dl
rm
jsx-no-bind.d.ts.map
145
0666
edit
dl
rm
jsx-no-bind.js
6172
0666
edit
dl
rm
jsx-no-comment-textnodes.d.ts
131
0666
edit
dl
rm
jsx-no-comment-textnodes.d.ts.map
171
0666
edit
dl
rm
jsx-no-comment-textnodes.js
1847
0666
edit
dl
rm
jsx-no-constructed-context-values.d.ts
140
0666
edit
dl
rm
jsx-no-constructed-context-values.d.ts.map
189
0666
edit
dl
rm
jsx-no-constructed-context-values.js
8778
0666
edit
dl
rm
jsx-no-duplicate-props.d.ts
129
0666
edit
dl
rm
jsx-no-duplicate-props.d.ts.map
167
0666
edit
dl
rm
jsx-no-duplicate-props.js
1697
0666
edit
dl
rm
jsx-no-leaked-render.d.ts
127
0666
edit
dl
rm
jsx-no-leaked-render.d.ts.map
163
0666
edit
dl
rm
jsx-no-leaked-render.js
7618
0666
edit
dl
rm
jsx-no-literals.d.ts
926
0666
edit
dl
rm
jsx-no-literals.d.ts.map
128
0666
edit
dl
rm
jsx-no-literals.js
16912
0666
edit
dl
rm
jsx-no-script-url.d.ts
124
0666
edit
dl
rm
jsx-no-script-url.d.ts.map
157
0666
edit
dl
rm
jsx-no-script-url.js
4156
0666
edit
dl
rm
jsx-no-target-blank.d.ts
126
0666
edit
dl
rm
jsx-no-target-blank.d.ts.map
161
0666
edit
dl
rm
jsx-no-target-blank.js
11018
0666
edit
dl
rm
jsx-no-undef.d.ts
119
0666
edit
dl
rm
jsx-no-undef.d.ts.map
147
0666
edit
dl
rm
jsx-no-undef.js
3157
0666
edit
dl
rm
jsx-no-useless-fragment.d.ts
130
0666
edit
dl
rm
jsx-no-useless-fragment.d.ts.map
169
0666
edit
dl
rm
jsx-no-useless-fragment.js
7018
0666
edit
dl
rm
jsx-one-expression-per-line.d.ts
134
0666
edit
dl
rm
jsx-one-expression-per-line.d.ts.map
177
0666
edit
dl
rm
jsx-one-expression-per-line.js
7949
0666
edit
dl
rm
jsx-pascal-case.d.ts
122
0666
edit
dl
rm
jsx-pascal-case.d.ts.map
153
0666
edit
dl
rm
jsx-pascal-case.js
4594
0666
edit
dl
rm
jsx-props-no-multi-spaces.d.ts
132
0666
edit
dl
rm
jsx-props-no-multi-spaces.d.ts.map
173
0666
edit
dl
rm
jsx-props-no-multi-spaces.js
3900
0666
edit
dl
rm
jsx-props-no-spread-multi.d.ts
132
0666
edit
dl
rm
jsx-props-no-spread-multi.d.ts.map
173
0666
edit
dl
rm
jsx-props-no-spread-multi.js
1527
0666
edit
dl
rm
jsx-props-no-spreading.d.ts
129
0666
edit
dl
rm
jsx-props-no-spreading.d.ts.map
167
0666
edit
dl
rm
jsx-props-no-spreading.js
4174
0666
edit
dl
rm
jsx-sort-default-props.d.ts
129
0666
edit
dl
rm
jsx-sort-default-props.d.ts.map
167
0666
edit
dl
rm
jsx-sort-default-props.js
5635
0666
edit
dl
rm
jsx-sort-props.d.ts
121
0666
edit
dl
rm
jsx-sort-props.d.ts.map
151
0666
edit
dl
rm
jsx-sort-props.js
18241
0666
edit
dl
rm
jsx-space-before-closing.d.ts
131
0666
edit
dl
rm
jsx-space-before-closing.d.ts.map
171
0666
edit
dl
rm
jsx-space-before-closing.js
3049
0666
edit
dl
rm
jsx-tag-spacing.d.ts
122
0666
edit
dl
rm
jsx-tag-spacing.d.ts.map
153
0666
edit
dl
rm
jsx-tag-spacing.js
10677
0666
edit
dl
rm
jsx-uses-react.d.ts
121
0666
edit
dl
rm
jsx-uses-react.d.ts.map
150
0666
edit
dl
rm
jsx-uses-react.js
1572
0666
edit
dl
rm
jsx-uses-vars.d.ts
120
0666
edit
dl
rm
jsx-uses-vars.d.ts.map
149
0666
edit
dl
rm
jsx-uses-vars.js
1655
0666
edit
dl
rm
jsx-wrap-multilines.d.ts
126
0666
edit
dl
rm
jsx-wrap-multilines.d.ts.map
161
0666
edit
dl
rm
jsx-wrap-multilines.js
8442
0666
edit
dl
rm
no-access-state-in-setstate.d.ts
134
0666
edit
dl
rm
no-access-state-in-setstate.d.ts.map
177
0666
edit
dl
rm
no-access-state-in-setstate.js
6790
0666
edit
dl
rm
no-adjacent-inline-elements.d.ts
134
0666
edit
dl
rm
no-adjacent-inline-elements.d.ts.map
177
0666
edit
dl
rm
no-adjacent-inline-elements.js
3139
0666
edit
dl
rm
no-array-index-key.d.ts
125
0666
edit
dl
rm
no-array-index-key.d.ts.map
159
0666
edit
dl
rm
no-array-index-key.js
7509
0666
edit
dl
rm
no-arrow-function-lifecycle.d.ts
134
0666
edit
dl
rm
no-arrow-function-lifecycle.d.ts.map
177
0666
edit
dl
rm
no-arrow-function-lifecycle.js
5163
0666
edit
dl
rm
no-children-prop.d.ts
123
0666
edit
dl
rm
no-children-prop.d.ts.map
155
0666
edit
dl
rm
no-children-prop.js
3968
0666
edit
dl
rm
no-danger-with-children.d.ts
130
0666
edit
dl
rm
no-danger-with-children.d.ts.map
169
0666
edit
dl
rm
no-danger-with-children.js
5187
0666
edit
dl
rm
no-danger.d.ts
116
0666
edit
dl
rm
no-danger.d.ts.map
141
0666
edit
dl
rm
no-danger.js
2695
0666
edit
dl
rm
no-deprecated.d.ts
120
0666
edit
dl
rm
no-deprecated.d.ts.map
149
0666
edit
dl
rm
no-deprecated.js
9961
0666
edit
dl
rm
no-did-mount-set-state.d.ts
129
0666
edit
dl
rm
no-did-mount-set-state.d.ts.map
166
0666
edit
dl
rm
no-did-mount-set-state.js
308
0666
edit
dl
rm
no-did-update-set-state.d.ts
130
0666
edit
dl
rm
no-did-update-set-state.d.ts.map
168
0666
edit
dl
rm
no-did-update-set-state.js
310
0666
edit
dl
rm
no-direct-mutation-state.d.ts
131
0666
edit
dl
rm
no-direct-mutation-state.d.ts.map
171
0666
edit
dl
rm
no-direct-mutation-state.js
4591
0666
edit
dl
rm
no-find-dom-node.d.ts
123
0666
edit
dl
rm
no-find-dom-node.d.ts.map
155
0666
edit
dl
rm
no-find-dom-node.js
1389
0666
edit
dl
rm
no-invalid-html-attribute.d.ts
132
0666
edit
dl
rm
no-invalid-html-attribute.d.ts.map
174
0666
edit
dl
rm
no-invalid-html-attribute.js
16601
0666
edit
dl
rm
no-is-mounted.d.ts
120
0666
edit
dl
rm
no-is-mounted.d.ts.map
149
0666
edit
dl
rm
no-is-mounted.js
1522
0666
edit
dl
rm
no-multi-comp.d.ts
120
0666
edit
dl
rm
no-multi-comp.d.ts.map
149
0666
edit
dl
rm
no-multi-comp.js
2066
0666
edit
dl
rm
no-namespace.d.ts
119
0666
edit
dl
rm
no-namespace.d.ts.map
147
0666
edit
dl
rm
no-namespace.js
1744
0666
edit
dl
rm
no-object-type-as-default-prop.d.ts
137
0666
edit
dl
rm
no-object-type-as-default-prop.d.ts.map
183
0666
edit
dl
rm
no-object-type-as-default-prop.js
3285
0666
edit
dl
rm
no-redundant-should-component-update.d.ts
143
0666
edit
dl
rm
no-redundant-should-component-update.d.ts.map
195
0666
edit
dl
rm
no-redundant-should-component-update.js
2437
0666
edit
dl
rm
no-render-return-value.d.ts
129
0666
edit
dl
rm
no-render-return-value.d.ts.map
167
0666
edit
dl
rm
no-render-return-value.js
2308
0666
edit
dl
rm
no-set-state.d.ts
119
0666
edit
dl
rm
no-set-state.d.ts.map
147
0666
edit
dl
rm
no-set-state.js
2374
0666
edit
dl
rm
no-string-refs.d.ts
121
0666
edit
dl
rm
no-string-refs.d.ts.map
151
0666
edit
dl
rm
no-string-refs.js
3770
0666
edit
dl
rm
no-this-in-sfc.d.ts
121
0666
edit
dl
rm
no-this-in-sfc.d.ts.map
151
0666
edit
dl
rm
no-this-in-sfc.js
1326
0666
edit
dl
rm
no-typos.d.ts
115
0666
edit
dl
rm
no-typos.d.ts.map
139
0666
edit
dl
rm
no-typos.js
8930
0666
edit
dl
rm
no-unescaped-entities.d.ts
128
0666
edit
dl
rm
no-unescaped-entities.d.ts.map
165
0666
edit
dl
rm
no-unescaped-entities.js
4773
0666
edit
dl
rm
no-unknown-property.d.ts
126
0666
edit
dl
rm
no-unknown-property.d.ts.map
162
0666
edit
dl
rm
no-unknown-property.js
28149
0666
edit
dl
rm
no-unsafe.d.ts
116
0666
edit
dl
rm
no-unsafe.d.ts.map
141
0666
edit
dl
rm
no-unsafe.js
4442
0666
edit
dl
rm
no-unstable-nested-components.d.ts
136
0666
edit
dl
rm
no-unstable-nested-components.d.ts.map
181
0666
edit
dl
rm
no-unstable-nested-components.js
15517
0666
edit
dl
rm
no-unused-class-component-methods.d.ts
140
0666
edit
dl
rm
no-unused-class-component-methods.d.ts.map
189
0666
edit
dl
rm
no-unused-class-component-methods.js
6795
0666
edit
dl
rm
no-unused-prop-types.d.ts
127
0666
edit
dl
rm
no-unused-prop-types.d.ts.map
163
0666
edit
dl
rm
no-unused-prop-types.js
4897
0666
edit
dl
rm
no-unused-state.d.ts
122
0666
edit
dl
rm
no-unused-state.d.ts.map
153
0666
edit
dl
rm
no-unused-state.js
16159
0666
edit
dl
rm
no-will-update-set-state.d.ts
131
0666
edit
dl
rm
no-will-update-set-state.d.ts.map
170
0666
edit
dl
rm
no-will-update-set-state.js
441
0666
edit
dl
rm
prefer-es6-class.d.ts
123
0666
edit
dl
rm
prefer-es6-class.d.ts.map
155
0666
edit
dl
rm
prefer-es6-class.js
1572
0666
edit
dl
rm
prefer-exact-props.d.ts
125
0666
edit
dl
rm
prefer-exact-props.d.ts.map
159
0666
edit
dl
rm
prefer-exact-props.js
5045
0666
edit
dl
rm
prefer-read-only-props.d.ts
129
0666
edit
dl
rm
prefer-read-only-props.d.ts.map
167
0666
edit
dl
rm
prefer-read-only-props.js
3069
0666
edit
dl
rm
prefer-stateless-function.d.ts
132
0666
edit
dl
rm
prefer-stateless-function.d.ts.map
173
0666
edit
dl
rm
prefer-stateless-function.js
12952
0666
edit
dl
rm
prop-types.d.ts
117
0666
edit
dl
rm
prop-types.d.ts.map
143
0666
edit
dl
rm
prop-types.js
7417
0666
edit
dl
rm
react-in-jsx-scope.d.ts
125
0666
edit
dl
rm
react-in-jsx-scope.d.ts.map
159
0666
edit
dl
rm
react-in-jsx-scope.js
1328
0666
edit
dl
rm
require-default-props.d.ts
128
0666
edit
dl
rm
require-default-props.d.ts.map
165
0666
edit
dl
rm
require-default-props.js
7361
0666
edit
dl
rm
require-optimization.d.ts
127
0666
edit
dl
rm
require-optimization.d.ts.map
163
0666
edit
dl
rm
require-optimization.js
7076
0666
edit
dl
rm
require-render-return.d.ts
128
0666
edit
dl
rm
require-render-return.d.ts.map
165
0666
edit
dl
rm
require-render-return.js
3237
0666
edit
dl
rm
self-closing-comp.d.ts
124
0666
edit
dl
rm
self-closing-comp.d.ts.map
157
0666
edit
dl
rm
self-closing-comp.js
2930
0666
edit
dl
rm
sort-comp.d.ts
116
0666
edit
dl
rm
sort-comp.d.ts.map
141
0666
edit
dl
rm
sort-comp.js
13733
0666
edit
dl
rm
sort-default-props.d.ts
125
0666
edit
dl
rm
sort-default-props.d.ts.map
159
0666
edit
dl
rm
sort-default-props.js
5233
0666
edit
dl
rm
sort-prop-types.d.ts
122
0666
edit
dl
rm
sort-prop-types.d.ts.map
153
0666
edit
dl
rm
sort-prop-types.js
10155
0666
edit
dl
rm
state-in-constructor.d.ts
127
0666
edit
dl
rm
state-in-constructor.d.ts.map
163
0666
edit
dl
rm
state-in-constructor.js
1921
0666
edit
dl
rm
static-property-placement.d.ts
132
0666
edit
dl
rm
static-property-placement.d.ts.map
173
0666
edit
dl
rm
static-property-placement.js
6734
0666
edit
dl
rm
style-prop-object.d.ts
124
0666
edit
dl
rm
style-prop-object.d.ts.map
157
0666
edit
dl
rm
style-prop-object.js
4134
0666
edit
dl
rm
void-dom-elements-no-children.d.ts
136
0666
edit
dl
rm
void-dom-elements-no-children.d.ts.map
181
0666
edit
dl
rm
void-dom-elements-no-children.js
4133
0666
edit
dl
rm
Edit:
/home/techb158/balavpn.abdallabala.com/node_modules/eslint-plugin-react/lib/rules/sort-comp.js
(13733B)
/** * @fileoverview Enforce component methods order * @author Yannick Croissant */ 'use strict'; const has = require('hasown'); const entries = require('object.entries'); const values = require('object.values'); const arrayIncludes = require('array-includes'); const Components = require('../util/Components'); const astUtil = require('../util/ast'); const docsUrl = require('../util/docsUrl'); const report = require('../util/report'); const defaultConfig = { order: [ 'static-methods', 'lifecycle', 'everything-else', 'render', ], groups: { lifecycle: [ 'displayName', 'propTypes', 'contextTypes', 'childContextTypes', 'mixins', 'statics', 'defaultProps', 'constructor', 'getDefaultProps', 'state', 'getInitialState', 'getChildContext', 'getDerivedStateFromProps', 'componentWillMount', 'UNSAFE_componentWillMount', 'componentDidMount', 'componentWillReceiveProps', 'UNSAFE_componentWillReceiveProps', 'shouldComponentUpdate', 'componentWillUpdate', 'UNSAFE_componentWillUpdate', 'getSnapshotBeforeUpdate', 'componentDidUpdate', 'componentDidCatch', 'componentWillUnmount', ], }, }; /** * Get the methods order from the default config and the user config * @param {Object} userConfig The user configuration. * @returns {Array} Methods order */ function getMethodsOrder(userConfig) { userConfig = userConfig || {}; const groups = Object.assign({}, defaultConfig.groups, userConfig.groups); const order = userConfig.order || defaultConfig.order; let config = []; let entry; for (let i = 0, j = order.length; i < j; i++) { entry = order[i]; if (has(groups, entry)) { config = config.concat(groups[entry]); } else { config.push(entry); } } return config; } // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ const messages = { unsortedProps: '{{propA}} should be placed {{position}} {{propB}}', }; /** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { docs: { description: 'Enforce component methods order', category: 'Stylistic Issues', recommended: false, url: docsUrl('sort-comp'), }, messages, schema: [{ type: 'object', properties: { order: { type: 'array', items: { type: 'string', }, }, groups: { type: 'object', patternProperties: { '^.*$': { type: 'array', items: { type: 'string', }, }, }, }, }, additionalProperties: false, }], }, create: Components.detect((context, components) => { /** @satisfies {Record<string, { node: ASTNode, score: number, closest: { distance: number, ref: { node: null | ASTNode, index: number } } }>} */ const errors = {}; const methodsOrder = getMethodsOrder(context.options[0]); // -------------------------------------------------------------------------- // Public // -------------------------------------------------------------------------- const regExpRegExp = /\/(.*)\/([gimsuy]*)/; /** * Get indexes of the matching patterns in methods order configuration * @param {Object} method - Method metadata. * @returns {Array} The matching patterns indexes. Return [Infinity] if there is no match. */ function getRefPropIndexes(method) { const methodGroupIndexes = []; methodsOrder.forEach((currentGroup, groupIndex) => { if (currentGroup === 'getters') { if (method.getter) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === 'setters') { if (method.setter) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === 'type-annotations') { if (method.typeAnnotation) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === 'static-variables') { if (method.staticVariable) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === 'static-methods') { if (method.staticMethod) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === 'instance-variables') { if (method.instanceVariable) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === 'instance-methods') { if (method.instanceMethod) { methodGroupIndexes.push(groupIndex); } } else if (arrayIncludes([ 'displayName', 'propTypes', 'contextTypes', 'childContextTypes', 'mixins', 'statics', 'defaultProps', 'constructor', 'getDefaultProps', 'state', 'getInitialState', 'getChildContext', 'getDerivedStateFromProps', 'componentWillMount', 'UNSAFE_componentWillMount', 'componentDidMount', 'componentWillReceiveProps', 'UNSAFE_componentWillReceiveProps', 'shouldComponentUpdate', 'componentWillUpdate', 'UNSAFE_componentWillUpdate', 'getSnapshotBeforeUpdate', 'componentDidUpdate', 'componentDidCatch', 'componentWillUnmount', 'render', ], currentGroup)) { if (currentGroup === method.name) { methodGroupIndexes.push(groupIndex); } } else { // Is the group a regex? const isRegExp = currentGroup.match(regExpRegExp); if (isRegExp) { const isMatching = new RegExp(isRegExp[1], isRegExp[2]).test(method.name); if (isMatching) { methodGroupIndexes.push(groupIndex); } } else if (currentGroup === method.name) { methodGroupIndexes.push(groupIndex); } } }); // No matching pattern, return 'everything-else' index if (methodGroupIndexes.length === 0) { const everythingElseIndex = methodsOrder.indexOf('everything-else'); if (everythingElseIndex !== -1) { methodGroupIndexes.push(everythingElseIndex); } else { // No matching pattern and no 'everything-else' group methodGroupIndexes.push(Infinity); } } return methodGroupIndexes; } /** * Get properties name * @param {Object} node - Property. * @returns {string} Property name. */ function getPropertyName(node) { if (node.kind === 'get') { return 'getter functions'; } if (node.kind === 'set') { return 'setter functions'; } return astUtil.getPropertyName(node); } /** * Store a new error in the error list * @param {Object} propA - Mispositioned property. * @param {Object} propB - Reference property. */ function storeError(propA, propB) { // Initialize the error object if needed if (!errors[propA.index]) { errors[propA.index] = { node: propA.node, score: 0, closest: { distance: Infinity, ref: { node: null, index: 0, }, }, }; } // Increment the prop score errors[propA.index].score += 1; // Stop here if we already have pushed another node at this position if (getPropertyName(errors[propA.index].node) !== getPropertyName(propA.node)) { return; } // Stop here if we already have a closer reference if (Math.abs(propA.index - propB.index) > errors[propA.index].closest.distance) { return; } // Update the closest reference errors[propA.index].closest.distance = Math.abs(propA.index - propB.index); errors[propA.index].closest.ref.node = propB.node; errors[propA.index].closest.ref.index = propB.index; } /** * Dedupe errors, only keep the ones with the highest score and delete the others */ function dedupeErrors() { entries(errors).forEach((entry) => { const i = entry[0]; const error = entry[1]; const index = error.closest.ref.index; if (errors[index]) { if (error.score > errors[index].score) { delete errors[index]; } else { delete errors[i]; } } }); } /** * Report errors */ function reportErrors() { dedupeErrors(); entries(errors).forEach((entry) => { const nodeA = entry[1].node; const nodeB = entry[1].closest.ref.node; const indexA = entry[0]; const indexB = entry[1].closest.ref.index; report(context, messages.unsortedProps, 'unsortedProps', { node: nodeA, data: { propA: getPropertyName(nodeA), propB: getPropertyName(nodeB), position: indexA < indexB ? 'before' : 'after', }, }); }); } /** * Compare two properties and find out if they are in the right order * @param {Array} propertiesInfos Array containing all the properties metadata. * @param {Object} propA First property name and metadata * @param {Object} propB Second property name. * @returns {Object} Object containing a correct true/false flag and the correct indexes for the two properties. */ function comparePropsOrder(propertiesInfos, propA, propB) { let i; let j; let k; let l; let refIndexA; let refIndexB; // Get references indexes (the correct position) for given properties const refIndexesA = getRefPropIndexes(propA); const refIndexesB = getRefPropIndexes(propB); // Get current indexes for given properties const classIndexA = propertiesInfos.indexOf(propA); const classIndexB = propertiesInfos.indexOf(propB); // Loop around the references indexes for the 1st property for (i = 0, j = refIndexesA.length; i < j; i++) { refIndexA = refIndexesA[i]; // Loop around the properties for the 2nd property (for comparison) for (k = 0, l = refIndexesB.length; k < l; k++) { refIndexB = refIndexesB[k]; if ( // Comparing the same properties refIndexA === refIndexB // 1st property is placed before the 2nd one in reference and in current component || ((refIndexA < refIndexB) && (classIndexA < classIndexB)) // 1st property is placed after the 2nd one in reference and in current component || ((refIndexA > refIndexB) && (classIndexA > classIndexB)) ) { return { correct: true, indexA: classIndexA, indexB: classIndexB, }; } } } // We did not find any correct match between reference and current component return { correct: false, indexA: refIndexA, indexB: refIndexB, }; } /** * Check properties order from a properties list and store the eventual errors * @param {Array} properties Array containing all the properties. */ function checkPropsOrder(properties) { const propertiesInfos = properties.map((node) => ({ name: getPropertyName(node), getter: node.kind === 'get', setter: node.kind === 'set', staticVariable: node.static && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition') && (!node.value || !astUtil.isFunctionLikeExpression(node.value)), staticMethod: node.static && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition' || node.type === 'MethodDefinition') && node.value && (astUtil.isFunctionLikeExpression(node.value)), instanceVariable: !node.static && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition') && (!node.value || !astUtil.isFunctionLikeExpression(node.value)), instanceMethod: !node.static && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition') && node.value && (astUtil.isFunctionLikeExpression(node.value)), typeAnnotation: !!node.typeAnnotation && node.value === null, })); // Loop around the properties propertiesInfos.forEach((propA, i) => { // Loop around the properties a second time (for comparison) propertiesInfos.forEach((propB, k) => { if (i === k) { return; } // Compare the properties order const order = comparePropsOrder(propertiesInfos, propA, propB); if (!order.correct) { // Store an error if the order is incorrect storeError({ node: properties[i], index: order.indexA, }, { node: properties[k], index: order.indexB, }); } }); }); } return { 'Program:exit'() { values(components.list()).forEach((component) => { const properties = astUtil.getComponentProperties(component.node); checkPropsOrder(properties); }); reportErrors(); }, }; }), defaultConfig, };
Save
cmd:
run