From 277015e8fa4b4be9b5dd1eb6c41819dd0cf5c64a Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Fri, 14 Jun 2024 23:15:04 -0400 Subject: [PATCH 1/3] feat: lint kebab case --- build/tasks/format/format-filenames.mjs | 32 ++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 36 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 build/tasks/format/format-filenames.mjs diff --git a/build/tasks/format/format-filenames.mjs b/build/tasks/format/format-filenames.mjs new file mode 100644 index 000000000..d4af32654 --- /dev/null +++ b/build/tasks/format/format-filenames.mjs @@ -0,0 +1,32 @@ +/** + * @file Format filenames to adhere to autofixable style guidelines. + * @author The OpenINF Authors & Friends + * @license MIT OR Apache-2.0 OR BlueOak-1.0.0 + * @module {type ES6Module} build/tasks/format/format-filenames + */ + +import { promises as fsp, readdirSync, renameSync } from 'node:fs'; +import { format as pathFormat, parse as pathParse } from 'node:path'; +import { kebabCase } from 'change-case'; +import recursive from 'recursive-readdir'; + +recursive( + '.', + ['.git', 'node_modules/', '_site/', 'vendor/'], + (err, filepaths) => { + for (path of filepaths) { + const parsedPath = pathParse(path); + + if ( + parsedPath.ext === '.ts' && + !parsedPath.name.endsWith('.d') && + parsedPath.name !== kebabCase(parsedPath.name) + ) { + parsedPath.name = kebabCase(parsedPath.name); + // If parsedPath.base exists, parsedPath.ext & parsedPath.name are ignored. + parsedPath.base = undefined; + renameSync(path, pathFormat(parsedPath)); + } + } + } +); diff --git a/package.json b/package.json index 2889513f9..ba10020d0 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "markdownlint-cli2-formatter-default": "0.0.4", "nps": "5.10.0", "prettier": "3.3.2", + "recursive-readdir": "2.2.3", "remark": "15.0.1", "remark-cli": "12.0.1", "remark-directive": "3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c58c67fa..b8213759a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -113,6 +113,9 @@ importers: prettier: specifier: 3.3.2 version: 3.3.2 + recursive-readdir: + specifier: 2.2.3 + version: 2.2.3 remark: specifier: 15.0.1 version: 15.0.1 @@ -1077,6 +1080,9 @@ packages: boolbase@1.0.0: resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==} + brace-expansion@1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} @@ -1132,6 +1138,9 @@ packages: resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + change-case@5.4.4: + resolution: {integrity: sha512-HRQyTk2/YPEkt9TnUPbOpr64Uw3KOicFWPVBb+xiHvd6eBx/qPr9xqfBFDT8P2vWsvvz4jbEkfDe71W3VyNu2w==} + character-entities-html4@2.1.0: resolution: {integrity: sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==} @@ -1223,6 +1232,9 @@ packages: resolution: {integrity: sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==} engines: {node: '>=4.0.0'} + concat-map@0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + concat-stream@2.0.0: resolution: {integrity: sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==} engines: {'0': node >= 6.0} @@ -2424,6 +2436,9 @@ packages: resolution: {integrity: sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==} engines: {node: '>=8.6'} + minimatch@3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} + minimatch@9.0.4: resolution: {integrity: sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==} engines: {node: '>=16 || 14 >=14.17'} @@ -2935,6 +2950,10 @@ packages: resolution: {integrity: sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==} engines: {node: '>= 10.13.0'} + recursive-readdir@2.2.3: + resolution: {integrity: sha512-8HrF5ZsXk5FAH9dgsx3BlUer73nIhuj+9OrQwEbLTPOBzGkL1lsFCR01am+v+0m2Cmbs1nP12hLDl5FA7EszKA==} + engines: {node: '>=6.0.0'} + remark-cli@12.0.1: resolution: {integrity: sha512-2NAEOACoTgo+e+YAaCTODqbrWyhMVmlUyjxNCkTrDRHHQvH6+NbrnqVvQaLH/Q8Ket3v90A43dgAJmXv8y5Tkw==} hasBin: true @@ -4577,6 +4596,11 @@ snapshots: boolbase@1.0.0: {} + brace-expansion@1.1.11: + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + brace-expansion@2.0.1: dependencies: balanced-match: 1.0.2 @@ -4636,6 +4660,8 @@ snapshots: chalk@5.3.0: {} + change-case@5.4.4: {} + character-entities-html4@2.1.0: {} character-entities-legacy@3.0.0: {} @@ -4727,6 +4753,8 @@ snapshots: common-tags@1.8.2: {} + concat-map@0.0.1: {} + concat-stream@2.0.0: dependencies: buffer-from: 1.1.2 @@ -6376,6 +6404,10 @@ snapshots: braces: 3.0.3 picomatch: 2.3.1 + minimatch@3.1.2: + dependencies: + brace-expansion: 1.1.11 + minimatch@9.0.4: dependencies: brace-expansion: 2.0.1 @@ -6864,6 +6896,10 @@ snapshots: dependencies: resolve: 1.22.8 + recursive-readdir@2.2.3: + dependencies: + minimatch: 3.1.2 + remark-cli@12.0.1: dependencies: import-meta-resolve: 4.1.0 From 67db947f87593d9b554ffa49d6a90eeac441219a Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Sun, 16 Jun 2024 13:22:47 -0400 Subject: [PATCH 2/3] bring branch up-to-speed --- .../{format-filenames.mjs => format-filenames.mts} | 0 package.json | 2 ++ pnpm-lock.yaml | 13 +++++++++++++ 3 files changed, 15 insertions(+) rename build/tasks/format/{format-filenames.mjs => format-filenames.mts} (100%) diff --git a/build/tasks/format/format-filenames.mjs b/build/tasks/format/format-filenames.mts similarity index 100% rename from build/tasks/format/format-filenames.mjs rename to build/tasks/format/format-filenames.mts diff --git a/package.json b/package.json index ba10020d0..e968becad 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,10 @@ "@shopify/prettier-plugin-liquid": "1.5.0", "@tsconfig/node-lts": "20.1.3", "@types/node": "20.14.2", + "@types/recursive-readdir": "2.2.4", "@yarnpkg/shell": "4.0.2", "autoprefixer": "10.4.19", + "change-case": "5.4.4", "cspell": "8.8.4", "cssnano": "7.0.2", "dictionary-en": "4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b8213759a..30f953315 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,12 +41,18 @@ importers: '@types/node': specifier: 20.14.2 version: 20.14.2 + '@types/recursive-readdir': + specifier: 2.2.4 + version: 2.2.4 '@yarnpkg/shell': specifier: 4.0.2 version: 4.0.2(typanion@3.14.0) autoprefixer: specifier: 10.4.19 version: 10.4.19(postcss@8.4.38) + change-case: + specifier: 5.4.4 + version: 5.4.4 cspell: specifier: 8.8.4 version: 8.8.4 @@ -898,6 +904,9 @@ packages: '@types/pluralize@0.0.29': resolution: {integrity: sha512-BYOID+l2Aco2nBik+iYS4SZX0Lf20KPILP5RGmM1IgzdwNdTs0eebiFriOPcej1sX9mLnSoiNte5zcFxssgpGA==} + '@types/recursive-readdir@2.2.4': + resolution: {integrity: sha512-84REEGT3lcgopvpkmGApzmU5UEG0valme5rQS/KGiguTkJ70/Au8UYZTyrzoZnY9svuX9351+1uvrRPzWDD/uw==} + '@types/supports-color@8.1.3': resolution: {integrity: sha512-Hy6UMpxhE3j1tLpl27exp1XqHD7n8chAiNPzWfz16LPZoMMoSc4dzLl6w9qijkEb/r5O1ozdu1CWGA2L83ZeZg==} @@ -4443,6 +4452,10 @@ snapshots: '@types/pluralize@0.0.29': {} + '@types/recursive-readdir@2.2.4': + dependencies: + '@types/node': 20.14.2 + '@types/supports-color@8.1.3': {} '@types/text-table@0.2.5': {} From c103036f31c5e9719441900591cfc6fa07c34691 Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Sun, 16 Jun 2024 14:29:09 -0400 Subject: [PATCH 3/3] this is still missing logging --- build/tasks/format/format-filenames.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/tasks/format/format-filenames.mts b/build/tasks/format/format-filenames.mts index d4af32654..bd4c9e451 100644 --- a/build/tasks/format/format-filenames.mts +++ b/build/tasks/format/format-filenames.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-filenames */ -import { promises as fsp, readdirSync, renameSync } from 'node:fs'; +import { renameSync } from 'node:fs'; import { format as pathFormat, parse as pathParse } from 'node:path'; import { kebabCase } from 'change-case'; import recursive from 'recursive-readdir';