change eslint tests formatting
This commit is contained in:
parent
afafd3fcb3
commit
ee90fdb90b
|
@ -14,67 +14,78 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("boolean-trivia", rule, {
|
||||
valid: [{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
valid: [
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: boolean) => {};
|
||||
fn(/* boolean prop */ true);
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: null) => {};
|
||||
fn(/* null prop */ null);
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: null) => {};
|
||||
fn(/*null prop*/ null);
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: boolean) => {};
|
||||
fn(/* comment */
|
||||
false
|
||||
);
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: boolean) => {};
|
||||
fn.apply(null, true);
|
||||
`,
|
||||
}],
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
invalid: [
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: null) => {};
|
||||
fn(null);
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentError" }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentError" }],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: boolean) => {};
|
||||
fn(false);
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentError" }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentError" }],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: boolean) => {};
|
||||
fn(/* boolean arg */false);
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentSpaceError" }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentSpaceError" }],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const fn = (prop: boolean) => {};
|
||||
fn(/* first comment */ /* second comment */ false);
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentError" }],
|
||||
}],
|
||||
`,
|
||||
errors: [{ messageId: "booleanTriviaArgumentError" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -9,32 +9,42 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("debug-assert", rule, {
|
||||
valid: [{
|
||||
code: `Debug.assert(true)`,
|
||||
}, {
|
||||
code: `Debug.assert(true, 'error message')`,
|
||||
}, {
|
||||
code: `Debug.assert(true, 'error message 1', 'error message 2')`,
|
||||
}, {
|
||||
code: `Debug.assert(true, 'error message 1', () => {})`,
|
||||
}, {
|
||||
code: "Debug.assert(true, `error message 1`, () => {})",
|
||||
}, {
|
||||
code: `Debug.assert(true, "error message 1", () => {})`,
|
||||
}],
|
||||
valid: [
|
||||
{
|
||||
code: `Debug.assert(true)`,
|
||||
},
|
||||
{
|
||||
code: `Debug.assert(true, 'error message')`,
|
||||
},
|
||||
{
|
||||
code: `Debug.assert(true, 'error message 1', 'error message 2')`,
|
||||
},
|
||||
{
|
||||
code: `Debug.assert(true, 'error message 1', () => {})`,
|
||||
},
|
||||
{
|
||||
code: "Debug.assert(true, `error message 1`, () => {})",
|
||||
},
|
||||
{
|
||||
code: `Debug.assert(true, "error message 1", () => {})`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `Debug.assert(true, 1)`,
|
||||
errors: [{ messageId: "secondArgumentDebugAssertError" }],
|
||||
}, {
|
||||
code: `Debug.assert(true, 'error message', 1)`,
|
||||
errors: [{ messageId: "thirdArgumentDebugAssertError" }],
|
||||
}, {
|
||||
code: `Debug.assert(true, null, 1)`,
|
||||
errors: [{
|
||||
messageId: "secondArgumentDebugAssertError",
|
||||
}, {
|
||||
messageId: "thirdArgumentDebugAssertError",
|
||||
}],
|
||||
}],
|
||||
invalid: [
|
||||
{
|
||||
code: `Debug.assert(true, 1)`,
|
||||
errors: [{ messageId: "secondArgumentDebugAssertError" }],
|
||||
},
|
||||
{
|
||||
code: `Debug.assert(true, 'error message', 1)`,
|
||||
errors: [{ messageId: "thirdArgumentDebugAssertError" }],
|
||||
},
|
||||
{
|
||||
code: `Debug.assert(true, null, 1)`,
|
||||
errors: [
|
||||
{ messageId: "secondArgumentDebugAssertError" },
|
||||
{ messageId: "thirdArgumentDebugAssertError" },
|
||||
],
|
||||
}
|
||||
],
|
||||
});
|
||||
|
|
|
@ -14,130 +14,174 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("no-double-space", rule, {
|
||||
valid: [{
|
||||
filename: FILENAME,
|
||||
code: `const a = {};`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `function fn() {}`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `const a = " ";`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `// ^ ^`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `class Cl {}`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `// comment `,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `/* comment */`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `" string ";`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `/ regexp /g;`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `const rgx = / regexp /g;`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: "const str = ` string template`;",
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: ` // comment`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: ` /* comment */`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `// `,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
valid: [
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `const a = {};`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `function fn() {}`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `const a = " ";`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `// ^ ^`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `class Cl {}`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `// comment `,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `/* comment */`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `" string ";`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `/ regexp /g;`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `const rgx = / regexp /g;`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: "const str = ` string template`;",
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: ` // comment`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: ` /* comment */`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `// `,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const a =
|
||||
1;
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
/**
|
||||
* comment
|
||||
*/
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
// comment
|
||||
// - comment
|
||||
// - comment
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
interface Props {
|
||||
prop: string[]; // comment prop
|
||||
propB: string[]; // comment propB
|
||||
}
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type: string[]
|
||||
*
|
||||
* @param exclude A JSON encoded string[] containing the paths to exclude
|
||||
* when enumerating the directory.
|
||||
*/
|
||||
`,
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const obj = {
|
||||
content: "function f() { 1; }",
|
||||
};
|
||||
`,
|
||||
}],
|
||||
`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
filename: FILENAME,
|
||||
code: `const a = {};`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 6 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `function fn() {}`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 9 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `class Cl {}`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 6 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: "const str = ` string template`;",
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 12 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `/** comment */`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 12 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `/** comment with many spaces */`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 12 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `// comment with many spaces`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 11 }],
|
||||
}, {
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
invalid: [
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `const a = {};`,
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 1, column: 6 },
|
||||
],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `function fn() {}`,
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 1, column: 9 },
|
||||
],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `class Cl {}`,
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 1, column: 6 }],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: "const str = ` string template`;",
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 1, column: 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `/** comment */`,
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 1, column: 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `/** comment with many spaces */`,
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 1, column: 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `// comment with many spaces`,
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 1, column: 11 },
|
||||
],
|
||||
},
|
||||
{
|
||||
filename: FILENAME,
|
||||
code: `
|
||||
const a = 1;
|
||||
const b = 2;
|
||||
const c = 3;
|
||||
`.trim(),
|
||||
errors: [{ messageId: "noDoubleSpaceError", line: 3, column: 10 }],
|
||||
}],
|
||||
`,
|
||||
errors: [
|
||||
{ messageId: "noDoubleSpaceError", line: 4, column: 10 },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -9,18 +9,22 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("no-in-operator", rule, {
|
||||
valid: [{
|
||||
code: `
|
||||
valid: [
|
||||
{
|
||||
code: `
|
||||
const prop = {};
|
||||
prop.hasProperty('a');
|
||||
`,
|
||||
}],
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `
|
||||
invalid: [
|
||||
{
|
||||
code: `
|
||||
const prop = {};
|
||||
prop in 'a';
|
||||
`,
|
||||
errors: [{ messageId: "noInOperatorError" }],
|
||||
}],
|
||||
`,
|
||||
errors: [{ messageId: "noInOperatorError" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -9,32 +9,40 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("no-keywords", rule, {
|
||||
valid: [{
|
||||
code: `const a = {};`,
|
||||
}, {
|
||||
code: `function a() {};`,
|
||||
}, {
|
||||
code: `const x = function string() {};`,
|
||||
}, {
|
||||
code: `const y = function () {};`,
|
||||
}, {
|
||||
code: `const y = () => {};`,
|
||||
}, {
|
||||
code: `
|
||||
valid: [
|
||||
{
|
||||
code: `const a = {};`,
|
||||
},
|
||||
{
|
||||
code: `function a() {};`,
|
||||
},
|
||||
{
|
||||
code: `const x = function string() {};`,
|
||||
},
|
||||
{
|
||||
code: `const y = function () {};`,
|
||||
},
|
||||
{
|
||||
code: `const y = () => {};`,
|
||||
},
|
||||
{
|
||||
code: `
|
||||
class A {
|
||||
b = () => {}
|
||||
a() {}
|
||||
number() {}
|
||||
}
|
||||
`,
|
||||
}, {
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
code: `
|
||||
interface A {
|
||||
b(): void;
|
||||
}
|
||||
`,
|
||||
}, {
|
||||
code: `
|
||||
`,
|
||||
},
|
||||
{
|
||||
code: `
|
||||
const obj = {
|
||||
a: null,
|
||||
b() {},
|
||||
|
@ -42,36 +50,50 @@ const obj = {
|
|||
string: function d (d: string) {},
|
||||
e: () => {},
|
||||
};
|
||||
`,
|
||||
}],
|
||||
`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `const number = 1;`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
}, {
|
||||
code: `function x(number: number) {};`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
}, {
|
||||
code: `const y = function (number: number) {};`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
}, {
|
||||
code: `const y = (number: number) => {};`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
}, {
|
||||
code: `
|
||||
invalid: [
|
||||
{
|
||||
code: `const number = 1;`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
},
|
||||
{
|
||||
code: `function x(number: number) {};`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
},
|
||||
{
|
||||
code: `const y = function (number: number) {};`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
},
|
||||
{
|
||||
code: `const y = (number: number) => {};`,
|
||||
errors: [{ messageId: "noKeywordsError" }],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
class A {
|
||||
b = function (any: any) {};
|
||||
a(number: number) {}
|
||||
}
|
||||
`,
|
||||
errors: [{ messageId: "noKeywordsError" }, { messageId: "noKeywordsError" }],
|
||||
}, {
|
||||
code: `
|
||||
`,
|
||||
errors: [
|
||||
{ messageId: "noKeywordsError" },
|
||||
{ messageId: "noKeywordsError" },
|
||||
],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
interface A {
|
||||
a(number: number): void;
|
||||
b: (any: any) => void;
|
||||
}
|
||||
`,
|
||||
errors: [{ messageId: "noKeywordsError" }, { messageId: "noKeywordsError" }],
|
||||
}],
|
||||
`,
|
||||
errors: [
|
||||
{ messageId: "noKeywordsError" },
|
||||
{ messageId: "noKeywordsError" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -9,23 +9,31 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("no-type-assertion-whitespace", rule, {
|
||||
valid: [{
|
||||
code: `const a = <number>1`,
|
||||
}, {
|
||||
code: `const s = <Type>(new Symbol(1, 'name'));`,
|
||||
}],
|
||||
valid: [
|
||||
{
|
||||
code: `const a = <number>1`,
|
||||
},
|
||||
{
|
||||
code: `const s = <Type>(new Symbol(1, 'name'));`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `const a = <number> 1`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 19, line: 1 }],
|
||||
}, {
|
||||
code: `const a = <number> 1`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 19, line: 1 }],
|
||||
}, {
|
||||
code: `const a = <number> 1`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 19, line: 1 }],
|
||||
}, {
|
||||
code: `const s = <Type> (new Symbol(1, 'name'));`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 17, line: 1 }],
|
||||
}],
|
||||
invalid: [
|
||||
{
|
||||
code: `const a = <number> 1`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 19, line: 1 }],
|
||||
},
|
||||
{
|
||||
code: `const a = <number> 1`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 19, line: 1 }],
|
||||
},
|
||||
{
|
||||
code: `const a = <number> 1`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 19, line: 1 }],
|
||||
},
|
||||
{
|
||||
code: `const s = <Type> (new Symbol(1, 'name'));`,
|
||||
errors: [{ messageId: "noTypeAssertionWhitespace", column: 17, line: 1 }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -9,32 +9,41 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("object-literal-surrounding-space", rule, {
|
||||
valid: [{
|
||||
code: `const prop = {}`,
|
||||
}, {
|
||||
code: `const prop = { }`,
|
||||
}, {
|
||||
code: `const prop = { x: 1 }`,
|
||||
}],
|
||||
valid: [
|
||||
{
|
||||
code: `const prop = {}`,
|
||||
},
|
||||
{
|
||||
code: `const prop = { }`,
|
||||
},
|
||||
{
|
||||
code: `const prop = { x: 1 }`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `const prop = {x: 1}`,
|
||||
errors: [{
|
||||
messageId: "leadingStringError",
|
||||
}, {
|
||||
messageId: "trailingStringError",
|
||||
}],
|
||||
}, {
|
||||
code: `const prop = { x: 1 }`,
|
||||
errors: [{ messageId: "leadingExcessStringError" }],
|
||||
}, {
|
||||
code: `const prop = { x: 1 }`,
|
||||
errors: [{ messageId: "trailingExcessStringError" }],
|
||||
}, {
|
||||
code: `const prop = { x: 1}`,
|
||||
errors: [{ messageId: "trailingStringError" }],
|
||||
}, {
|
||||
code: `const prop = {x: 1 }`,
|
||||
errors: [{ messageId: "leadingStringError" }],
|
||||
}],
|
||||
invalid: [
|
||||
{
|
||||
code: `const prop = {x: 1}`,
|
||||
errors: [
|
||||
{ messageId: "leadingStringError" },
|
||||
{ messageId: "trailingStringError" }
|
||||
],
|
||||
},
|
||||
{
|
||||
code: `const prop = { x: 1 }`,
|
||||
errors: [{ messageId: "leadingExcessStringError" }],
|
||||
},
|
||||
{
|
||||
code: `const prop = { x: 1 }`,
|
||||
errors: [{ messageId: "trailingExcessStringError" }],
|
||||
},
|
||||
{
|
||||
code: `const prop = { x: 1}`,
|
||||
errors: [{ messageId: "trailingStringError" }],
|
||||
},
|
||||
{
|
||||
code: `const prop = {x: 1 }`,
|
||||
errors: [{ messageId: "leadingStringError" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -9,93 +9,119 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("only-arrow-functions", rule, {
|
||||
valid: [{
|
||||
code: `const a = () => {};`,
|
||||
}, {
|
||||
code: `((func) => func())(() => {});`,
|
||||
}, {
|
||||
code: `function* generator() {}`,
|
||||
}, {
|
||||
code: `let generator = function*() {}`,
|
||||
}, {
|
||||
code: `function hasThisParameter(this) {}`,
|
||||
}, {
|
||||
code: `let hasThisParameter = function(this) {}`,
|
||||
}, {
|
||||
code: `let usesThis = function() { this; }`,
|
||||
}, {
|
||||
code: `let usesThis2 = function(foo = this) {}`,
|
||||
}, {
|
||||
code: `
|
||||
let fn = function fn() {};
|
||||
function z() {};
|
||||
`,
|
||||
options: [{ allowNamedFunctions: true }],
|
||||
}, {
|
||||
code: `
|
||||
valid: [
|
||||
{
|
||||
code: `const a = () => {};`,
|
||||
},
|
||||
{
|
||||
code: `((func) => func())(() => {});`,
|
||||
},
|
||||
{
|
||||
code: `function* generator() {}`,
|
||||
},
|
||||
{
|
||||
code: `let generator = function*() {}`,
|
||||
},
|
||||
{
|
||||
code: `function hasThisParameter(this) {}`,
|
||||
},
|
||||
{
|
||||
code: `let hasThisParameter = function(this) {}`,
|
||||
},
|
||||
{
|
||||
code: `let usesThis = function() { this; }`,
|
||||
},
|
||||
{
|
||||
code: `let usesThis2 = function(foo = this) {}`,
|
||||
},
|
||||
{
|
||||
code: `
|
||||
let fn = function fn() {};
|
||||
function z() {};
|
||||
`,
|
||||
options: [{ allowNamedFunctions: true }],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
function fn() {};
|
||||
let generator = function*() {}
|
||||
function hasThisParameter(this) {}
|
||||
let hasThisParameter = function(this) {}
|
||||
`,
|
||||
options: [{ allowDeclarations: true }],
|
||||
}, {
|
||||
code: `
|
||||
`,
|
||||
options: [{ allowDeclarations: true }],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
class A {
|
||||
test() {}
|
||||
}
|
||||
`,
|
||||
}, {
|
||||
code: `
|
||||
},
|
||||
{
|
||||
code: `
|
||||
const obj = {
|
||||
test() {}
|
||||
}
|
||||
`,
|
||||
}],
|
||||
`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `function foo(a: any): any {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `let b = function () {};`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `function c() {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `((func) => func())(function e(): void {});`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `
|
||||
invalid: [
|
||||
{
|
||||
code: `function foo(a: any): any {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `let b = function () {};`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `function c() {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `((func) => func())(function e(): void {});`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
let notUsesThis = function() {
|
||||
function f() { this; }
|
||||
}
|
||||
`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `
|
||||
`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
let notUsesThis2 = function() {
|
||||
return class { method() { this; } }
|
||||
}
|
||||
`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `export function exported() {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `async function asyncFunction() {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `
|
||||
let b = function () {};
|
||||
((func) => func())(function e(): void {});
|
||||
`,
|
||||
options: [{ allowDeclarations: true }],
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }, { messageId: "onlyArrowFunctionsError" }],
|
||||
}, {
|
||||
code: `const x = function() {}`,
|
||||
options: [{ allowNamedFunctions: true }],
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
}],
|
||||
`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `export function exported() {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `async function asyncFunction() {}`,
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
{
|
||||
code: `
|
||||
let b = function () {};
|
||||
((func) => func())(function e(): void {});
|
||||
`,
|
||||
options: [{ allowDeclarations: true }],
|
||||
errors: [
|
||||
{ messageId: "onlyArrowFunctionsError" },
|
||||
{ messageId: "onlyArrowFunctionsError" },
|
||||
],
|
||||
},
|
||||
{
|
||||
code: `const x = function() {}`,
|
||||
options: [{ allowNamedFunctions: true }],
|
||||
errors: [{ messageId: "onlyArrowFunctionsError" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
|
|
@ -9,27 +9,37 @@ const ruleTester = new RuleTester({
|
|||
});
|
||||
|
||||
ruleTester.run("type-operator-spacing", rule, {
|
||||
valid: [{
|
||||
code: `type T = string | number`,
|
||||
}, {
|
||||
code: `type T = string & number`,
|
||||
}, {
|
||||
code: `function fn(): string | number {}`,
|
||||
}, {
|
||||
code: `function fn(): string & number {}`,
|
||||
}],
|
||||
valid: [
|
||||
{
|
||||
code: `type T = string | number`,
|
||||
},
|
||||
{
|
||||
code: `type T = string & number`,
|
||||
},
|
||||
{
|
||||
code: `function fn(): string | number {}`,
|
||||
},
|
||||
{
|
||||
code: `function fn(): string & number {}`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [{
|
||||
code: `type T = string|number`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
}, {
|
||||
code: `type T = string&number`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
}, {
|
||||
code: `function fn(): string|number {}`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
}, {
|
||||
code: `function fn(): string&number {}`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
}],
|
||||
invalid: [
|
||||
{
|
||||
code: `type T = string|number`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
},
|
||||
{
|
||||
code: `type T = string&number`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
},
|
||||
{
|
||||
code: `function fn(): string|number {}`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
},
|
||||
{
|
||||
code: `function fn(): string&number {}`,
|
||||
errors: [{ messageId: "typeOperatorSpacingError" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue