Skip to content

Commit f83db1c

Browse files
committed
chore: improve .js extension linting script
1 parent 15e3ca0 commit f83db1c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

scripts/lint-local-js-imports.mjs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
// temp script to check for missing ".js" extensions in relative local imports
2+
// related oxlint issue: https://github.com/oxc-project/oxc/issues/19431
3+
14
import fs from 'node:fs';
25
import path from 'node:path';
36
import { styleText } from 'node:util';
47

5-
// temp script to check for missing ".js" extensions in relative local imports
6-
// related oxlint issue: https://github.com/oxc-project/oxc/issues/19431
7-
88
const roots = ['demos', 'frameworks', 'frameworks-plugins', 'packages'];
99
const excludedFolders = ['demos/aurelia/test', 'demos/react/test', 'demos/vue/test', 'frameworks/angular-slickgrid'];
1010
const allowedExtPattern = /\.(html|js|json|mjs|png|vue)(\?.*)?$/;
@@ -49,6 +49,7 @@ function walk(dir, acc) {
4949
}
5050
}
5151

52+
const startTime = performance.now();
5253
const files = [];
5354
for (const root of roots) {
5455
walk(root, files);
@@ -83,6 +84,9 @@ for (const filePath of scopedFiles) {
8384
}
8485
}
8586

87+
const endTime = performance.now();
88+
const elapsedTime = ((endTime - startTime) / 1000).toFixed(1);
89+
8690
if (errors.length > 0) {
8791
console.error(color(`Found ${errors.length} relative imports missing a file extension (.js, .json, .mjs, or .vue).`, ['red', 'bold']));
8892
console.error(color('Add the appropriate extension to the import path in the following lines:', 'yellow'));
@@ -96,7 +100,11 @@ if (errors.length > 0) {
96100

97101
console.error('');
98102
console.error(color(`Total violations: ${errors.length}`, ['red', 'bold']));
103+
console.error(`Finished in ${elapsedTime}s on ${scopedFiles.length} files.`);
99104
process.exit(1);
105+
} else {
106+
console.log('Found 0 violations.');
107+
console.log(`Finished in ${elapsedTime}s on ${scopedFiles.length} files.`);
100108
}
101109

102110
console.log(color('All relative imports have file extensions.', 'green'));

0 commit comments

Comments
 (0)