/home/techb158/balavpn.abdallabala.com/node_modules/eslint-plugin-react/lib/rules
NameSizeModeActions
boolean-prop-naming.d.ts1260666editdlrm
boolean-prop-naming.d.ts.map1610666editdlrm
boolean-prop-naming.js132860666editdlrm
button-has-type.d.ts1220666editdlrm
button-has-type.d.ts.map1530666editdlrm
button-has-type.js45280666editdlrm
checked-requires-onchange-or-readonly.d.ts1440666editdlrm
checked-requires-onchange-or-readonly.d.ts.map1970666editdlrm
checked-requires-onchange-or-readonly.js35470666editdlrm
default-props-match-prop-types.d.ts1370666editdlrm
default-props-match-prop-types.d.ts.map1830666editdlrm
default-props-match-prop-types.js34680666editdlrm
destructuring-assignment.d.ts1310666editdlrm
destructuring-assignment.d.ts.map1710666editdlrm
destructuring-assignment.js98880666editdlrm
display-name.d.ts1190666editdlrm
display-name.d.ts.map1470666editdlrm
display-name.js91300666editdlrm
forbid-component-props.d.ts1290666editdlrm
forbid-component-props.d.ts.map1670666editdlrm
forbid-component-props.js77690666editdlrm
forbid-dom-props.d.ts1230666editdlrm
forbid-dom-props.d.ts.map1550666editdlrm
forbid-dom-props.js31900666editdlrm
forbid-elements.d.ts1220666editdlrm
forbid-elements.d.ts.map1530666editdlrm
forbid-elements.js32000666editdlrm
forbid-foreign-prop-types.d.ts1320666editdlrm
forbid-foreign-prop-types.d.ts.map1720666editdlrm
forbid-foreign-prop-types.js37140666editdlrm
forbid-prop-types.d.ts1240666editdlrm
forbid-prop-types.d.ts.map1570666editdlrm
forbid-prop-types.js88590666editdlrm
forward-ref-uses-ref.d.ts1270666editdlrm
forward-ref-uses-ref.d.ts.map1630666editdlrm
forward-ref-uses-ref.js31330666editdlrm
function-component-definition.d.ts1360666editdlrm
function-component-definition.d.ts.map1810666editdlrm
function-component-definition.js84130666editdlrm
hook-use-state.d.ts1210666editdlrm
hook-use-state.d.ts.map1510666editdlrm
hook-use-state.js73650666editdlrm
iframe-missing-sandbox.d.ts1290666editdlrm
iframe-missing-sandbox.d.ts.map1670666editdlrm
iframe-missing-sandbox.js40220666editdlrm
index.d.ts64790666editdlrm
index.d.ts.map2240666editdlrm
index.js63370666editdlrm
jsx-boolean-value.d.ts1240666editdlrm
jsx-boolean-value.d.ts.map1570666editdlrm
jsx-boolean-value.js45150666editdlrm
jsx-child-element-spacing.d.ts1320666editdlrm
jsx-child-element-spacing.d.ts.map1730666editdlrm
jsx-child-element-spacing.js29150666editdlrm
jsx-closing-bracket-location.d.ts1350666editdlrm
jsx-closing-bracket-location.d.ts.map1790666editdlrm
jsx-closing-bracket-location.js110060666editdlrm
jsx-closing-tag-location.d.ts1310666editdlrm
jsx-closing-tag-location.d.ts.map1710666editdlrm
jsx-closing-tag-location.js37660666editdlrm
jsx-curly-brace-presence.d.ts1310666editdlrm
jsx-curly-brace-presence.d.ts.map1710666editdlrm
jsx-curly-brace-presence.js138900666editdlrm
jsx-curly-newline.d.ts1240666editdlrm
jsx-curly-newline.d.ts.map1570666editdlrm
jsx-curly-newline.js61280666editdlrm
jsx-curly-spacing.d.ts1240666editdlrm
jsx-curly-spacing.d.ts.map1570666editdlrm
jsx-curly-spacing.js147950666editdlrm
jsx-equals-spacing.d.ts1250666editdlrm
jsx-equals-spacing.d.ts.map1590666editdlrm
jsx-equals-spacing.js36210666editdlrm
jsx-filename-extension.d.ts1290666editdlrm
jsx-filename-extension.d.ts.map1670666editdlrm
jsx-filename-extension.js32400666editdlrm
jsx-first-prop-new-line.d.ts1300666editdlrm
jsx-first-prop-new-line.d.ts.map1690666editdlrm
jsx-first-prop-new-line.js27340666editdlrm
jsx-fragments.d.ts1200666editdlrm
jsx-fragments.d.ts.map1490666editdlrm
jsx-fragments.js70430666editdlrm
jsx-handler-names.d.ts1240666editdlrm
jsx-handler-names.d.ts.map1570666editdlrm
jsx-handler-names.js63470666editdlrm
jsx-indent-props.d.ts1230666editdlrm
jsx-indent-props.d.ts.map1550666editdlrm
jsx-indent-props.js65790666editdlrm
jsx-indent.d.ts1170666editdlrm
jsx-indent.d.ts.map1430666editdlrm
jsx-indent.js146810666editdlrm
jsx-key.d.ts1140666editdlrm
jsx-key.d.ts.map1370666editdlrm
jsx-key.js101720666editdlrm
jsx-max-depth.d.ts1200666editdlrm
jsx-max-depth.d.ts.map1490666editdlrm
jsx-max-depth.js41330666editdlrm
jsx-max-props-per-line.d.ts1290666editdlrm
jsx-max-props-per-line.d.ts.map1670666editdlrm
jsx-max-props-per-line.js41620666editdlrm
jsx-newline.d.ts1180666editdlrm
jsx-newline.d.ts.map1450666editdlrm
jsx-newline.js50440666editdlrm
jsx-no-bind.d.ts1180666editdlrm
jsx-no-bind.d.ts.map1450666editdlrm
jsx-no-bind.js61720666editdlrm
jsx-no-comment-textnodes.d.ts1310666editdlrm
jsx-no-comment-textnodes.d.ts.map1710666editdlrm
jsx-no-comment-textnodes.js18470666editdlrm
jsx-no-constructed-context-values.d.ts1400666editdlrm
jsx-no-constructed-context-values.d.ts.map1890666editdlrm
jsx-no-constructed-context-values.js87780666editdlrm
jsx-no-duplicate-props.d.ts1290666editdlrm
jsx-no-duplicate-props.d.ts.map1670666editdlrm
jsx-no-duplicate-props.js16970666editdlrm
jsx-no-leaked-render.d.ts1270666editdlrm
jsx-no-leaked-render.d.ts.map1630666editdlrm
jsx-no-leaked-render.js76180666editdlrm
jsx-no-literals.d.ts9260666editdlrm
jsx-no-literals.d.ts.map1280666editdlrm
jsx-no-literals.js169120666editdlrm
jsx-no-script-url.d.ts1240666editdlrm
jsx-no-script-url.d.ts.map1570666editdlrm
jsx-no-script-url.js41560666editdlrm
jsx-no-target-blank.d.ts1260666editdlrm
jsx-no-target-blank.d.ts.map1610666editdlrm
jsx-no-target-blank.js110180666editdlrm
jsx-no-undef.d.ts1190666editdlrm
jsx-no-undef.d.ts.map1470666editdlrm
jsx-no-undef.js31570666editdlrm
jsx-no-useless-fragment.d.ts1300666editdlrm
jsx-no-useless-fragment.d.ts.map1690666editdlrm
jsx-no-useless-fragment.js70180666editdlrm
jsx-one-expression-per-line.d.ts1340666editdlrm
jsx-one-expression-per-line.d.ts.map1770666editdlrm
jsx-one-expression-per-line.js79490666editdlrm
jsx-pascal-case.d.ts1220666editdlrm
jsx-pascal-case.d.ts.map1530666editdlrm
jsx-pascal-case.js45940666editdlrm
jsx-props-no-multi-spaces.d.ts1320666editdlrm
jsx-props-no-multi-spaces.d.ts.map1730666editdlrm
jsx-props-no-multi-spaces.js39000666editdlrm
jsx-props-no-spread-multi.d.ts1320666editdlrm
jsx-props-no-spread-multi.d.ts.map1730666editdlrm
jsx-props-no-spread-multi.js15270666editdlrm
jsx-props-no-spreading.d.ts1290666editdlrm
jsx-props-no-spreading.d.ts.map1670666editdlrm
jsx-props-no-spreading.js41740666editdlrm
jsx-sort-default-props.d.ts1290666editdlrm
jsx-sort-default-props.d.ts.map1670666editdlrm
jsx-sort-default-props.js56350666editdlrm
jsx-sort-props.d.ts1210666editdlrm
jsx-sort-props.d.ts.map1510666editdlrm
jsx-sort-props.js182410666editdlrm
jsx-space-before-closing.d.ts1310666editdlrm
jsx-space-before-closing.d.ts.map1710666editdlrm
jsx-space-before-closing.js30490666editdlrm
jsx-tag-spacing.d.ts1220666editdlrm
jsx-tag-spacing.d.ts.map1530666editdlrm
jsx-tag-spacing.js106770666editdlrm
jsx-uses-react.d.ts1210666editdlrm
jsx-uses-react.d.ts.map1500666editdlrm
jsx-uses-react.js15720666editdlrm
jsx-uses-vars.d.ts1200666editdlrm
jsx-uses-vars.d.ts.map1490666editdlrm
jsx-uses-vars.js16550666editdlrm
jsx-wrap-multilines.d.ts1260666editdlrm
jsx-wrap-multilines.d.ts.map1610666editdlrm
jsx-wrap-multilines.js84420666editdlrm
no-access-state-in-setstate.d.ts1340666editdlrm
no-access-state-in-setstate.d.ts.map1770666editdlrm
no-access-state-in-setstate.js67900666editdlrm
no-adjacent-inline-elements.d.ts1340666editdlrm
no-adjacent-inline-elements.d.ts.map1770666editdlrm
no-adjacent-inline-elements.js31390666editdlrm
no-array-index-key.d.ts1250666editdlrm
no-array-index-key.d.ts.map1590666editdlrm
no-array-index-key.js75090666editdlrm
no-arrow-function-lifecycle.d.ts1340666editdlrm
no-arrow-function-lifecycle.d.ts.map1770666editdlrm
no-arrow-function-lifecycle.js51630666editdlrm
no-children-prop.d.ts1230666editdlrm
no-children-prop.d.ts.map1550666editdlrm
no-children-prop.js39680666editdlrm
no-danger-with-children.d.ts1300666editdlrm
no-danger-with-children.d.ts.map1690666editdlrm
no-danger-with-children.js51870666editdlrm
no-danger.d.ts1160666editdlrm
no-danger.d.ts.map1410666editdlrm
no-danger.js26950666editdlrm
no-deprecated.d.ts1200666editdlrm
no-deprecated.d.ts.map1490666editdlrm
no-deprecated.js99610666editdlrm
no-did-mount-set-state.d.ts1290666editdlrm
no-did-mount-set-state.d.ts.map1660666editdlrm
no-did-mount-set-state.js3080666editdlrm
no-did-update-set-state.d.ts1300666editdlrm
no-did-update-set-state.d.ts.map1680666editdlrm
no-did-update-set-state.js3100666editdlrm
no-direct-mutation-state.d.ts1310666editdlrm
no-direct-mutation-state.d.ts.map1710666editdlrm
no-direct-mutation-state.js45910666editdlrm
no-find-dom-node.d.ts1230666editdlrm
no-find-dom-node.d.ts.map1550666editdlrm
no-find-dom-node.js13890666editdlrm
no-invalid-html-attribute.d.ts1320666editdlrm
no-invalid-html-attribute.d.ts.map1740666editdlrm
no-invalid-html-attribute.js166010666editdlrm
no-is-mounted.d.ts1200666editdlrm
no-is-mounted.d.ts.map1490666editdlrm
no-is-mounted.js15220666editdlrm
no-multi-comp.d.ts1200666editdlrm
no-multi-comp.d.ts.map1490666editdlrm
no-multi-comp.js20660666editdlrm
no-namespace.d.ts1190666editdlrm
no-namespace.d.ts.map1470666editdlrm
no-namespace.js17440666editdlrm
no-object-type-as-default-prop.d.ts1370666editdlrm
no-object-type-as-default-prop.d.ts.map1830666editdlrm
no-object-type-as-default-prop.js32850666editdlrm
no-redundant-should-component-update.d.ts1430666editdlrm
no-redundant-should-component-update.d.ts.map1950666editdlrm
no-redundant-should-component-update.js24370666editdlrm
no-render-return-value.d.ts1290666editdlrm
no-render-return-value.d.ts.map1670666editdlrm
no-render-return-value.js23080666editdlrm
no-set-state.d.ts1190666editdlrm
no-set-state.d.ts.map1470666editdlrm
no-set-state.js23740666editdlrm
no-string-refs.d.ts1210666editdlrm
no-string-refs.d.ts.map1510666editdlrm
no-string-refs.js37700666editdlrm
no-this-in-sfc.d.ts1210666editdlrm
no-this-in-sfc.d.ts.map1510666editdlrm
no-this-in-sfc.js13260666editdlrm
no-typos.d.ts1150666editdlrm
no-typos.d.ts.map1390666editdlrm
no-typos.js89300666editdlrm
no-unescaped-entities.d.ts1280666editdlrm
no-unescaped-entities.d.ts.map1650666editdlrm
no-unescaped-entities.js47730666editdlrm
no-unknown-property.d.ts1260666editdlrm
no-unknown-property.d.ts.map1620666editdlrm
no-unknown-property.js281490666editdlrm
no-unsafe.d.ts1160666editdlrm
no-unsafe.d.ts.map1410666editdlrm
no-unsafe.js44420666editdlrm
no-unstable-nested-components.d.ts1360666editdlrm
no-unstable-nested-components.d.ts.map1810666editdlrm
no-unstable-nested-components.js155170666editdlrm
no-unused-class-component-methods.d.ts1400666editdlrm
no-unused-class-component-methods.d.ts.map1890666editdlrm
no-unused-class-component-methods.js67950666editdlrm
no-unused-prop-types.d.ts1270666editdlrm
no-unused-prop-types.d.ts.map1630666editdlrm
no-unused-prop-types.js48970666editdlrm
no-unused-state.d.ts1220666editdlrm
no-unused-state.d.ts.map1530666editdlrm
no-unused-state.js161590666editdlrm
no-will-update-set-state.d.ts1310666editdlrm
no-will-update-set-state.d.ts.map1700666editdlrm
no-will-update-set-state.js4410666editdlrm
prefer-es6-class.d.ts1230666editdlrm
prefer-es6-class.d.ts.map1550666editdlrm
prefer-es6-class.js15720666editdlrm
prefer-exact-props.d.ts1250666editdlrm
prefer-exact-props.d.ts.map1590666editdlrm
prefer-exact-props.js50450666editdlrm
prefer-read-only-props.d.ts1290666editdlrm
prefer-read-only-props.d.ts.map1670666editdlrm
prefer-read-only-props.js30690666editdlrm
prefer-stateless-function.d.ts1320666editdlrm
prefer-stateless-function.d.ts.map1730666editdlrm
prefer-stateless-function.js129520666editdlrm
prop-types.d.ts1170666editdlrm
prop-types.d.ts.map1430666editdlrm
prop-types.js74170666editdlrm
react-in-jsx-scope.d.ts1250666editdlrm
react-in-jsx-scope.d.ts.map1590666editdlrm
react-in-jsx-scope.js13280666editdlrm
require-default-props.d.ts1280666editdlrm
require-default-props.d.ts.map1650666editdlrm
require-default-props.js73610666editdlrm
require-optimization.d.ts1270666editdlrm
require-optimization.d.ts.map1630666editdlrm
require-optimization.js70760666editdlrm
require-render-return.d.ts1280666editdlrm
require-render-return.d.ts.map1650666editdlrm
require-render-return.js32370666editdlrm
self-closing-comp.d.ts1240666editdlrm
self-closing-comp.d.ts.map1570666editdlrm
self-closing-comp.js29300666editdlrm
sort-comp.d.ts1160666editdlrm
sort-comp.d.ts.map1410666editdlrm
sort-comp.js137330666editdlrm
sort-default-props.d.ts1250666editdlrm
sort-default-props.d.ts.map1590666editdlrm
sort-default-props.js52330666editdlrm
sort-prop-types.d.ts1220666editdlrm
sort-prop-types.d.ts.map1530666editdlrm
sort-prop-types.js101550666editdlrm
state-in-constructor.d.ts1270666editdlrm
state-in-constructor.d.ts.map1630666editdlrm
state-in-constructor.js19210666editdlrm
static-property-placement.d.ts1320666editdlrm
static-property-placement.d.ts.map1730666editdlrm
static-property-placement.js67340666editdlrm
style-prop-object.d.ts1240666editdlrm
style-prop-object.d.ts.map1570666editdlrm
style-prop-object.js41340666editdlrm
void-dom-elements-no-children.d.ts1360666editdlrm
void-dom-elements-no-children.d.ts.map1810666editdlrm
void-dom-elements-no-children.js41330666editdlrm
Edit: /home/techb158/balavpn.abdallabala.com/node_modules/eslint-plugin-react/lib/rules/jsx-indent.js (14681B)
/** * @fileoverview Validate JSX indentation * @author Yannick Croissant * This rule has been ported and modified from eslint and nodeca. * @author Vitaly Puzrin * @author Gyandeep Singh * @copyright 2015 Vitaly Puzrin. All rights reserved. * @copyright 2015 Gyandeep Singh. All rights reserved. Copyright (C) 2014 by Vitaly Puzrin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 'use strict'; const matchAll = require('string.prototype.matchall'); const repeat = require('string.prototype.repeat'); const astUtil = require('../util/ast'); const docsUrl = require('../util/docsUrl'); const reportC = require('../util/report'); const jsxUtil = require('../util/jsx'); const eslintUtil = require('../util/eslint'); const getSourceCode = eslintUtil.getSourceCode; const getText = eslintUtil.getText; // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ const messages = { wrongIndent: 'Expected indentation of {{needed}} {{type}} {{characters}} but found {{gotten}}.', }; /** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { docs: { description: 'Enforce JSX indentation', category: 'Stylistic Issues', recommended: false, url: docsUrl('jsx-indent'), }, fixable: 'whitespace', messages, schema: [{ anyOf: [{ enum: ['tab'], }, { type: 'integer', }], }, { type: 'object', properties: { checkAttributes: { type: 'boolean', }, indentLogicalExpressions: { type: 'boolean', }, }, additionalProperties: false, }], }, create(context) { const extraColumnStart = 0; let indentType = 'space'; let indentSize = 4; if (context.options.length) { if (context.options[0] === 'tab') { indentSize = 1; indentType = 'tab'; } else if (typeof context.options[0] === 'number') { indentSize = context.options[0]; indentType = 'space'; } } const indentChar = indentType === 'space' ? ' ' : '\t'; const options = context.options[1] || {}; const checkAttributes = options.checkAttributes || false; const indentLogicalExpressions = options.indentLogicalExpressions || false; /** * Responsible for fixing the indentation issue fix * @param {ASTNode} node Node violating the indent rule * @param {number} needed Expected indentation character count * @returns {Function} function to be executed by the fixer * @private */ function getFixerFunction(node, needed) { const indent = repeat(indentChar, needed); if (node.type === 'JSXText' || node.type === 'Literal') { return function fix(fixer) { const regExp = /\n[\t ]*(\S)/g; const fixedText = node.raw.replace(regExp, (match, p1) => `\n${indent}${p1}`); return fixer.replaceText(node, fixedText); }; } if (node.type === 'ReturnStatement') { const raw = getText(context, node); const lines = raw.split('\n'); if (lines.length > 1) { return function fix(fixer) { const lastLineStart = raw.lastIndexOf('\n'); const lastLine = raw.slice(lastLineStart).replace(/^\n[\t ]*(\S)/, (match, p1) => `\n${indent}${p1}`); return fixer.replaceTextRange( [node.range[0] + lastLineStart, node.range[1]], lastLine ); }; } } return function fix(fixer) { return fixer.replaceTextRange( [node.range[0] - node.loc.start.column, node.range[0]], indent ); }; } /** * Reports a given indent violation and properly pluralizes the message * @param {ASTNode} node Node violating the indent rule * @param {number} needed Expected indentation character count * @param {number} gotten Indentation character count in the actual node/code * @param {Object} [loc] Error line and column location */ function report(node, needed, gotten, loc) { const msgContext = { needed, type: indentType, characters: needed === 1 ? 'character' : 'characters', gotten, }; reportC(context, messages.wrongIndent, 'wrongIndent', Object.assign({ node, data: msgContext, fix: getFixerFunction(node, needed), }, loc && { loc })); } /** * Get node indent * @param {ASTNode} node Node to examine * @param {boolean} [byLastLine] get indent of node's last line * @param {boolean} [excludeCommas] skip comma on start of line * @return {number} Indent */ function getNodeIndent(node, byLastLine, excludeCommas) { let src = getText(context, node, node.loc.start.column + extraColumnStart); const lines = src.split('\n'); if (byLastLine) { src = lines[lines.length - 1]; } else { src = lines[0]; } const skip = excludeCommas ? ',' : ''; let regExp; if (indentType === 'space') { regExp = new RegExp(`^[ ${skip}]+`); } else { regExp = new RegExp(`^[\t${skip}]+`); } const indent = regExp.exec(src); return indent ? indent[0].length : 0; } /** * Check if the node is the right member of a logical expression * @param {ASTNode} node The node to check * @return {boolean} true if its the case, false if not */ function isRightInLogicalExp(node) { return ( node.parent && node.parent.parent && node.parent.parent.type === 'LogicalExpression' && node.parent.parent.right === node.parent && !indentLogicalExpressions ); } /** * Check if the node is the alternate member of a conditional expression * @param {ASTNode} node The node to check * @return {boolean} true if its the case, false if not */ function isAlternateInConditionalExp(node) { return ( node.parent && node.parent.parent && node.parent.parent.type === 'ConditionalExpression' && node.parent.parent.alternate === node.parent && getSourceCode(context).getTokenBefore(node).value !== '(' ); } /** * Check if the node is within a DoExpression block but not the first expression (which need to be indented) * @param {ASTNode} node The node to check * @return {boolean} true if its the case, false if not */ function isSecondOrSubsequentExpWithinDoExp(node) { /* It returns true when node.parent.parent.parent.parent matches: DoExpression({ ..., body: BlockStatement({ ..., body: [ ..., // 1-n times ExpressionStatement({ ..., expression: JSXElement({ ..., openingElement: JSXOpeningElement() // the node }) }), ... // 0-n times ] }) }) except: DoExpression({ ..., body: BlockStatement({ ..., body: [ ExpressionStatement({ ..., expression: JSXElement({ ..., openingElement: JSXOpeningElement() // the node }) }), ... // 0-n times ] }) }) */ const isInExpStmt = ( node.parent && node.parent.parent && node.parent.parent.type === 'ExpressionStatement' ); if (!isInExpStmt) { return false; } const expStmt = node.parent.parent; const isInBlockStmtWithinDoExp = ( expStmt.parent && expStmt.parent.type === 'BlockStatement' && expStmt.parent.parent && expStmt.parent.parent.type === 'DoExpression' ); if (!isInBlockStmtWithinDoExp) { return false; } const blockStmt = expStmt.parent; const blockStmtFirstExp = blockStmt.body[0]; return !(blockStmtFirstExp === expStmt); } /** * Check indent for nodes list * @param {ASTNode} node The node to check * @param {number} indent needed indent * @param {boolean} [excludeCommas] skip comma on start of line */ function checkNodesIndent(node, indent, excludeCommas) { const nodeIndent = getNodeIndent(node, false, excludeCommas); const isCorrectRightInLogicalExp = isRightInLogicalExp(node) && (nodeIndent - indent) === indentSize; const isCorrectAlternateInCondExp = isAlternateInConditionalExp(node) && (nodeIndent - indent) === 0; if ( nodeIndent !== indent && astUtil.isNodeFirstInLine(context, node) && !isCorrectRightInLogicalExp && !isCorrectAlternateInCondExp ) { report(node, indent, nodeIndent); } } /** * Check indent for Literal Node or JSXText Node * @param {ASTNode} node The node to check * @param {number} indent needed indent */ function checkLiteralNodeIndent(node, indent) { const value = node.value; const regExp = indentType === 'space' ? /\n( *)[\t ]*\S/g : /\n(\t*)[\t ]*\S/g; const nodeIndentsPerLine = Array.from( matchAll(String(value), regExp), (match) => (match[1] ? match[1].length : 0) ); const hasFirstInLineNode = nodeIndentsPerLine.length > 0; if ( hasFirstInLineNode && !nodeIndentsPerLine.every((actualIndent) => actualIndent === indent) ) { nodeIndentsPerLine.forEach((nodeIndent) => { report(node, indent, nodeIndent); }); } } function handleOpeningElement(node) { const sourceCode = getSourceCode(context); let prevToken = sourceCode.getTokenBefore(node); if (!prevToken) { return; } // Use the parent in a list or an array if (prevToken.type === 'JSXText' || ((prevToken.type === 'Punctuator') && prevToken.value === ',')) { prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]); prevToken = prevToken.type === 'Literal' || prevToken.type === 'JSXText' ? prevToken.parent : prevToken; // Use the first non-punctuator token in a conditional expression } else if (prevToken.type === 'Punctuator' && prevToken.value === ':') { do { prevToken = sourceCode.getTokenBefore(prevToken); } while (prevToken.type === 'Punctuator' && prevToken.value !== '/'); prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]); while (prevToken.parent && prevToken.parent.type !== 'ConditionalExpression') { prevToken = prevToken.parent; } } prevToken = prevToken.type === 'JSXExpressionContainer' ? prevToken.expression : prevToken; const parentElementIndent = getNodeIndent(prevToken); const indent = ( prevToken.loc.start.line === node.loc.start.line || isRightInLogicalExp(node) || isAlternateInConditionalExp(node) || isSecondOrSubsequentExpWithinDoExp(node) ) ? 0 : indentSize; checkNodesIndent(node, parentElementIndent + indent); } function handleClosingElement(node) { if (!node.parent) { return; } const peerElementIndent = getNodeIndent(node.parent.openingElement || node.parent.openingFragment); checkNodesIndent(node, peerElementIndent); } function handleAttribute(node) { if (!checkAttributes || (!node.value || node.value.type !== 'JSXExpressionContainer')) { return; } const nameIndent = getNodeIndent(node.name); const lastToken = getSourceCode(context).getLastToken(node.value); const firstInLine = astUtil.getFirstNodeInLine(context, lastToken); const indent = node.name.loc.start.line === firstInLine.loc.start.line ? 0 : nameIndent; checkNodesIndent(firstInLine, indent); } function handleLiteral(node) { if (!node.parent) { return; } if (node.parent.type !== 'JSXElement' && node.parent.type !== 'JSXFragment') { return; } const parentNodeIndent = getNodeIndent(node.parent); checkLiteralNodeIndent(node, parentNodeIndent + indentSize); } return { JSXOpeningElement: handleOpeningElement, JSXOpeningFragment: handleOpeningElement, JSXClosingElement: handleClosingElement, JSXClosingFragment: handleClosingElement, JSXAttribute: handleAttribute, JSXExpressionContainer(node) { if (!node.parent) { return; } const parentNodeIndent = getNodeIndent(node.parent); checkNodesIndent(node, parentNodeIndent + indentSize); }, Literal: handleLiteral, JSXText: handleLiteral, ReturnStatement(node) { if ( !node.parent || !jsxUtil.isJSX(node.argument) ) { return; } let fn = node.parent; while (fn && fn.type !== 'FunctionDeclaration' && fn.type !== 'FunctionExpression') { fn = fn.parent; } if ( !fn || !jsxUtil.isReturningJSX(context, node, true) ) { return; } const openingIndent = getNodeIndent(node); const closingIndent = getNodeIndent(node, true); if (openingIndent !== closingIndent) { report(node, openingIndent, closingIndent); } }, }; }, };