Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate trivial node type check helpers #1720

Merged
merged 1 commit into from Dec 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/utils/types.js
@@ -1,5 +1,12 @@
'use strict';

/**
* Trivial helpers in this file that only check a node's existence and/or type are deprecated in favor of inlining that check.
* We don't need a function for every type of node.
* And as written, these functions won't correctly narrow the type of the node, which we would need if we incorporate TypeScript: https://github.com/ember-cli/eslint-plugin-ember/issues/1613
* TODO: we should inline these trivial checks and only check for node existence when it's actually a possibility a node might not exist.
*/

module.exports = {
isAnyFunctionExpression,
isArrayExpression,
Expand Down Expand Up @@ -56,6 +63,7 @@ function isAnyFunctionExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ArrayExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isArrayExpression(node) {
return node !== undefined && node.type === 'ArrayExpression';
Expand All @@ -66,6 +74,7 @@ function isArrayExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ArrowFunctionExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isArrowFunctionExpression(node) {
return node !== undefined && node.type === 'ArrowFunctionExpression';
Expand All @@ -76,6 +85,7 @@ function isArrowFunctionExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an AssignmentExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isAssignmentExpression(node) {
return node.type === 'AssignmentExpression';
Expand All @@ -86,6 +96,7 @@ function isAssignmentExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an BinaryExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isBinaryExpression(node) {
return node !== undefined && node.type === 'BinaryExpression';
Expand All @@ -96,6 +107,7 @@ function isBinaryExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an CallExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isCallExpression(node) {
return node !== undefined && node.type === 'CallExpression';
Expand Down Expand Up @@ -125,6 +137,7 @@ function isCallWithFunctionExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a ClassDeclaration.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isClassDeclaration(node) {
return node !== undefined && node.type === 'ClassDeclaration';
Expand Down Expand Up @@ -163,6 +176,7 @@ function isConciseArrowFunctionWithCallExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a ConditionalExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isConditionalExpression(node) {
return node !== undefined && node.type === 'ConditionalExpression';
Expand All @@ -173,6 +187,7 @@ function isConditionalExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a Decorator.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isDecorator(node) {
return node !== undefined && node.type === 'Decorator';
Expand All @@ -183,6 +198,7 @@ function isDecorator(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ExpressionStatement.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isExpressionStatement(node) {
return node !== undefined && node.type === 'ExpressionStatement';
Expand All @@ -193,6 +209,7 @@ function isExpressionStatement(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a FunctionDeclaration
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isFunctionDeclaration(node) {
return node !== undefined && node.type === 'FunctionDeclaration';
Expand All @@ -203,6 +220,7 @@ function isFunctionDeclaration(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an FunctionExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isFunctionExpression(node) {
return node !== undefined && node.type === 'FunctionExpression';
Expand All @@ -213,6 +231,7 @@ function isFunctionExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an Identifier.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isIdentifier(node) {
return node !== undefined && node.type === 'Identifier';
Expand All @@ -223,6 +242,7 @@ function isIdentifier(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ImportDeclaration.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isImportDeclaration(node) {
return node !== undefined && node.type === 'ImportDeclaration';
Expand All @@ -233,6 +253,7 @@ function isImportDeclaration(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ImportDefaultSpecifier.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isImportDefaultSpecifier(node) {
return node !== undefined && node.type === 'ImportDefaultSpecifier';
Expand All @@ -243,6 +264,7 @@ function isImportDefaultSpecifier(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an Literal.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isLiteral(node) {
return node !== undefined && node.type === 'Literal';
Expand All @@ -253,6 +275,7 @@ function isLiteral(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an LogicalExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isLogicalExpression(node) {
return node !== undefined && node.type === 'LogicalExpression';
Expand All @@ -263,6 +286,7 @@ function isLogicalExpression(node) {
*
* @param {Object} node The node to check.
* @return {boolean} Whether or not the node is an MemberExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isMemberExpression(node) {
return node !== undefined && node.type === 'MemberExpression';
Expand All @@ -273,6 +297,7 @@ function isMemberExpression(node) {
*
* @param {Object} node The node to check.
* @return {boolean} Whether or not the node is a MethodDefinition.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isMethodDefinition(node) {
return node !== undefined && node.type === 'MethodDefinition';
Expand All @@ -283,6 +308,7 @@ function isMethodDefinition(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an NewExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isNewExpression(node) {
return node !== undefined && node.type === 'NewExpression';
Expand All @@ -293,6 +319,7 @@ function isNewExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ObjectExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isObjectExpression(node) {
return node !== undefined && node.type === 'ObjectExpression';
Expand All @@ -303,6 +330,7 @@ function isObjectExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ObjectPattern.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isObjectPattern(node) {
return node !== undefined && node.type === 'ObjectPattern';
Expand All @@ -313,6 +341,7 @@ function isObjectPattern(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an OptionalCallExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isOptionalCallExpression(node) {
return node.type === 'OptionalCallExpression';
Expand All @@ -323,6 +352,7 @@ function isOptionalCallExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an OptionalMemberExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isOptionalMemberExpression(node) {
return node.type === 'OptionalMemberExpression';
Expand All @@ -333,6 +363,7 @@ function isOptionalMemberExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an Property.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isProperty(node) {
return node !== undefined && node.type === 'Property';
Expand All @@ -343,6 +374,7 @@ function isProperty(node) {
*
* @param {Object} node The node to check.
* @return {Boolean} Whether or not the node is a ReturnStatement.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isReturnStatement(node) {
return node !== undefined && node.type && node.type === 'ReturnStatement';
Expand All @@ -353,6 +385,7 @@ function isReturnStatement(node) {
*
* @param {Object} node The node to check.
* @return {Boolean} Whether or not the node is a SpreadElement.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isSpreadElement(node) {
return node !== undefined && node.type === 'SpreadElement';
Expand All @@ -371,6 +404,7 @@ function isStringLiteral(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a TaggedTemplateExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isTaggedTemplateExpression(node) {
return node !== undefined && node.type === 'TaggedTemplateExpression';
Expand All @@ -381,6 +415,7 @@ function isTaggedTemplateExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a TemplateLiteral.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isTemplateLiteral(node) {
return node !== undefined && node.type === 'TemplateLiteral';
Expand All @@ -391,6 +426,7 @@ function isTemplateLiteral(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an ThisExpression.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isThisExpression(node) {
return node !== undefined && node.type === 'ThisExpression';
Expand All @@ -401,6 +437,7 @@ function isThisExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an Literal.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isUnaryExpression(node) {
return node !== undefined && node.type === 'UnaryExpression';
Expand All @@ -411,6 +448,7 @@ function isUnaryExpression(node) {
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is a VariableDeclarator.
* @deprecated trivial helpers are deprecated in favor of inlining the type check
*/
function isVariableDeclarator(node) {
return node !== undefined && node.type === 'VariableDeclarator';
Expand Down