Skip to content

Commit a3d194d

Browse files
feat: lint kebab case
1 parent c6acb93 commit a3d194d

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file Format filenames to adhere to autofixable style guidelines.
3+
* @author The OpenINF Authors & Friends
4+
* @license MIT OR Apache-2.0 OR BlueOak-1.0.0
5+
* @module {type ES6Module} build/tasks/format/format-filenames
6+
*/
7+
8+
import { promises as fsp, readdirSync, renameSync } from 'node:fs';
9+
import { format as pathFormat, parse as pathParse } from 'node:path';
10+
import { kebabCase } from 'change-case';
11+
import recursive from 'recursive-readdir';
12+
13+
recursive(
14+
'.',
15+
['.git', 'node_modules/', '_site/', 'vendor/'],
16+
(err, filepaths) => {
17+
for (path of filepaths) {
18+
const parsedPath = pathParse(path);
19+
20+
if (
21+
parsedPath.ext === '.ts' &&
22+
!parsedPath.name.endsWith('.d') &&
23+
parsedPath.name !== kebabCase(parsedPath.name)
24+
) {
25+
parsedPath.name = kebabCase(parsedPath.name);
26+
// If parsedPath.base exists, parsedPath.ext & parsedPath.name are ignored.
27+
parsedPath.base = undefined;
28+
renameSync(path, pathFormat(parsedPath));
29+
}
30+
}
31+
}
32+
);

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
"@openinf/util-text": "1.1.2",
2929
"@openinf/util-types": "2.1.3",
3030
"@shopify/prettier-plugin-liquid": "1.5.0",
31+
"@types/recursive-readdir": "2.2.4",
3132
"@yarnpkg/shell": "4.0.2",
3233
"autoprefixer": "10.4.19",
34+
"change-case": "5.4.4",
3335
"cross-env": "7.0.3",
3436
"cross-spawn": "7.0.3",
3537
"cspell": "8.8.4",
@@ -54,6 +56,7 @@
5456
"markdownlint-cli2-formatter-default": "0.0.4",
5557
"nps": "5.10.0",
5658
"prettier": "3.3.2",
59+
"recursive-readdir": "2.2.3",
5760
"remark": "15.0.1",
5861
"remark-cli": "12.0.1",
5962
"remark-directive": "3.0.0",

pnpm-lock.yaml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)