Files
react-native-devtools-frontend/scripts/eslint_rules/lib/avoid_assert_equal.js
T
Jack Franklin 28447fd262 Add ESLint rule to ban assert.equal
`assert.equal` is a non-strict check - it uses `==`. In our tests we
should either use:

* `assert.strictEqual` which uses `===`
* `assert.deepEqual` which does
a comparison on objects.

Change-Id: I872f9be140dc4c60b199fce94f95d0c12ee2bbc0
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2160929
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-04-23 12:41:30 +00:00

39 lines
1011 B
JavaScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Rule to ban usage of assert.equal
* @author Jack Franklin
*/
'use strict';
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Usage of assert.equal',
category: 'Possible Errors',
},
fixable: 'code',
schema: [] // no options
},
create: function(context) {
return {
MemberExpression(node) {
if (node.object.name === 'assert' && node.property.name === 'equal') {
context.report({
node,
message: 'assert.equal is non-strict. Use assert.strictEqual or assert.deepEqual to compare objects'
});
}
}
};
}
};