Skip to content

Commit eef345a

Browse files
authored
Ignore findBy calls from ember-cli-mirage in no-array-prototype-extensions (#2331)
* Ignore `findBy` calls from `ember-cli-mirage` in `no-array-prototype-extensions` * Add tests for ember-cli-mirage exceptions for `findBy` * Fix prettier errors * Remove `window|undefined` from exception regexp
1 parent 8e4b717 commit eef345a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/rules/no-array-prototype-extensions.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ const KNOWN_NON_ARRAY_FUNCTION_CALLS = new Set([
8989
'sessionStorage.clear()',
9090
]);
9191

92+
/**
93+
* Ignore these function calls using RegExps.
94+
*/
95+
const KNOWN_NON_ARRAY_FUNCTION_CALLS_REGEXP = new Set([
96+
// ember-cli-mirage
97+
/\.server\.schema\.(.*)\.findBy\(\)/,
98+
]);
99+
92100
/**
93101
* Ignore objects of these names.
94102
*/
@@ -692,6 +700,13 @@ module.exports = {
692700
return;
693701
}
694702

703+
for (const expression of KNOWN_NON_ARRAY_FUNCTION_CALLS_REGEXP) {
704+
// Ignore any known non-array function calls matching a regular expression to reduce false positives.
705+
if (expression.test(name)) {
706+
return;
707+
}
708+
}
709+
695710
for (const functionName of FN_NAMES_TO_KNOWN_NON_ARRAY_WORDS.keys()) {
696711
const words = FN_NAMES_TO_KNOWN_NON_ARRAY_WORDS.get(functionName);
697712
if (

tests/lib/rules/no-array-prototype-extensions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ ruleTester.run('no-array-prototype-extensions', rule, {
247247

248248
// TODO: handle non-Identifier property names:
249249
'foo["clear"]();',
250+
251+
// Common ember-cli-mirage calls
252+
'this.server.schema.users.findBy()',
253+
'this.server.schema.devices.findBy()',
254+
'this.server.schema.users.findBy({ foo: "bar" })',
255+
'this.server.schema.devices.findBy({ foo: "bar" })',
250256
],
251257
invalid: [
252258
{

0 commit comments

Comments
 (0)