Default useArrowFunction is wrong when using mocha #9558
Replies: 2 comments 1 reply
-
|
You're right — Mocha binds Until the rule gets a built-in option to detect Mocha/other test framework contexts, you can work around it with an override in your {
"overrides": [
{
"include": ["**/*.test.{js,ts}", "**/*.spec.{js,ts}", "**/test/**"],
"linter": {
"rules": {
"style": {
"useArrowFunction": "off"
}
}
}
}
]
}This disables the rule only in test files while keeping it active everywhere else. If you want something more targeted (only disabling it inside This would be a good candidate for a rule option, similar to how |
Beta Was this translation helpful? Give feedback.
-
|
Good catch. Mocha explicitly discourages arrow functions because it binds Until Biome adds framework-aware configuration for {
"overrides": [
{
"includes": ["**/*.test.{js,ts}", "**/*.spec.{js,ts}", "**/test/**"],
"linter": {
"rules": {
"style": {
"useArrowFunction": "off"
}
}
}
}
]
}This keeps the rule active for your application code while disabling it where Mocha needs regular functions. For a more targeted approach, you could also use inline suppression: // biome-ignore lint/style/useArrowFunction: mocha binds this to test context
describe(function () {
this.timeout(5000);
});The |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Within mocha function calls (e.g.
describe(),test()) theuseArrowFunctionrule should be disabled.Mocha binds
thisto the test context, so using an arrow function will lose access to this context. In fact, it is actively discouraged in their docs.Beta Was this translation helpful? Give feedback.
All reactions