eslint-codemod-utils
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -23,3 +23,3 @@ "use strict"; | ||
const espree = __importStar(require("espree")); | ||
const utils_1 = require("../utils"); | ||
const __1 = require(".."); | ||
const ESPREE_OPTIONS = { | ||
@@ -36,3 +36,3 @@ ecmaVersion: 2015, | ||
const program = espree.parse('<Hello name="world"></Hello>', ESPREE_OPTIONS); | ||
expect((0, utils_1.closestOfType)(program.body[0].expression.openingElement, 'JSXElement')).toHaveProperty('type', 'JSXElement'); | ||
expect((0, __1.closestOfType)(program.body[0].expression.openingElement, 'JSXElement')).toHaveProperty('type', 'JSXElement'); | ||
}); | ||
@@ -43,11 +43,11 @@ }); | ||
const { body } = espree.parse('<Hello name="world"></Hello>', ESPREE_OPTIONS); | ||
expect((0, utils_1.hasJSXAttribute)(body[0].expression, 'name')).to.be.true; | ||
expect((0, __1.hasJSXAttribute)(body[0].expression, 'name')).to.be.true; | ||
}); | ||
test('no attribute on jsx', () => { | ||
const { body } = espree.parse('<Hello></Hello>', ESPREE_OPTIONS); | ||
expect((0, utils_1.hasJSXAttribute)(body[0].expression, 'name')).to.be.false; | ||
expect((0, __1.hasJSXAttribute)(body[0].expression, 'name')).to.be.false; | ||
}); | ||
test('is not jsx', () => { | ||
const { body } = espree.parse('1 + 1', ESPREE_OPTIONS); | ||
expect((0, utils_1.hasJSXAttribute)(body[0].expression, 'name')).to.be.false; | ||
expect((0, __1.hasJSXAttribute)(body[0].expression, 'name')).to.be.false; | ||
}); | ||
@@ -58,11 +58,11 @@ }); | ||
const { body } = espree.parse(`import x from 'place'`, ESPREE_OPTIONS); | ||
expect((0, utils_1.insertImportSpecifier)(body[0], 'name').toString()).eq(`import x, { name } from 'place'`); | ||
expect((0, __1.insertImportSpecifier)(body[0], 'name').toString()).eq(`import x, { name } from 'place'`); | ||
}); | ||
test('no default', () => { | ||
const { body } = espree.parse(`import { nothing } from 'place'`, ESPREE_OPTIONS); | ||
expect((0, utils_1.insertImportSpecifier)(body[0], 'name').toString()).eq(`import { nothing, name } from 'place'`); | ||
expect((0, __1.insertImportSpecifier)(body[0], 'name').toString()).eq(`import { nothing, name } from 'place'`); | ||
}); | ||
test('with alias', () => { | ||
const { body } = espree.parse(`import x from 'place'`, ESPREE_OPTIONS); | ||
expect((0, utils_1.insertImportSpecifier)(body[0], 'name', 'alias').toString()).eq(`import x, { name as alias } from 'place'`); | ||
expect((0, __1.insertImportSpecifier)(body[0], 'name', 'alias').toString()).eq(`import x, { name as alias } from 'place'`); | ||
}); | ||
@@ -73,8 +73,18 @@ }); | ||
const { body } = espree.parse(`import { nothing, name } from 'place'`, ESPREE_OPTIONS); | ||
expect((0, utils_1.removeImportSpecifier)(body[0], 'name').toString()).eq(`import { nothing } from 'place'`); | ||
expect((0, __1.removeImportSpecifier)(body[0], 'name').toString()).eq(`import { nothing } from 'place'`); | ||
}); | ||
test('with alias', () => { | ||
const { body } = espree.parse(`import x, { name as alias } from 'place'`, ESPREE_OPTIONS); | ||
expect((0, utils_1.removeImportSpecifier)(body[0], 'name').toString()).eq(`import x from 'place'`); | ||
expect((0, __1.removeImportSpecifier)(body[0], 'name').toString()).eq(`import x from 'place'`); | ||
}); | ||
}); | ||
describe('insertJSXAttribute', () => { | ||
test('basic', () => { | ||
const { body } = espree.parse(`<Hello />`, ESPREE_OPTIONS); | ||
expect((0, __1.insertJSXAttribute)(body[0].expression, 'hello', (0, __1.literal)('world')).toString()).eq(`<Hello hello='world' />`); | ||
}); | ||
test('with closing', () => { | ||
const { body } = espree.parse(`<Hello></Hello>`, ESPREE_OPTIONS); | ||
expect((0, __1.insertJSXAttribute)(body[0].expression, 'hello', (0, __1.literal)('world')).toString()).eq(`<Hello hello='world'></Hello>`); | ||
}); | ||
}); |
@@ -8,2 +8,2 @@ /** constants has to be first so that it resolves the map */ | ||
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, ArrayPattern, AssignmentOperator, AssignmentPattern, ExportAllDeclaration, ClassDeclaration, Comment, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier, ObjectPattern, RestElement, VariableDeclaration, } from 'estree-jsx'; | ||
export type { ArrayExpression, ArrayPattern, ArrowFunctionExpression, AssignmentExpression, AssignmentOperator, AssignmentPattern, AssignmentProperty, AwaitExpression, BigIntLiteral, BinaryExpression, BinaryOperator, BlockStatement, BreakStatement, CallExpression, CatchClause, ChainElement, ChainExpression, Class, ClassBody, ClassDeclaration, ClassExpression, Comment, ConditionalExpression, ContinueStatement, DebuggerStatement, Declaration, Directive, DoWhileStatement, EmptyStatement, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier, Expression, ExpressionMap, ExpressionStatement, ForInStatement, ForOfStatement, ForStatement, Function, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, ImportDeclaration, ImportDefaultSpecifier, ImportExpression, ImportNamespaceSpecifier, ImportSpecifier, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXEmptyExpression, JSXExpressionContainer, JSXFragment, JSXIdentifier, JSXMemberExpression, JSXNamespacedName, JSXOpeningElement, JSXOpeningFragment, JSXSpreadAttribute, JSXSpreadChild, JSXText, LabeledStatement, Literal, LogicalExpression, LogicalOperator, MemberExpression, MetaProperty, MethodDefinition, ModuleDeclaration, ModuleSpecifier, NewExpression, Node, NodeMap, ObjectExpression, ObjectPattern, Pattern, Position, PrivateIdentifier, Program, Property, PropertyDefinition, RegExpLiteral, RestElement, ReturnStatement, SequenceExpression, SimpleCallExpression, SimpleLiteral, SourceLocation, SpreadElement, Statement, StaticBlock, Super, SwitchCase, SwitchStatement, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, ThrowStatement, TryStatement, UnaryExpression, UnaryOperator, UpdateExpression, UpdateOperator, VariableDeclaration, VariableDeclarator, WhileStatement, WithStatement, YieldExpression, } from 'estree-jsx'; |
@@ -8,2 +8,3 @@ export { node } from './node'; | ||
export { closestOfType } from './closest-of-type'; | ||
export { insertJSXAttribute } from './insert-jsx-attribute'; | ||
export * from './utils'; |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.closestOfType = exports.getNodeAfterComment = exports.getFirstCommentInFile = exports.insertAtStartOfFile = exports.getIdentifierInParentScope = exports.isNodeOfType = exports.node = void 0; | ||
exports.insertJSXAttribute = exports.closestOfType = exports.getNodeAfterComment = exports.getFirstCommentInFile = exports.insertAtStartOfFile = exports.getIdentifierInParentScope = exports.isNodeOfType = exports.node = void 0; | ||
var node_1 = require("./node"); | ||
@@ -29,2 +29,4 @@ Object.defineProperty(exports, "node", { enumerable: true, get: function () { return node_1.node; } }); | ||
Object.defineProperty(exports, "closestOfType", { enumerable: true, get: function () { return closest_of_type_1.closestOfType; } }); | ||
var insert_jsx_attribute_1 = require("./insert-jsx-attribute"); | ||
Object.defineProperty(exports, "insertJSXAttribute", { enumerable: true, get: function () { return insert_jsx_attribute_1.insertJSXAttribute; } }); | ||
__exportStar(require("./utils"), exports); |
@@ -8,2 +8,2 @@ /** constants has to be first so that it resolves the map */ | ||
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, ArrayPattern, AssignmentOperator, AssignmentPattern, ExportAllDeclaration, ClassDeclaration, Comment, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier, ObjectPattern, RestElement, VariableDeclaration, } from 'estree-jsx'; | ||
export type { ArrayExpression, ArrayPattern, ArrowFunctionExpression, AssignmentExpression, AssignmentOperator, AssignmentPattern, AssignmentProperty, AwaitExpression, BigIntLiteral, BinaryExpression, BinaryOperator, BlockStatement, BreakStatement, CallExpression, CatchClause, ChainElement, ChainExpression, Class, ClassBody, ClassDeclaration, ClassExpression, Comment, ConditionalExpression, ContinueStatement, DebuggerStatement, Declaration, Directive, DoWhileStatement, EmptyStatement, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier, Expression, ExpressionMap, ExpressionStatement, ForInStatement, ForOfStatement, ForStatement, Function, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, ImportDeclaration, ImportDefaultSpecifier, ImportExpression, ImportNamespaceSpecifier, ImportSpecifier, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXEmptyExpression, JSXExpressionContainer, JSXFragment, JSXIdentifier, JSXMemberExpression, JSXNamespacedName, JSXOpeningElement, JSXOpeningFragment, JSXSpreadAttribute, JSXSpreadChild, JSXText, LabeledStatement, Literal, LogicalExpression, LogicalOperator, MemberExpression, MetaProperty, MethodDefinition, ModuleDeclaration, ModuleSpecifier, NewExpression, Node, NodeMap, ObjectExpression, ObjectPattern, Pattern, Position, PrivateIdentifier, Program, Property, PropertyDefinition, RegExpLiteral, RestElement, ReturnStatement, SequenceExpression, SimpleCallExpression, SimpleLiteral, SourceLocation, SpreadElement, Statement, StaticBlock, Super, SwitchCase, SwitchStatement, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, ThrowStatement, TryStatement, UnaryExpression, UnaryOperator, UpdateExpression, UpdateOperator, VariableDeclaration, VariableDeclarator, WhileStatement, WithStatement, YieldExpression, } from 'estree-jsx'; |
@@ -8,2 +8,3 @@ export { node } from './node'; | ||
export { closestOfType } from './closest-of-type'; | ||
export { insertJSXAttribute } from './insert-jsx-attribute'; | ||
export * from './utils'; |
@@ -8,2 +8,3 @@ export { node } from './node'; | ||
export { closestOfType } from './closest-of-type'; | ||
export { insertJSXAttribute } from './insert-jsx-attribute'; | ||
export * from './utils'; |
{ | ||
"name": "eslint-codemod-utils", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "A collection of AST helper functions for more complex ESLint rule fixes.", | ||
@@ -5,0 +5,0 @@ "author": "Alex Hinds", |
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
590574
89
16434