mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
* feat: update err loc of require-yield and no-useless-constructor * update loc to constructor keyword only
108 lines
2.1 KiB
JavaScript
108 lines
2.1 KiB
JavaScript
/**
|
|
* @fileoverview Tests for require-yield rule
|
|
* @author Toru Nagashima
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/require-yield");
|
|
const RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } });
|
|
|
|
ruleTester.run("require-yield", rule, {
|
|
valid: [
|
|
"function foo() { return 0; }",
|
|
"function* foo() { yield 0; }",
|
|
"function* foo() { }",
|
|
"(function* foo() { yield 0; })();",
|
|
"(function* foo() { })();",
|
|
"var obj = { *foo() { yield 0; } };",
|
|
"var obj = { *foo() { } };",
|
|
"class A { *foo() { yield 0; } };",
|
|
"class A { *foo() { } };",
|
|
],
|
|
invalid: [
|
|
{
|
|
code: "function* foo() { return 0; }",
|
|
errors: [
|
|
{
|
|
messageId: "missingYield",
|
|
line: 1,
|
|
column: 1,
|
|
endLine: 1,
|
|
endColumn: 14,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "(function* foo() { return 0; })();",
|
|
errors: [
|
|
{
|
|
messageId: "missingYield",
|
|
line: 1,
|
|
column: 2,
|
|
endLine: 1,
|
|
endColumn: 15,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "var obj = { *foo() { return 0; } }",
|
|
errors: [
|
|
{
|
|
messageId: "missingYield",
|
|
line: 1,
|
|
column: 13,
|
|
endLine: 1,
|
|
endColumn: 17,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "class A { *foo() { return 0; } }",
|
|
errors: [
|
|
{
|
|
messageId: "missingYield",
|
|
line: 1,
|
|
column: 11,
|
|
endLine: 1,
|
|
endColumn: 15,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "function* foo() { function* bar() { yield 0; } }",
|
|
errors: [
|
|
{
|
|
messageId: "missingYield",
|
|
line: 1,
|
|
column: 1,
|
|
endLine: 1,
|
|
endColumn: 14,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "function* foo() { function* bar() { return 0; } yield 0; }",
|
|
errors: [
|
|
{
|
|
messageId: "missingYield",
|
|
line: 1,
|
|
column: 19,
|
|
endLine: 1,
|
|
endColumn: 32,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|