| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 34c47ed commit cd5ee52
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/alphabetize-errors'); | ||
| 7 | + | ||
| 8 | + new RuleTester().run('alphabetize-errors', rule, { | ||
| 9 | + valid: [ | ||
| 10 | + ` | ||
| 11 | + E('AAA', 'foo'); | ||
| 12 | + E('BBB', 'bar'); | ||
| 13 | + E('CCC', 'baz'); | ||
| 14 | + ` | ||
| 15 | + ], | ||
| 16 | + invalid: [ | ||
| 17 | + { | ||
| 18 | + code: ` | ||
| 19 | + E('BBB', 'bar'); | ||
| 20 | + E('AAA', 'foo'); | ||
| 21 | + E('CCC', 'baz'); | ||
| 22 | + `, | ||
| 23 | + errors: [{ message: 'Out of ASCIIbetical order - BBB >= AAA', line: 3 }] | ||
| 24 | + } | ||
| 25 | + ] | ||
| 26 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/buffer-constructor'); | ||
| 7 | + | ||
| 8 | + const message = 'Use of the Buffer() constructor has been deprecated. ' + | ||
| 9 | + 'Please use either Buffer.alloc(), Buffer.allocUnsafe(), ' + | ||
| 10 | + 'or Buffer.from()'; | ||
| 11 | + | ||
| 12 | + new RuleTester().run('buffer-constructor', rule, { | ||
| 13 | + valid: [ | ||
| 14 | + 'Buffer.from(foo)' | ||
| 15 | + ], | ||
| 16 | + invalid: [ | ||
| 17 | + { | ||
| 18 | + code: 'Buffer(foo)', | ||
| 19 | + errors: [{ message }] | ||
| 20 | + }, | ||
| 21 | + { | ||
| 22 | + code: 'new Buffer(foo)', | ||
| 23 | + errors: [{ message }] | ||
| 24 | + } | ||
| 25 | + ] | ||
| 26 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/crypto-check'); | ||
| 7 | + | ||
| 8 | + const message = 'Please add a hasCrypto check to allow this test to be ' + | ||
| 9 | + 'skipped when Node is built "--without-ssl".'; | ||
| 10 | + | ||
| 11 | + new RuleTester().run('crypto-check', rule, { | ||
| 12 | + valid: [ | ||
| 13 | + 'foo', | ||
| 14 | + 'crypto', | ||
| 15 | + ` | ||
| 16 | + if (!common.hasCrypto) { | ||
| 17 | + common.skip(); | ||
| 18 | + } | ||
| 19 | + require('crypto'); | ||
| 20 | + ` | ||
| 21 | + ], | ||
| 22 | + invalid: [ | ||
| 23 | + { | ||
| 24 | + code: 'require("crypto")', | ||
| 25 | + errors: [{ message }] | ||
| 26 | + }, | ||
| 27 | + { | ||
| 28 | + code: 'if (common.foo) {} require("crypto")', | ||
| 29 | + errors: [{ message }] | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/inspector-check'); | ||
| 7 | + | ||
| 8 | + const message = 'Please add a skipIfInspectorDisabled() call to allow this ' + | ||
| 9 | + 'test to be skippped when Node is built ' + | ||
| 10 | + '\'--without-inspector\'.'; | ||
| 11 | + | ||
| 12 | + new RuleTester().run('inspector-check', rule, { | ||
| 13 | + valid: [ | ||
| 14 | + 'foo;', | ||
| 15 | + 'common.skipIfInspectorDisabled(); require("inspector");' | ||
| 16 | + ], | ||
| 17 | + invalid: [ | ||
| 18 | + { | ||
| 19 | + code: 'require("inspector")', | ||
| 20 | + errors: [{ message }] | ||
| 21 | + } | ||
| 22 | + ] | ||
| 23 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/no-let-in-for-declaration'); | ||
| 7 | + | ||
| 8 | + const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); | ||
| 9 | + | ||
| 10 | + const message = 'Use of `let` as the loop variable in a for-loop is ' + | ||
| 11 | + 'not recommended. Please use `var` instead.'; | ||
| 12 | + | ||
| 13 | + ruleTester.run('no-let-in-for-declaration', rule, { | ||
| 14 | + valid: [ | ||
| 15 | + 'let foo;', | ||
| 16 | + 'for (var foo = 1;;);', | ||
| 17 | + 'for (foo = 1;;);', | ||
| 18 | + 'for (;;);', | ||
| 19 | + 'for (const foo of bar);', | ||
| 20 | + 'for (var foo of bar);', | ||
| 21 | + 'for (const foo in bar);', | ||
| 22 | + 'for (var foo in bar);' | ||
| 23 | + ], | ||
| 24 | + invalid: [ | ||
| 25 | + { | ||
| 26 | + code: 'for (let foo = 1;;);', | ||
| 27 | + errors: [{ message }] | ||
| 28 | + }, | ||
| 29 | + { | ||
| 30 | + code: 'for (let foo in bar);', | ||
| 31 | + errors: [{ message }] | ||
| 32 | + }, | ||
| 33 | + { | ||
| 34 | + code: 'for (let foo of bar);', | ||
| 35 | + errors: [{ message }] | ||
| 36 | + } | ||
| 37 | + ] | ||
| 38 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/no-unescaped-regexp-dot'); | ||
| 7 | + | ||
| 8 | + new RuleTester().run('no-unescaped-regexp-dot', rule, { | ||
| 9 | + valid: [ | ||
| 10 | + '/foo/', | ||
| 11 | + String.raw`/foo\./`, | ||
| 12 | + '/.+/', | ||
| 13 | + '/.*/', | ||
| 14 | + '/.?/', | ||
| 15 | + '/.{5}/', | ||
| 16 | + String.raw`/\\\./` | ||
| 17 | + ], | ||
| 18 | + invalid: [ | ||
| 19 | + { | ||
| 20 | + code: '/./', | ||
| 21 | + errors: [{ message: 'Unescaped dot character in regular expression' }] | ||
| 22 | + }, | ||
| 23 | + { | ||
| 24 | + code: String.raw`/\\./`, | ||
| 25 | + errors: [{ message: 'Unescaped dot character in regular expression' }] | ||
| 26 | + } | ||
| 27 | + ] | ||
| 28 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/prefer-assert-iferror'); | ||
| 7 | + | ||
| 8 | + new RuleTester().run('prefer-assert-iferror', rule, { | ||
| 9 | + valid: [ | ||
| 10 | + 'assert.ifError(err);', | ||
| 11 | + 'if (err) throw somethingElse;', | ||
| 12 | + 'throw err;', | ||
| 13 | + 'if (err) { throw somethingElse; }' | ||
| 14 | + ], | ||
| 15 | + invalid: [ | ||
| 16 | + { | ||
| 17 | + code: 'if (err) throw err;', | ||
| 18 | + errors: [{ message: 'Use assert.ifError(err) instead.' }] | ||
| 19 | + }, | ||
| 20 | + { | ||
| 21 | + code: 'if (error) { throw error; }', | ||
| 22 | + errors: [{ message: 'Use assert.ifError(error) instead.' }] | ||
| 23 | + } | ||
| 24 | + ] | ||
| 25 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/prefer-assert-methods'); | ||
| 7 | + | ||
| 8 | + new RuleTester().run('prefer-assert-methods', rule, { | ||
| 9 | + valid: [ | ||
| 10 | + 'assert.strictEqual(foo, bar)', | ||
| 11 | + 'assert(foo === bar && baz)' | ||
| 12 | + ], | ||
| 13 | + invalid: [ | ||
| 14 | + { | ||
| 15 | + code: 'assert(foo == bar)', | ||
| 16 | + errors: [{ message: "'assert.equal' should be used instead of '=='" }] | ||
| 17 | + }, | ||
| 18 | + { | ||
| 19 | + code: 'assert(foo === bar)', | ||
| 20 | + errors: [{ | ||
| 21 | + message: "'assert.strictEqual' should be used instead of '==='" | ||
| 22 | + }] | ||
| 23 | + }, | ||
| 24 | + { | ||
| 25 | + code: 'assert(foo != bar)', | ||
| 26 | + errors: [{ | ||
| 27 | + message: "'assert.notEqual' should be used instead of '!='" | ||
| 28 | + }] | ||
| 29 | + }, | ||
| 30 | + { | ||
| 31 | + code: 'assert(foo !== bar)', | ||
| 32 | + errors: [{ | ||
| 33 | + message: "'assert.notStrictEqual' should be used instead of '!=='" | ||
| 34 | + }] | ||
| 35 | + }, | ||
| 36 | + ] | ||
| 37 | + }); | ||
| 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-mustnotcall'); | ||
| 7 | + | ||
| 8 | + const message = 'Please use common.mustNotCall(msg) instead of ' + | ||
| 9 | + 'common.mustCall(fn, 0) or common.mustCall(0).'; | ||
| 10 | + | ||
| 11 | + new RuleTester().run('prefer-common-mustnotcall', rule, { | ||
| 12 | + valid: [ | ||
| 13 | + 'common.mustNotCall(fn)', | ||
| 14 | + 'common.mustCall(fn)', | ||
| 15 | + 'common.mustCall(fn, 1)' | ||
| 16 | + ], | ||
| 17 | + invalid: [ | ||
| 18 | + { | ||
| 19 | + code: 'common.mustCall(fn, 0)', | ||
| 20 | + errors: [{ message }] | ||
| 21 | + }, | ||
| 22 | + { | ||
| 23 | + code: 'common.mustCall(0)', | ||
| 24 | + errors: [{ message }] | ||
| 25 | + } | ||
| 26 | + ] | ||
| 27 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const RuleTester = require('../../tools/eslint').RuleTester; | ||
| 6 | + const rule = require('../../tools/eslint-rules/require-buffer'); | ||
| 7 | + const ruleTester = new RuleTester({ | ||
| 8 | + parserOptions: { ecmaVersion: 6 }, | ||
| 9 | + env: { node: true } | ||
| 10 | + }); | ||
| 11 | + | ||
| 12 | + const message = "Use const Buffer = require('buffer').Buffer; " + | ||
| 13 | + 'at the beginning of this file'; | ||
| 14 | + | ||
| 15 | + ruleTester.run('require-buffer', rule, { | ||
| 16 | + valid: [ | ||
| 17 | + 'foo', | ||
| 18 | + 'const Buffer = require("Buffer"); Buffer;' | ||
| 19 | + ], | ||
| 20 | + invalid: [ | ||
| 21 | + { | ||
| 22 | + code: 'Buffer;', | ||
| 23 | + errors: [{ message }] | ||
| 24 | + } | ||
| 25 | + ] | ||
| 26 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments