eslint-codemod-utils
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -6,5 +6,8 @@ "use strict"; | ||
const nodes_1 = require("./nodes"); | ||
const ts_nodes_1 = require("./ts-nodes"); | ||
const identity_1 = require("./utils/identity"); | ||
exports.DEFAULT_WHITESPACE = '\n '; | ||
exports.typeToHelperLookup = new Proxy({ | ||
exports.typeToHelperLookup = new Proxy( | ||
// @ts-expect-error | ||
{ | ||
// TODO implement | ||
@@ -109,2 +112,6 @@ AssignmentProperty: identity_1.identity, | ||
YieldExpression: nodes_1.yieldExpression, | ||
// typescript | ||
TSAsExpression: ts_nodes_1.tsAsExpression, | ||
TSStringKeyword: ts_nodes_1.tsStringKeyword, | ||
TSTypeReference: ts_nodes_1.tsTypeReference, | ||
}, { | ||
@@ -116,4 +123,13 @@ // dynamic getter will fail and provide debug information | ||
} | ||
throw new Error(`ecu: key ${name.toString()} missing in typeMap`); | ||
const nodeName = name.toString(); | ||
throw new Error(`\ | ||
eslint-codemod-utils: type '${nodeName}' missing in typeMap. | ||
This is probably because the type '${nodeName}' is a Typescript or Flow specific node type. These nodes currently have only partial support. | ||
To resolve this you can: | ||
* Use a more constrained parser like esprima in your eslint config | ||
* Lodge a bug at https://github.com/DarkPurple141/eslint-codemod-utils/issues | ||
`); | ||
}, | ||
}); |
@@ -5,4 +5,5 @@ /** constants has to be first so that it resolves the map */ | ||
export * from './jsx-nodes'; | ||
export * from './ts-nodes'; | ||
export * from './utils'; | ||
export * from './types'; | ||
export type { JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXOpeningElement, JSXOpeningFragment, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXText, JSXSpreadChild, ExpressionStatement, BlockStatement, StaticBlock, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, Declaration, Identifier, Literal, Program, Function, FunctionDeclaration, SwitchCase, CatchClause, VariableDeclarator, Statement, Expression, PrivateIdentifier, Property, PropertyDefinition, AssignmentProperty, Super, TemplateElement, SpreadElement, Pattern, ClassBody, Class, MethodDefinition, ModuleDeclaration, ModuleSpecifier, ThisExpression, ArrayExpression, ObjectExpression, FunctionExpression, ArrowFunctionExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, } from 'estree-jsx'; |
@@ -17,3 +17,4 @@ "use strict"; | ||
__exportStar(require("./jsx-nodes"), exports); | ||
__exportStar(require("./ts-nodes"), exports); | ||
__exportStar(require("./utils"), exports); | ||
__exportStar(require("./types"), exports); |
@@ -162,6 +162,5 @@ "use strict"; | ||
toString: () => `return${argument | ||
? // @ts-expect-error | ||
argument.type === 'JSXElement' | ||
? ` (${constants_1.DEFAULT_WHITESPACE}${(0, node_1.node)(argument)}${constants_1.DEFAULT_WHITESPACE})` | ||
: ` ${(0, node_1.node)(argument)}` | ||
? argument.type === 'JSXElement' | ||
? ` (${constants_1.DEFAULT_WHITESPACE}${(0, node_1.node)(argument)}${constants_1.DEFAULT_WHITESPACE})` | ||
: ` ${(0, node_1.node)(argument)}` | ||
: ''};`, | ||
@@ -168,0 +167,0 @@ }; |
import type { Node as BaseNode, JSXSpreadChild } from 'estree-jsx'; | ||
import type { AST_NODE_TYPES, BaseNode as RawTSBaseNode } from '@typescript-eslint/types/dist/generated/ast-spec'; | ||
import type { Rule } from 'eslint'; | ||
export declare type EslintCodemodUtilsBaseNode = BaseNode | JSXSpreadChild; | ||
declare type TSBaseNode = RawTSBaseNode | { | ||
type: keyof typeof AST_NODE_TYPES; | ||
}; | ||
export declare type EslintCodemodUtilsBaseNode = BaseNode | JSXSpreadChild | TSBaseNode; | ||
export declare type WithoutType<T extends EslintCodemodUtilsBaseNode> = Omit<T, 'type'>; | ||
@@ -13,1 +17,2 @@ export declare type RuleListener<T extends EslintNode = EslintNode> = { | ||
export declare type EslintNode = Partial<Rule.NodeParentExtension> & EslintCodemodUtilsBaseNode; | ||
export {}; |
import type { EslintNode } from '../types'; | ||
export declare function closestOfType<T extends EslintNode, K extends EslintNode['type']>(node: T, type: K): Extract<EslintNode, { | ||
type: K; | ||
export declare function closestOfType<NodeType extends EslintNode['type']>(node: EslintNode, type: NodeType): Extract<EslintNode, { | ||
type: NodeType; | ||
}> | null; |
import { jsxAttribute, jsxClosingElement, jsxClosingFragment, jsxElement, jsxEmptyExpression, jsxExpressionContainer, jsxFragment, jsxIdentifier, jsxMemberExpression, jsxOpeningElement, jsxOpeningFragment, jsxSpreadAttribute, jsxSpreadChild, jsxText, } from './jsx-nodes'; | ||
import { arrayExpression, arrayPattern, arrowFunctionExpression, assignmentExpression, awaitExpression, binaryExpression, blockStatement, breakStatement, callExpression, catchClause, chainExpression, classBody, classDeclaration, classExpression, conditionalExpression, continueStatement, debuggerStatement, doWhileStatement, emptyStatement, exportAllDeclaration, exportDefaultDeclaration, exportNamedDeclaration, exportSpecifier, expressionStatement, forInStatement, forOfStatement, forStatement, functionDeclaration, functionExpression, identifier, ifStatement, importDeclaration, importDefaultSpecifier, importExpression, importNamespaceSpecifier, importSpecifier, literal, logicalExpression, memberExpression, methodDefinition, newExpression, objectExpression, objectPattern, program, property, propertyDefinition, returnStatement, sequenceExpression, spreadElement, staticBlock, switchCase, switchStatement, taggedTemplateExpression, templateElement, templateLiteral, thisExpression, throwStatement, tryStatement, unaryExpression, updateExpression, variableDeclaration, variableDeclarator, whileStatement, withStatement, yieldExpression, } from './nodes'; | ||
import { tsAsExpression, tsStringKeyword, tsTypeReference } from './ts-nodes'; | ||
import { identity } from './utils/identity'; | ||
export const DEFAULT_WHITESPACE = '\n '; | ||
export const typeToHelperLookup = new Proxy({ | ||
export const typeToHelperLookup = new Proxy( | ||
// @ts-expect-error | ||
{ | ||
// TODO implement | ||
@@ -105,2 +108,6 @@ AssignmentProperty: identity, | ||
YieldExpression: yieldExpression, | ||
// typescript | ||
TSAsExpression: tsAsExpression, | ||
TSStringKeyword: tsStringKeyword, | ||
TSTypeReference: tsTypeReference, | ||
}, { | ||
@@ -112,4 +119,13 @@ // dynamic getter will fail and provide debug information | ||
} | ||
throw new Error(`ecu: key ${name.toString()} missing in typeMap`); | ||
const nodeName = name.toString(); | ||
throw new Error(`\ | ||
eslint-codemod-utils: type '${nodeName}' missing in typeMap. | ||
This is probably because the type '${nodeName}' is a Typescript or Flow specific node type. These nodes currently have only partial support. | ||
To resolve this you can: | ||
* Use a more constrained parser like esprima in your eslint config | ||
* Lodge a bug at https://github.com/DarkPurple141/eslint-codemod-utils/issues | ||
`); | ||
}, | ||
}); |
@@ -5,4 +5,5 @@ /** constants has to be first so that it resolves the map */ | ||
export * from './jsx-nodes'; | ||
export * from './ts-nodes'; | ||
export * from './utils'; | ||
export * from './types'; | ||
export type { JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXOpeningElement, JSXOpeningFragment, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXText, JSXSpreadChild, ExpressionStatement, BlockStatement, StaticBlock, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, Declaration, Identifier, Literal, Program, Function, FunctionDeclaration, SwitchCase, CatchClause, VariableDeclarator, Statement, Expression, PrivateIdentifier, Property, PropertyDefinition, AssignmentProperty, Super, TemplateElement, SpreadElement, Pattern, ClassBody, Class, MethodDefinition, ModuleDeclaration, ModuleSpecifier, ThisExpression, ArrayExpression, ObjectExpression, FunctionExpression, ArrowFunctionExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, } from 'estree-jsx'; |
@@ -5,3 +5,4 @@ /** constants has to be first so that it resolves the map */ | ||
export * from './jsx-nodes'; | ||
export * from './ts-nodes'; | ||
export * from './utils'; | ||
export * from './types'; |
@@ -150,6 +150,5 @@ import { node } from './utils/node'; | ||
toString: () => `return${argument | ||
? // @ts-expect-error | ||
argument.type === 'JSXElement' | ||
? ` (${DEFAULT_WHITESPACE}${node(argument)}${DEFAULT_WHITESPACE})` | ||
: ` ${node(argument)}` | ||
? argument.type === 'JSXElement' | ||
? ` (${DEFAULT_WHITESPACE}${node(argument)}${DEFAULT_WHITESPACE})` | ||
: ` ${node(argument)}` | ||
: ''};`, | ||
@@ -156,0 +155,0 @@ }; |
import type { Node as BaseNode, JSXSpreadChild } from 'estree-jsx'; | ||
import type { AST_NODE_TYPES, BaseNode as RawTSBaseNode } from '@typescript-eslint/types/dist/generated/ast-spec'; | ||
import type { Rule } from 'eslint'; | ||
export declare type EslintCodemodUtilsBaseNode = BaseNode | JSXSpreadChild; | ||
declare type TSBaseNode = RawTSBaseNode | { | ||
type: keyof typeof AST_NODE_TYPES; | ||
}; | ||
export declare type EslintCodemodUtilsBaseNode = BaseNode | JSXSpreadChild | TSBaseNode; | ||
export declare type WithoutType<T extends EslintCodemodUtilsBaseNode> = Omit<T, 'type'>; | ||
@@ -13,1 +17,2 @@ export declare type RuleListener<T extends EslintNode = EslintNode> = { | ||
export declare type EslintNode = Partial<Rule.NodeParentExtension> & EslintCodemodUtilsBaseNode; | ||
export {}; |
import type { EslintNode } from '../types'; | ||
export declare function closestOfType<T extends EslintNode, K extends EslintNode['type']>(node: T, type: K): Extract<EslintNode, { | ||
type: K; | ||
export declare function closestOfType<NodeType extends EslintNode['type']>(node: EslintNode, type: NodeType): Extract<EslintNode, { | ||
type: NodeType; | ||
}> | null; |
{ | ||
"name": "eslint-codemod-utils", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "A collection of AST helper functions for more complex ESLint rule fixes.", | ||
@@ -25,3 +25,4 @@ "author": "Alex Hinds", | ||
"dependencies": { | ||
"@types/estree-jsx": "^0.0.1" | ||
"@types/estree-jsx": "^1.0.0", | ||
"@typescript-eslint/types": "^5.45.0" | ||
}, | ||
@@ -31,2 +32,3 @@ "devDependencies": { | ||
"@types/node": "^17.0.18", | ||
"@typescript-eslint/typescript-estree": "^5.45.0", | ||
"espree": "^9.3.1", | ||
@@ -33,0 +35,0 @@ "typescript": "^4.5.5", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
562478
77
15407
2
6
+ Added@types/estree-jsx@1.0.5(transitive)
+ Added@typescript-eslint/types@5.62.0(transitive)
- Removed@types/estree-jsx@0.0.1(transitive)
Updated@types/estree-jsx@^1.0.0