11// Copyright 2024 The Chromium Authors. All rights reserved.
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- 'use strict' ;
54
6- /**
7- * @fileoverview Prefer `assert.isOk` and `assert.isNotOk` over `assert.ok`
8- * and `assert.notOk`.
9- *
10- * For consistency with the other `assert.isXXX` checks, we standardize on
11- * `assert.isOk` and `assert.isNotOk`. We still also allow plain `assert`.
12- */
5+ import { createRule } from './tsUtils.ts' ;
136
14- // ------------------------------------------------------------------------------
15- // Rule Definition
16- // ------------------------------------------------------------------------------
17-
18- /** @type {import('eslint').Rule.RuleModule } */
19- module . exports = {
7+ export default createRule ( {
8+ name : 'prefer-assert-is-ok' ,
209 meta : {
2110 type : 'suggestion' ,
22-
2311 docs : {
2412 description : 'Prefer `assert.isOk` and `assert.isNotOk` over `assert.ok` and `assert.notOk`.' ,
2513 category : 'Best Practices' ,
@@ -29,23 +17,20 @@ module.exports = {
2917 useAssertIsNotOk : 'Use `assert.isNotOk(e)` or `assert(!e)` instead of `assert.notOk(e)`' ,
3018 } ,
3119 fixable : 'code' ,
32- schema : [ ] , // no options
20+ schema : [ ] , // no options
3321 } ,
34- create : function ( context ) {
22+ defaultOptions : [ ] ,
23+ create : function ( context ) {
3524 function isAssertOk ( calleeNode ) {
36- return calleeNode . type === 'MemberExpression' &&
37- calleeNode . object . type === 'Identifier' &&
38- calleeNode . object . name === 'assert' &&
39- calleeNode . property . type === 'Identifier' &&
40- calleeNode . property . name === 'ok' ;
25+ return calleeNode . type === 'MemberExpression' && calleeNode . object . type === 'Identifier' &&
26+ calleeNode . object . name === 'assert' && calleeNode . property . type === 'Identifier' &&
27+ calleeNode . property . name === 'ok' ;
4128 }
4229
4330 function isAssertNotOk ( calleeNode ) {
44- return calleeNode . type === 'MemberExpression' &&
45- calleeNode . object . type === 'Identifier' &&
46- calleeNode . object . name === 'assert' &&
47- calleeNode . property . type === 'Identifier' &&
48- calleeNode . property . name === 'notOk' ;
31+ return calleeNode . type === 'MemberExpression' && calleeNode . object . type === 'Identifier' &&
32+ calleeNode . object . name === 'assert' && calleeNode . property . type === 'Identifier' &&
33+ calleeNode . property . name === 'notOk' ;
4934 }
5035
5136 function reportError ( node , calleeText , messageId ) {
@@ -68,4 +53,4 @@ module.exports = {
6853 }
6954 } ;
7055 } ,
71- } ;
56+ } ) ;
0 commit comments