GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tools: lint rule for assert.fail() · nodejs/node@8fa2029

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .eslintrc
  • tools/eslint-rules
    • assert-fail-single-argument.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.eslintrc‎

Copy file name to clipboardExpand all lines: .eslintrc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ rules:
8585
prefer-const: 2
8686

8787
# Custom rules in tools/eslint-rules
88+
assert-fail-single-argument: 2
8889
new-with-error: [2, "Error", "RangeError", "TypeError", "SyntaxError", "ReferenceError"]
8990

9091

Collapse file

‎tools/eslint-rules/assert-fail-single-argument.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @fileoverview Prohibit use of a single argument only in `assert.fail()`. It
3+
* is almost always an error.
4+
* @author Rich Trott
5+
*/
6+
'use strict';
7+
8+
//------------------------------------------------------------------------------
9+
// Rule Definition
10+
//------------------------------------------------------------------------------
11+
12+
const msg = 'assert.fail() message should be third argument';
13+
14+
function isAssert(node) {
15+
return node.callee.object && node.callee.object.name === 'assert';
16+
}
17+
18+
function isFail(node) {
19+
return node.callee.property && node.callee.property.name === 'fail';
20+
}
21+
22+
module.exports = function(context) {
23+
return {
24+
'CallExpression': function(node) {
25+
if (isAssert(node) && isFail(node) && node.arguments.length === 1) {
26+
context.report(node, msg);
27+
}
28+
}
29+
};
30+
};

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.