1
1
// Copyright 2024 The Chromium Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
- 'use strict' ;
5
4
6
- /**
7
- * @fileoverview Prefer `assert.lengthOf` to check `length` of an array-like.
8
- */
9
-
10
- // ------------------------------------------------------------------------------
11
- // Rule Definition
12
- // ------------------------------------------------------------------------------
5
+ import { createRule } from './tsUtils.ts' ;
13
6
14
7
const EQUALITY_ASSERTIONS = new Set ( [ 'deepEqual' , 'deepStrictEqual' , 'equal' , 'strictEqual' ] ) ;
15
8
16
- /** @type { import('eslint').Rule.RuleModule } */
17
- module . exports = {
9
+ export default createRule ( {
10
+ name : 'prefer-assert-length-of' ,
18
11
meta : {
19
12
type : 'suggestion' ,
20
-
21
13
docs : {
22
14
description : 'Prefer `assert.lengthOf` to check `length` of an array-like.' ,
23
15
category : 'Best Practices' ,
@@ -26,15 +18,14 @@ module.exports = {
26
18
useAssertLengthOf : 'Use `assert.lengthOf` to check `length` of an array-like' ,
27
19
} ,
28
20
fixable : 'code' ,
29
- schema : [ ] , // no options
21
+ schema : [ ] , // no options
30
22
} ,
31
- create : function ( context ) {
23
+ defaultOptions : [ ] ,
24
+ create : function ( context ) {
32
25
function isAssertEquality ( calleeNode ) {
33
- return calleeNode . type === 'MemberExpression' &&
34
- calleeNode . object . type === 'Identifier' &&
35
- calleeNode . object . name === 'assert' &&
36
- calleeNode . property . type === 'Identifier' &&
37
- EQUALITY_ASSERTIONS . has ( calleeNode . property . name ) ;
26
+ return calleeNode . type === 'MemberExpression' && calleeNode . object . type === 'Identifier' &&
27
+ calleeNode . object . name === 'assert' && calleeNode . property . type === 'Identifier' &&
28
+ EQUALITY_ASSERTIONS . has ( calleeNode . property . name ) ;
38
29
}
39
30
40
31
function isLengthProperty ( argumentNode ) {
@@ -43,8 +34,7 @@ module.exports = {
43
34
}
44
35
45
36
function isNumberLiteral ( argumentNode ) {
46
- return argumentNode . type === 'Literal' &&
47
- typeof argumentNode . value === 'number' ;
37
+ return argumentNode . type === 'Literal' && typeof argumentNode . value === 'number' ;
48
38
}
49
39
50
40
function reportError ( node ) {
@@ -76,4 +66,4 @@ module.exports = {
76
66
}
77
67
} ;
78
68
} ,
79
- } ;
69
+ } ) ;
0 commit comments