@putout/printer
Advanced tools
| import { | ||
| isCoupleLines, | ||
| isIdentifierAndIdentifier, | ||
| isStringAndIdentifier, | ||
| } from '#is'; | ||
@@ -13,4 +12,3 @@ import {createTypeChecker} from '#type-checker'; | ||
| ['+', isIdentifierAndIdentifier], | ||
| ['-: -> !', isStringAndIdentifier], | ||
| ['+', isInsideOneElementArray], | ||
| ]); |
@@ -6,3 +6,2 @@ import {createTypeChecker} from '#type-checker'; | ||
| isInsideArray, | ||
| isStringAndIdentifier, | ||
| } from '#is'; | ||
@@ -15,7 +14,2 @@ | ||
| const isStringAndIdentifierInsideOneElementArray = createTypeChecker([ | ||
| ['-: -> !', isStringAndIdentifier], | ||
| ['+', isInsideOneElementArray], | ||
| ]); | ||
| export const beforeIf = createTypeChecker([ | ||
@@ -25,3 +19,3 @@ ['-: -> !', isInsideArray], | ||
| ['+', isIdentifierAndIdentifier], | ||
| ['+', isStringAndIdentifierInsideOneElementArray], | ||
| ['+', isInsideOneElementArray], | ||
| ]); |
@@ -112,3 +112,2 @@ import {types} from '@putout/babel'; | ||
| ['+', isNeedsToHideIndentOption], | ||
| ['-: ->', isArrayInsideArray], | ||
| ['+: -> !', isLastElementObjectExpression], | ||
@@ -115,0 +114,0 @@ ]); |
@@ -18,2 +18,16 @@ import {isSimple} from '@putout/operate'; | ||
| const { | ||
| isObjectExpression, | ||
| isObjectProperty, | ||
| isCallExpression, | ||
| isAwaitExpression, | ||
| isBooleanLiteral, | ||
| isNullLiteral, | ||
| isStringLiteral, | ||
| isSpreadElement, | ||
| isIdentifier, | ||
| isNumericLiteral, | ||
| isArrayExpression, | ||
| } = types; | ||
| const isParentProperty = (path) => path.find(isObjectProperty); | ||
@@ -74,15 +88,2 @@ | ||
| const { | ||
| isObjectExpression, | ||
| isObjectProperty, | ||
| isCallExpression, | ||
| isAwaitExpression, | ||
| isBooleanLiteral, | ||
| isNullLiteral, | ||
| isStringLiteral, | ||
| isSpreadElement, | ||
| isIdentifier, | ||
| isNumericLiteral, | ||
| } = types; | ||
| const {round} = Math; | ||
@@ -143,8 +144,9 @@ | ||
| const {elements} = path.node; | ||
| const [first] = elements; | ||
| if (!isStringLiteral(first)) | ||
| return false; | ||
| for (const element of elements.filter(isStringLiteral)) { | ||
| if (element.value.length >= maxElementLengthInOneLine) | ||
| return true; | ||
| } | ||
| return first.value.length > maxElementLengthInOneLine; | ||
| return false; | ||
| }; | ||
@@ -203,4 +205,45 @@ | ||
| const isLengthLessTheMax = (length, {maxElementsInOneLine}) => length <= maxElementsInOneLine; | ||
| const isAllStrings = (path) => { | ||
| const {elements} = path.node; | ||
| const {length} = elements.filter(isStringLiteral); | ||
| return elements.length === length; | ||
| }; | ||
| const isTupleInsideArray = createTypeChecker([ | ||
| ['-: parentPath -> !ArrayExpression'], | ||
| ['-: -> !', isAllStrings], | ||
| ['-', isMoreThenMaxLiteralLength], | ||
| ['+: node.elements.length', isLengthLessTheMax], | ||
| ]); | ||
| const isMixedTuples = (path, {maxElementLengthInOneLine}) => { | ||
| const elements = path.get('elements'); | ||
| const arrayElements = elements.filter(isArrayExpression); | ||
| const {length} = arrayElements; | ||
| if (!length) | ||
| return false; | ||
| if (isObjectProperty(path.parentPath)) | ||
| return false; | ||
| for (const arrayElement of arrayElements) { | ||
| if (isMoreThenMaxLiteralLength(arrayElement, {maxElementLengthInOneLine})) | ||
| return false; | ||
| if (isAllStrings(arrayElement)) | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
| export const isMultiLine = createTypeChecker([ | ||
| ['-: node.elements.length -> -'], | ||
| ['-', isTupleInsideArray], | ||
| ['+', isMixedTuples], | ||
| ['+', isBodyWithOneElement], | ||
@@ -214,3 +257,2 @@ ['+', isMoreThenMaxElementLengthInOneLine], | ||
| ['-', isIdentifierAndIdentifier], | ||
| ['-', isCallInsideArrow], | ||
| ['-', isIncreaseIndent], | ||
@@ -276,3 +318,3 @@ ['-', isInsideLoop], | ||
| function tooLong(path) { | ||
| function tooLong(path, {maxElementLengthInOneLine}) { | ||
| const elements = path.get('elements'); | ||
@@ -284,3 +326,3 @@ | ||
| for (const el of path.get('elements')) { | ||
| if (el.isStringLiteral() && el.node.value.length > 4) | ||
| if (el.isStringLiteral() && el.node.value.length > maxElementLengthInOneLine) | ||
| return true; | ||
@@ -292,14 +334,2 @@ } | ||
| function isCallInsideArrow(path) { | ||
| const {parentPath} = path; | ||
| if (!parentPath.isCallExpression()) | ||
| return false; | ||
| if (!parentPath.parentPath.isFunction()) | ||
| return false; | ||
| return path.node.elements.length < 4; | ||
| } | ||
| function isNumbers(elements) { | ||
@@ -306,0 +336,0 @@ for (const element of elements) { |
| import {types} from '@putout/babel'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| import { | ||
| isFirstArgOfCall, | ||
| isLastArgInCall, | ||
| } from '#is'; | ||
| import {chain} from '../chain.js'; | ||
@@ -21,22 +25,2 @@ import {checkCallsCount} from './check-calls-count.js'; | ||
| const isPathFirstArg = ({node, parentPath}) => { | ||
| const [first] = parentPath.node.arguments; | ||
| return node === first; | ||
| }; | ||
| function isPathLastArg({node, parentPath}) { | ||
| const last = parentPath.node.arguments.at(-1); | ||
| return node === last; | ||
| } | ||
| const isFirstArgOfCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathFirstArg], | ||
| ]); | ||
| const isLastArgInCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathLastArg], | ||
| ]); | ||
| const callWithRoot = (fn) => (a, {root}) => fn(root); | ||
@@ -43,0 +27,0 @@ |
@@ -28,2 +28,1 @@ import {types} from '@putout/babel'; | ||
| ]); | ||
| import {types} from '@putout/babel'; | ||
| import {isCoupleLines, exists} from '#is'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| import { | ||
| isCoupleLines, | ||
| exists, | ||
| callWithPrev, | ||
| callWithNext, | ||
| } from '#is'; | ||
| import {hasAssign} from './has.js'; | ||
| const { | ||
| isObjectExpression, | ||
| isAssignmentPattern, | ||
| isFunction, | ||
@@ -40,25 +44,7 @@ isVariableDeclarator, | ||
| export function isPrevAssignObject(path) { | ||
| const prev = path.getPrevSibling(); | ||
| if (!isAssignmentPattern(prev.node.value)) | ||
| return false; | ||
| const {right} = prev.node.value; | ||
| return isObjectExpression(right); | ||
| } | ||
| export const isPrevAssignObject = callWithPrev(createTypeChecker([ | ||
| '-: node.value -> !AssignmentPattern', | ||
| '+: node.value.right -> ObjectExpression', | ||
| ])); | ||
| export function isNextAssignObject(path) { | ||
| const next = path.getNextSibling(); | ||
| if (!next.node) | ||
| return false; | ||
| if (!isAssignmentPattern(next.node.value)) | ||
| return false; | ||
| const {right} = next.node.value; | ||
| return isObjectExpression(right); | ||
| } | ||
| export const isNextAssignObject = callWithNext(createTypeChecker(['-: node -> -', '-: node.value -> !AssignmentPattern', '+: node.value.right -> ObjectExpression'])); |
@@ -131,2 +131,1 @@ import {wrongShorthand} from './wrong-shorthand.js'; | ||
| }; | ||
+21
-0
| import {types} from '@putout/babel'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
@@ -205,1 +206,21 @@ const { | ||
| export const noTrailingComment = (path) => !path.node.trailingComments?.length; | ||
| const isPathFirstArg = ({node, parentPath}) => { | ||
| const [first] = parentPath.node.arguments; | ||
| return node === first; | ||
| }; | ||
| function isPathLastArg({node, parentPath}) { | ||
| const last = parentPath.node.arguments.at(-1); | ||
| return node === last; | ||
| } | ||
| export const isFirstArgOfCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathFirstArg], | ||
| ]); | ||
| export const isLastArgInCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathLastArg], | ||
| ]); |
@@ -35,3 +35,3 @@ import {parseRoundBraces} from './parse-round-braces.js'; | ||
| maxSpecifiersInOneLine: 2, | ||
| maxElementsInOneLine: 5, | ||
| maxElementsInOneLine: 3, | ||
| maxElementLengthInOneLine: 15, | ||
@@ -38,0 +38,0 @@ maxLogicalsInOneLine: 3, |
+1
-1
| { | ||
| "name": "@putout/printer", | ||
| "version": "18.7.9", | ||
| "version": "18.8.0", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
326561
0.25%6822
0.19%