code: "import\n(source)",
options: ["always", { allowNewlines: true }],
parserOptions: { ecmaVersion: 2020 }
+ },
+
+ // Optional chaining
+ {
+ code: "func?.()",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 2020 }
+ },
+ {
+ code: "func ?.()",
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 }
+ },
+ {
+ code: "func?. ()",
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 }
+ },
+ {
+ code: "func ?. ()",
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 }
}
],
invalid: [
},
{
code: "f\n();",
- output: "f ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
},
{
code: "f\n(a, b);",
- output: "f (a, b);",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
},
{
code: "f.b\n();",
- output: "f.b ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [
{
},
{
code: "f.b\n().c ();",
- output: "f.b ().c ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [
{
},
{
code: "f\n() ()",
- output: "f () ()",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\n()()",
- output: "f () ()",
+ output: "f\n() ()", // Don't fix the first error to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [
{ messageId: "unexpectedNewline", type: "CallExpression" },
},
{
code: "f\r();",
- output: "f ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\u2028();",
- output: "f ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\u2029();",
- output: "f ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
{
code: "f\r\n();",
- output: "f ();",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [{ messageId: "unexpectedNewline", type: "CallExpression" }]
},
},
{
code: "fnn\n (a, b);",
- output: "fnn (a, b);",
+ output: null, // Don't fix to avoid hiding no-unexpected-multiline (https://github.com/eslint/eslint/issues/7787)
options: ["always"],
errors: [
{
endColumn: 2
}
]
+ },
+ {
+ code: "f /*comment*/ ()",
+ output: null, // Don't remove comments
+ options: ["never"],
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "f /*\n*/ ()",
+ output: null, // Don't remove comments
+ options: ["never"],
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "f/*comment*/()",
+ output: "f/*comment*/ ()",
+ options: ["always"],
+ errors: [{ messageId: "missing" }]
+ },
+
+ // Optional chaining
+ {
+ code: "func ?.()",
+ output: "func?.()",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "func?. ()",
+ output: "func?.()",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "func ?. ()",
+ output: "func?.()",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "func\n?.()",
+ output: "func?.()",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "func\n//comment\n?.()",
+ output: null, // Don't remove comments
+ options: ["never"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedWhitespace" }]
+ },
+ {
+ code: "func?.()",
+ output: null, // Not sure inserting a space into either before/after `?.`.
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "missing" }]
+ },
+ {
+ code: "func\n ?.()",
+ output: "func ?.()",
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedNewline" }]
+ },
+ {
+ code: "func?.\n ()",
+ output: "func?. ()",
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedNewline" }]
+ },
+ {
+ code: "func ?.\n ()",
+ output: "func ?. ()",
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedNewline" }]
+ },
+ {
+ code: "func\n /*comment*/ ?.()",
+ output: null, // Don't remove comments
+ options: ["always"],
+ parserOptions: { ecmaVersion: 2020 },
+ errors: [{ messageId: "unexpectedNewline" }]
}
]
});