Skip to content

Commit 5e9c33c

Browse files
committed
Remove accidentally duplicated array elements, change indentation and more
- extract code into a separate function "getBaseFileName"
1 parent 85ca779 commit 5e9c33c

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

lib/license-files.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import path from 'node:path';
22

33
const BASENAMES_PRECEDENCE = [
4-
/^LICENSE$/,
5-
/^LICENSE\-\w+$/, // e.g. LICENSE-MIT
6-
/^LICENCE$/,
7-
/^LICENCE\-\w+$/, // e.g. LICENCE-MIT
8-
/^MIT-LICENSE$/,
9-
/^COPYING$/,
10-
/^README$/, // TODO: should we really include README?
4+
/^LICENSE$/,
5+
/^LICENSE\-\w+$/, // e.g. LICENSE-MIT
6+
/^MIT-LICENSE$/,
7+
/^COPYING$/,
8+
/^README$/, // TODO: should we really include README?
119
];
1210

1311
// Find and list license files in the precedence order
1412
const licenseFiles = (dirFiles) => {
15-
const files = [];
13+
const files = [];
1614

17-
BASENAMES_PRECEDENCE.forEach((basenamePattern) => {
18-
dirFiles.some((filename) => {
19-
const basename = path.basename(filename, path.extname(filename)).toUpperCase();
15+
BASENAMES_PRECEDENCE.forEach((basenamePattern) => {
16+
dirFiles.some((filename) => {
17+
const basename = getBaseFileName(filename);
2018

21-
if (basenamePattern.test(basename)) {
22-
files.push(filename);
23-
return true;
24-
}
19+
if (basenamePattern.test(basename)) {
20+
files.push(filename);
2521

26-
return false;
27-
});
28-
});
22+
return true;
23+
}
2924

30-
return files;
25+
return false;
26+
});
27+
});
28+
29+
return files;
30+
};
31+
32+
const getBaseFileName = (filename) => {
33+
return path.basename(filename, path.extname(filename)).toUpperCase();
3134
};
35+
3236
export { licenseFiles };

0 commit comments

Comments
 (0)