@@ -32,6 +32,7 @@ module.exports = {
3232
3333 create : function ( context ) {
3434 // Declare a test stack in case of nested test cases (not currently supported by QUnit).
35+ /** @type {Array<{assertVar: string | null}> } */
3536 const testStack = [ ] ;
3637
3738 function getCurrentAssertContextVariable ( ) {
@@ -40,7 +41,11 @@ module.exports = {
4041 return testStack [ testStack . length - 1 ] . assertVar ;
4142 }
4243
43- // Check for something like `equal(...)` without assert parameter.
44+ /**
45+ * Check for something like `equal(...)` without assert parameter.
46+ * @param {import('eslint').Rule.Node } calleeNode
47+ * @returns {boolean }
48+ */
4449 function isGlobalEqualityAssertion ( calleeNode ) {
4550 return (
4651 calleeNode &&
@@ -49,7 +54,11 @@ module.exports = {
4954 ) ;
5055 }
5156
52- // Check for something like `assert.equal(...)`.
57+ /**
58+ * // Check for something like `assert.equal(...)`.
59+ * @param {import('eslint').Rule.Node } calleeNode
60+ * @returns {boolean }
61+ */
5362 function isAssertEquality ( calleeNode ) {
5463 return (
5564 calleeNode &&
@@ -61,37 +70,57 @@ module.exports = {
6170 ) ;
6271 }
6372
64- // Check for something like `equal(...)` or `assert.equal(...)`.
73+ /**
74+ * Check for something like `equal(...)` or `assert.equal(...)`.
75+ * @param {import('eslint').Rule.Node } calleeNode
76+ * @returns {boolean }
77+ */
6578 function isEqualityAssertion ( calleeNode ) {
79+ if ( calleeNode . type !== "CallExpression" ) {
80+ return false ;
81+ }
6682 return (
6783 isGlobalEqualityAssertion ( calleeNode ) ||
6884 isAssertEquality ( calleeNode )
6985 ) ;
7086 }
7187
72- // Finds the first boolean argument of a CallExpression if one exists.
88+ /**
89+ * Finds the first boolean argument of a CallExpression if one exists.
90+ * @param {import('eslint').Rule.Node } node
91+ * @returns {import('eslint').Rule.Node | undefined }
92+ */
7393 function getBooleanArgument ( node ) {
74- return (
75- node . arguments . length >= 2 &&
76- [ node . arguments [ 0 ] , node . arguments [ 1 ] ] . find (
77- ( arg ) =>
78- arg . type === "Literal" &&
79- ( arg . value === true || arg . value === false ) ,
80- )
94+ if ( node . type !== "CallExpression" || node . arguments . length < 2 ) {
95+ return undefined ;
96+ }
97+ return [ node . arguments [ 0 ] , node . arguments [ 1 ] ] . find (
98+ ( arg ) =>
99+ arg . type === "Literal" &&
100+ ( arg . value === true || arg . value === false ) ,
81101 ) ;
82102 }
83103
104+ /**
105+ * @param {import('eslint').Rule.Node } node
106+ */
84107 function reportError ( node ) {
85108 context . report ( {
86109 node : node ,
87110 messageId : "useAssertTrueOrFalse" ,
88111 fix ( fixer ) {
89112 const booleanArgument = getBooleanArgument ( node ) ;
113+ if ( ! booleanArgument ) {
114+ return ;
115+ }
90116 const newAssertionFunctionName = booleanArgument . value
91117 ? "true"
92118 : "false" ;
93119
94120 const sourceCode = context . getSourceCode ( ) ;
121+ if ( node . type !== "CallExpression" ) {
122+ return ;
123+ }
95124 const newArgsTextArray = node . arguments
96125 . filter ( ( arg ) => arg !== booleanArgument )
97126 . map ( ( arg ) => sourceCode . getText ( arg ) ) ;
0 commit comments