Skip to content

Commit d697f65

Browse files
committed
Use positional check instead of directory blocklist
Check that tests/ or test/ is within the first 2 path segments (top-level or under a project name prefix) rather than hardcoding app/addon exclusions.
1 parent 76decf1 commit d697f65

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/rules/no-test-import-export.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ module.exports = {
7070

7171
function isInTestDirectory(filename) {
7272
const filenameParts = path.normalize(filename).split(path.sep);
73-
// Must contain a tests/ or test/ segment, and must not be under app/ or addon/
74-
const hasTestDir = filenameParts.includes('tests') || filenameParts.includes('test');
75-
const isAppCode = filenameParts.includes('app') || filenameParts.includes('addon');
76-
return hasTestDir && !isAppCode;
73+
const testDirIndex = filenameParts.findIndex((part) => part === 'tests' || part === 'test');
74+
// tests/ or test/ must be a top-level directory (index 0) or directly under
75+
// a project name (index 1, e.g. my-app/tests/). Deeper nesting like
76+
// app/components/tests/ is not a real test directory.
77+
return testDirIndex >= 0 && testDirIndex <= 1;
7778
}
7879

7980
function isTestHelperFilename(filename) {

0 commit comments

Comments
 (0)