| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 49d6628 commit aa32bd0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ rules: | |||
| 10 | 10 | # Custom rules in tools/eslint-rules | |
| 11 | 11 | prefer-assert-iferror: error | |
| 12 | 12 | prefer-assert-methods: error | |
| 13 | + prefer-common-expectserror: error | ||
| 13 | 14 | prefer-common-mustnotcall: error | |
| 14 | 15 | crypto-check: error | |
| 15 | 16 | inspector-check: error | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/prefer-common-expectserror'); | ||
| 7 | + | ||
| 8 | + const message = 'Please use common.expectsError(fn, err) instead of ' + | ||
| 9 | + 'assert.throws(fn, common.expectsError(err)).'; | ||
| 10 | + | ||
| 11 | + new RuleTester().run('prefer-common-expectserror', rule, { | ||
| 12 | + valid: [ | ||
| 13 | + 'assert.throws(fn, /[a-z]/)', | ||
| 14 | + 'assert.throws(function () {}, function() {})', | ||
| 15 | + 'common.expectsError(function() {}, err)' | ||
| 16 | + ], | ||
| 17 | + invalid: [ | ||
| 18 | + { | ||
| 19 | + code: 'assert.throws(function() {}, common.expectsError(err))', | ||
| 20 | + errors: [{ message }] | ||
| 21 | + }, | ||
| 22 | + { | ||
| 23 | + code: 'assert.throws(fn, common.expectsError(err))', | ||
| 24 | + errors: [{ message }] | ||
| 25 | + } | ||
| 26 | + ] | ||
| 27 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + //------------------------------------------------------------------------------ | ||
| 4 | + // Rule Definition | ||
| 5 | + //------------------------------------------------------------------------------ | ||
| 6 | + | ||
| 7 | + const msg = 'Please use common.expectsError(fn, err) instead of ' + | ||
| 8 | + 'assert.throws(fn, common.expectsError(err)).'; | ||
| 9 | + | ||
| 10 | + const astSelector = | ||
| 11 | + 'CallExpression[arguments.length=2]' + | ||
| 12 | + '[callee.object.name="assert"]' + | ||
| 13 | + '[callee.property.name="throws"]' + | ||
| 14 | + '[arguments.1.callee.object.name="common"]' + | ||
| 15 | + '[arguments.1.callee.property.name="expectsError"]'; | ||
| 16 | + | ||
| 17 | + module.exports = function(context) { | ||
| 18 | + return { | ||
| 19 | + [astSelector]: (node) => context.report(node, msg) | ||
| 20 | + }; | ||
| 21 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments