33 * @author Vitor Balocco
44 */
55
6- 'use strict'
7-
86/**
97 * Gets the property of the Object node passed in that has the name specified.
10- *
11- * @param {string } propertyName Name of the property to return.
12- * @param {ASTNode } node The ObjectExpression node.
13- * @returns {ASTNode } The Property node or null if not found.
148 */
15- function getPropertyFromObject ( propertyName , node ) {
9+ function getPropertyFromObject (
10+ propertyName : string ,
11+ node : ASTNode | undefined
12+ ) : Property | null {
1613 if ( node && node . type === 'ObjectExpression' ) {
1714 for ( const property of node . properties ) {
18- if ( property . type === 'Property' && property . key . name === propertyName ) {
15+ if (
16+ property . type === 'Property' &&
17+ property . key . type === 'Identifier' &&
18+ property . key . name === propertyName
19+ ) {
1920 return property
2021 }
2122 }
@@ -25,23 +26,18 @@ function getPropertyFromObject(propertyName, node) {
2526
2627/**
2728 * Extracts the `meta` property from the ObjectExpression that all rules export.
28- *
29- * @param {ASTNode } exportsNode ObjectExpression node that the rule exports.
30- * @returns {ASTNode } The `meta` Property node or null if not found.
3129 */
32- function getMetaPropertyFromExportsNode ( exportsNode ) {
30+ function getMetaPropertyFromExportsNode ( exportsNode : ASTNode | undefined ) {
3331 return getPropertyFromObject ( 'meta' , exportsNode )
3432}
3533
3634/**
3735 * Checks the validity of the meta definition of this rule and reports any errors found.
38- *
39- * @param {RuleContext } context The ESLint rule context.
40- * @param {ASTNode } exportsNode ObjectExpression node that the rule exports.
41- * @param {boolean } ruleIsFixable whether the rule is fixable or not.
42- * @returns {void }
4336 */
44- function checkMetaValidity ( context , exportsNode ) {
37+ function checkMetaValidity (
38+ context : RuleContext ,
39+ exportsNode : ASTNode | undefined
40+ ) {
4541 const metaProperty = getMetaPropertyFromExportsNode ( exportsNode )
4642 if ( ! metaProperty ) {
4743 return
@@ -102,7 +98,7 @@ function checkMetaValidity(context, exportsNode) {
10298 }
10399}
104100
105- module . exports = {
101+ export default {
106102 meta : {
107103 type : 'problem' ,
108104 docs : {
@@ -120,27 +116,29 @@ module.exports = {
120116 languages : [ 'js/js' ]
121117 } ,
122118
123- create ( context ) {
124- let exportsNode
119+ create ( context : RuleContext ) {
120+ let exportsNode : ASTNode | undefined
125121
126122 return {
127- AssignmentExpression ( node ) {
123+ AssignmentExpression ( node : AssignmentExpression ) {
128124 if (
129125 node . left &&
130126 node . right &&
131127 node . left . type === 'MemberExpression' &&
128+ node . left . object . type === 'Identifier' &&
132129 node . left . object . name === 'module' &&
130+ node . left . property . type === 'Identifier' &&
133131 node . left . property . name === 'exports'
134132 ) {
135133 exportsNode = node . right
136134 }
137135 } ,
138136
139- ExportDefaultDeclaration ( node ) {
137+ ExportDefaultDeclaration ( node : ExportDefaultDeclaration ) {
140138 exportsNode = node . declaration
141139 } ,
142140
143- 'Program:exit' ( programNode ) {
141+ 'Program:exit' ( ) {
144142 checkMetaValidity ( context , exportsNode )
145143 }
146144 }
0 commit comments