@servicetitan/folder-lint 40.2.2 → 40.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/folderSchema.d.ts +3 -3
- package/dist/folderSchema.d.ts.map +1 -1
- package/dist/folderSchema.js +1 -2
- package/dist/folderSchema.js.map +1 -1
- package/dist/namingConvention.js.map +1 -1
- package/package.json +6 -6
- package/src/folderSchema.ts +5 -6
- package/src/__tests__/file.test.ts +0 -21
- package/src/__tests__/folderSchema.test.ts +0 -518
- package/src/__tests__/lazy.test.ts +0 -50
- package/src/__tests__/namingConvention.test.ts +0 -64
package/dist/folderSchema.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface Folder {
|
|
|
8
8
|
/**
|
|
9
9
|
* folder name, it is ignored for the root Folder
|
|
10
10
|
* supports Glob
|
|
11
|
-
* https://github.com/isaacs/
|
|
11
|
+
* https://github.com/isaacs/minimatch#features
|
|
12
12
|
*/
|
|
13
13
|
name: string;
|
|
14
14
|
/**
|
|
@@ -25,14 +25,14 @@ export interface Folder {
|
|
|
25
25
|
* used to check full file name with extension
|
|
26
26
|
* no path before filename is captured
|
|
27
27
|
* supports Glob
|
|
28
|
-
* https://github.com/isaacs/
|
|
28
|
+
* https://github.com/isaacs/minimatch#features
|
|
29
29
|
*/
|
|
30
30
|
allowedFiles?: string | string[];
|
|
31
31
|
/**
|
|
32
32
|
* defaults to value in previous node or empty array if no previous value
|
|
33
33
|
* used to check only the part that starts after first dot
|
|
34
34
|
* supports Glob
|
|
35
|
-
* https://github.com/isaacs/
|
|
35
|
+
* https://github.com/isaacs/minimatch#features
|
|
36
36
|
*/
|
|
37
37
|
allowedExtensions?: string | string[];
|
|
38
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folderSchema.d.ts","sourceRoot":"","sources":["../src/folderSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"folderSchema.d.ts","sourceRoot":"","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AE,MAAM,EAAE,EAC3B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACnB,OAAO,EAAE,CASX;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAE1E;AAED;;GAEG;AACH,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/folderSchema.js
CHANGED
|
@@ -55,7 +55,6 @@ _export(exports, {
|
|
|
55
55
|
return splitFilename;
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
const _glob = require("glob");
|
|
59
58
|
const _minimatch = require("minimatch");
|
|
60
59
|
const _failures = require("./failures");
|
|
61
60
|
const _file = require("./file");
|
|
@@ -217,7 +216,7 @@ function checkFileExt(allowedExtensions, fileName, folderName) {
|
|
|
217
216
|
return [];
|
|
218
217
|
}
|
|
219
218
|
function compareByMagicInName(a, b) {
|
|
220
|
-
return +
|
|
219
|
+
return +new _minimatch.Minimatch(a.name).hasMagic() - +new _minimatch.Minimatch(b.name).hasMagic();
|
|
221
220
|
}
|
|
222
221
|
// = T & { [P in K]-?: T[P]; };
|
|
223
222
|
|
package/dist/folderSchema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/folderSchema.ts"],"sourcesContent":["import { glob } from 'glob';\nimport { minimatch } from 'minimatch';\nimport {\n allowedExtensionsFailure,\n allowedFilesFailure,\n allowedFolderNameFailure,\n Failure,\n fileNamingConventionFailure,\n folderNamingConventionFailure,\n} from './failures';\nimport { getFileBasename, getFileExtension } from './file';\nimport { alwaysLazy, MaybeLazy, memoizeConst } from './lazy';\nimport { NamingConvention } from './namingConvention';\n\n/**\n * `Folder` represents tree-like folder schema\n */\nexport interface Folder {\n /**\n * folder name, it is ignored for the root Folder\n * supports Glob\n * https://github.com/isaacs/node-glob#glob-primer\n */\n name: string;\n\n /**\n * defaults to undefined\n * has to be set at least on the root Folder\n */\n namingConvention?: NamingConvention;\n\n /**\n * defaults to []\n */\n children?: MaybeLazy<Folder> | MaybeLazy<Folder>[];\n\n /**\n * defaults to ['*']\n * used to check full file name with extension\n * no path before filename is captured\n * supports Glob\n * https://github.com/isaacs/node-glob#glob-primer\n */\n allowedFiles?: string | string[];\n\n /**\n * defaults to value in previous node or empty array if no previous value\n * used to check only the part that starts after first dot\n * supports Glob\n * https://github.com/isaacs/node-glob#glob-primer\n */\n allowedExtensions?: string | string[];\n\n /**\n * defaults to true, but takes effect only if allowedExtensions is not undefined\n * if false parent extensions are getting concatenated with current ones\n */\n overrideExtensions?: boolean;\n\n /**\n * defaults to false\n * if true then all content will be considered valid.\n */\n ignore?: boolean;\n}\n\nexport interface ParentFolder extends Folder {\n namingConvention: NamingConvention;\n}\n\nexport type RootFolder = MaybeLazy<ParentFolder>;\n\nexport function checkPath(rawCfg: RootFolder) {\n const cfg = canonicalizeConfig(alwaysLazy(rawCfg));\n const memoCfg = memoizeConfig(cfg)();\n\n return (filename: string): Failure[] => {\n const pathParts = splitFilename(filename);\n return checkFolder(memoCfg, pathParts, '<root>');\n };\n}\n\nexport function canonicalizeConfig(lazyFolder: () => ParentFolder): LazyCanonicalFolder {\n return (): CanonicalFolder => {\n const folder = lazyFolder();\n\n const allowedExtensions = alwaysArray(folder.allowedExtensions);\n\n const children = alwaysArray(folder.children)\n .map(alwaysLazy)\n .map(lazyChild => () => inheritNamingConvention(folder.namingConvention, lazyChild()))\n .map(lazyChild => () => inheritAllowedExtensions(allowedExtensions, lazyChild()))\n .map(canonicalizeConfig);\n\n return {\n ...folder,\n\n allowedExtensions,\n children,\n\n ignore: !!folder.ignore,\n allowedFiles: canonicalizeAllowedFiles(folder.allowedFiles),\n };\n };\n}\n\nexport function memoizeConfig(lazyFolder: LazyCanonicalFolder): LazyCanonicalFolder {\n return memoizeConst(() => {\n const folder = lazyFolder();\n const children = folder.children.map(memoizeConfig);\n\n return {\n ...folder,\n children,\n };\n });\n}\n\nexport function canonicalizeAllowedFiles(files: string | string[] = ['*']): string[] {\n return alwaysArray(files);\n}\n\nexport function alwaysArray<T>(es: T | T[] = []): T[] {\n return Array.isArray(es) ? es : [es];\n}\n\nexport interface CanonicalFolder extends ParentFolder {\n children: LazyCanonicalFolder[];\n allowedFiles: string[];\n allowedExtensions: string[];\n ignore: boolean;\n}\n\nexport type LazyCanonicalFolder = () => CanonicalFolder;\n\nexport function inheritNamingConvention<T extends Folder>(\n parentNamingConvention: NamingConvention,\n child: T\n): RequiredProp<T, 'namingConvention'> {\n return {\n ...(child as any),\n namingConvention: child.namingConvention ?? parentNamingConvention,\n };\n}\n\nexport function inheritAllowedExtensions<T extends Folder>(\n parentAllowedExtensions: string[],\n child: T\n): RequiredProp<T, 'allowedExtensions'> {\n const overrideExtensions =\n child.overrideExtensions !== false && child.allowedExtensions !== undefined;\n\n const childAllowedExtensions = alwaysArray(child.allowedExtensions);\n\n const allowedExtensions = overrideExtensions\n ? childAllowedExtensions\n : [...parentAllowedExtensions, ...childAllowedExtensions];\n\n return {\n ...(child as any),\n allowedExtensions,\n };\n}\n\nexport function splitFilename(filename: string): string[] {\n const path = filename\n .replace(/\\\\/g, '/')\n .split('/')\n .filter(s => s.length > 0);\n\n if (path.length < 1) {\n return [''];\n }\n\n return path;\n}\n\nexport function isAllowedFolderName(pattern: string, folderName: string): boolean {\n return minimatch(folderName, pattern);\n}\n\nexport function checkFolder(\n cfg: CanonicalFolder,\n subPath: string[],\n folderName: string\n): Failure[] {\n if (cfg.ignore) {\n return [];\n }\n\n const isLastFolderInPath = subPath.length === 1;\n\n if (isLastFolderInPath) {\n const [fileName] = subPath;\n return [\n ...checkFileNamingConvention(cfg.namingConvention, fileName, folderName),\n ...checkFileName(cfg.allowedFiles, fileName, folderName),\n ...checkFileExt(cfg.allowedExtensions, fileName, folderName),\n ];\n }\n\n const [childFolderName, ...restPath] = subPath;\n\n const children = cfg.children\n .map(c => c()) // load children\n .sort(compareByMagicInName);\n\n const allowedChild = children.find(childCfg =>\n isAllowedFolderName(childCfg.name, childFolderName)\n );\n\n if (!allowedChild) {\n return [\n allowedFolderNameFailure({\n folderName: childFolderName,\n parentName: folderName,\n allowedNames: children.map(c => c.name),\n }),\n ];\n }\n\n return [\n ...checkFolderNamingConvention(cfg.namingConvention, childFolderName, folderName),\n ...checkFolder(allowedChild, restPath, childFolderName),\n ];\n}\n\nexport function checkFolderNamingConvention(\n namingConvention: NamingConvention,\n folderName: string,\n parentName: string\n): Failure[] {\n if (!NamingConvention.check(namingConvention, folderName)) {\n return [folderNamingConventionFailure({ folderName, parentName, namingConvention })];\n }\n\n return [];\n}\n\nexport function checkFileName(\n allowedFiles: string[],\n fileName: string,\n folderName: string\n): Failure[] {\n const isMatch = allowedFiles.some(af => minimatch(fileName, af));\n\n if (!isMatch) {\n return [allowedFilesFailure({ fileName, folderName, allowedFiles })];\n }\n\n return [];\n}\n\nexport function checkFileNamingConvention(\n namingConvention: NamingConvention,\n fileName: string,\n folderName: string\n): Failure[] {\n if (!NamingConvention.check(namingConvention, getFileBasename(fileName))) {\n return [fileNamingConventionFailure({ fileName, folderName, namingConvention })];\n }\n\n return [];\n}\n\nexport function checkFileExt(\n allowedExtensions: string[],\n fileName: string,\n folderName: string\n): Failure[] {\n const fileExt = getFileExtension(fileName);\n const isMatch = allowedExtensions.some(ae => minimatch(fileExt, ae));\n\n if (!isMatch) {\n return [allowedExtensionsFailure({ fileName, folderName, allowedExtensions })];\n }\n\n return [];\n}\n\nexport function compareByMagicInName<T extends { name: string }>(a: T, b: T) {\n return +glob.hasMagic(a.name) - +glob.hasMagic(b.name);\n}\n\n/**\n * Make K properties in T required\n */\ntype RequiredProp<T, K extends keyof T> = T & Required<Pick<T, K>>; // = T & { [P in K]-?: T[P]; };\n"],"names":["alwaysArray","canonicalizeAllowedFiles","canonicalizeConfig","checkFileExt","checkFileName","checkFileNamingConvention","checkFolder","checkFolderNamingConvention","checkPath","compareByMagicInName","inheritAllowedExtensions","inheritNamingConvention","isAllowedFolderName","memoizeConfig","splitFilename","rawCfg","cfg","alwaysLazy","memoCfg","filename","pathParts","lazyFolder","folder","allowedExtensions","children","map","lazyChild","namingConvention","ignore","allowedFiles","memoizeConst","files","es","Array","isArray","parentNamingConvention","child","parentAllowedExtensions","overrideExtensions","undefined","childAllowedExtensions","path","replace","split","filter","s","length","pattern","folderName","minimatch","subPath","isLastFolderInPath","fileName","childFolderName","restPath","c","sort","allowedChild","find","childCfg","name","allowedFolderNameFailure","parentName","allowedNames","NamingConvention","check","folderNamingConventionFailure","isMatch","some","af","allowedFilesFailure","getFileBasename","fileNamingConventionFailure","fileExt","getFileExtension","ae","allowedExtensionsFailure","a","b","glob","hasMagic"],"mappings":";;;;;;;;;;;QA0HgBA;eAAAA;;QAJAC;eAAAA;;QApCAC;eAAAA;;QAuLAC;eAAAA;;QA1BAC;eAAAA;;QAcAC;eAAAA;;QAxEAC;eAAAA;;QA8CAC;eAAAA;;QA3JAC;eAAAA;;QAgNAC;eAAAA;;QAvIAC;eAAAA;;QAVAC;eAAAA;;QA0CAC;eAAAA;;QAvEAC;eAAAA;;QA0DAC;eAAAA;;;sBApKK;2BACK;0BAQnB;sBAC2C;sBACE;kCACnB;AA4D1B,SAASN,UAAUO,MAAkB;IACxC,MAAMC,MAAMd,mBAAmBe,IAAAA,gBAAU,EAACF;IAC1C,MAAMG,UAAUL,cAAcG;IAE9B,OAAO,CAACG;QACJ,MAAMC,YAAYN,cAAcK;QAChC,OAAOb,YAAYY,SAASE,WAAW;IAC3C;AACJ;AAEO,SAASlB,mBAAmBmB,UAA8B;IAC7D,OAAO;QACH,MAAMC,SAASD;QAEf,MAAME,oBAAoBvB,YAAYsB,OAAOC,iBAAiB;QAE9D,MAAMC,WAAWxB,YAAYsB,OAAOE,QAAQ,EACvCC,GAAG,CAAC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AO;YAACkB,IAAAA,uCAA6B,EAAC;gBAAElB;gBAAYc;gBAAYnC;YAAiB;SAAG;IACxF;IAEA,OAAO,EAAE;AACb;AAEO,SAASvB,cACZyB,YAAsB,EACtBuB,QAAgB,EAChBJ,UAAkB;IAElB,MAAMmB,UAAUtC,aAAauC,IAAI,CAACC,CAAAA,KAAMpB,IAAAA,oBAAS,EAACG,UAAUiB;IAE5D,IAAI,CAACF,SAAS;QACV,OAAO;YAACG,IAAAA,6BAAmB,EAAC;gBAAElB;gBAAUJ;gBAAYnB;YAAa;SAAG;IACxE;IAEA,OAAO,EAAE;AACb;AAEO,SAASxB,0BACZsB,gBAAkC,EAClCyB,QAAgB,EAChBJ,UAAkB;IAElB,IAAI,CAACgB,kCAAgB,CAACC,KAAK,CAACtC,kBAAkB4C,IAAAA,qBAAe,EAACnB,YAAY;QACtE,OAAO;YAACoB,IAAAA,qCAA2B,EAAC;gBAAEpB;gBAAUJ;gBAAYrB;YAAiB;SAAG;IACpF;IAEA,OAAO,EAAE;AACb;AAEO,SAASxB,aACZoB,iBAA2B,EAC3B6B,QAAgB,EAChBJ,UAAkB;IAElB,MAAMyB,UAAUC,IAAAA,sBAAgB,EAACtB;IACjC,MAAMe,UAAU5C,kBAAkB6C,IAAI,CAACO,CAAAA,KAAM1B,IAAAA,oBAAS,EAACwB,SAASE;IAEhE,IAAI,CAACR,SAAS;QACV,OAAO;YAACS,IAAAA,kCAAwB,EAAC;gBAAExB;gBAAUJ;gBAAYzB;YAAkB;SAAG;IAClF;IAEA,OAAO,EAAE;AACb;AAEO,SAASd,qBAAiDoE,CAAI,EAAEC,CAAI;IACvE,OAAO,CAACC,UAAI,CAACC,QAAQ,CAACH,EAAEjB,IAAI,IAAI,CAACmB,UAAI,CAACC,QAAQ,CAACF,EAAElB,IAAI;AACzD;CAKoE,+BAA+B"}
|
|
1
|
+
{"version":3,"sources":["../src/folderSchema.ts"],"sourcesContent":["import { minimatch, Minimatch } from 'minimatch';\nimport {\n allowedExtensionsFailure,\n allowedFilesFailure,\n allowedFolderNameFailure,\n Failure,\n fileNamingConventionFailure,\n folderNamingConventionFailure,\n} from './failures';\nimport { getFileBasename, getFileExtension } from './file';\nimport { alwaysLazy, MaybeLazy, memoizeConst } from './lazy';\nimport { NamingConvention } from './namingConvention';\n\n/**\n * `Folder` represents tree-like folder schema\n */\nexport interface Folder {\n /**\n * folder name, it is ignored for the root Folder\n * supports Glob\n * https://github.com/isaacs/minimatch#features\n */\n name: string;\n\n /**\n * defaults to undefined\n * has to be set at least on the root Folder\n */\n namingConvention?: NamingConvention;\n\n /**\n * defaults to []\n */\n children?: MaybeLazy<Folder> | MaybeLazy<Folder>[];\n\n /**\n * defaults to ['*']\n * used to check full file name with extension\n * no path before filename is captured\n * supports Glob\n * https://github.com/isaacs/minimatch#features\n */\n allowedFiles?: string | string[];\n\n /**\n * defaults to value in previous node or empty array if no previous value\n * used to check only the part that starts after first dot\n * supports Glob\n * https://github.com/isaacs/minimatch#features\n */\n allowedExtensions?: string | string[];\n\n /**\n * defaults to true, but takes effect only if allowedExtensions is not undefined\n * if false parent extensions are getting concatenated with current ones\n */\n overrideExtensions?: boolean;\n\n /**\n * defaults to false\n * if true then all content will be considered valid.\n */\n ignore?: boolean;\n}\n\nexport interface ParentFolder extends Folder {\n namingConvention: NamingConvention;\n}\n\nexport type RootFolder = MaybeLazy<ParentFolder>;\n\nexport function checkPath(rawCfg: RootFolder) {\n const cfg = canonicalizeConfig(alwaysLazy(rawCfg));\n const memoCfg = memoizeConfig(cfg)();\n\n return (filename: string): Failure[] => {\n const pathParts = splitFilename(filename);\n return checkFolder(memoCfg, pathParts, '<root>');\n };\n}\n\nexport function canonicalizeConfig(lazyFolder: () => ParentFolder): LazyCanonicalFolder {\n return (): CanonicalFolder => {\n const folder = lazyFolder();\n\n const allowedExtensions = alwaysArray(folder.allowedExtensions);\n\n const children = alwaysArray(folder.children)\n .map(alwaysLazy)\n .map(lazyChild => () => inheritNamingConvention(folder.namingConvention, lazyChild()))\n .map(lazyChild => () => inheritAllowedExtensions(allowedExtensions, lazyChild()))\n .map(canonicalizeConfig);\n\n return {\n ...folder,\n\n allowedExtensions,\n children,\n\n ignore: !!folder.ignore,\n allowedFiles: canonicalizeAllowedFiles(folder.allowedFiles),\n };\n };\n}\n\nexport function memoizeConfig(lazyFolder: LazyCanonicalFolder): LazyCanonicalFolder {\n return memoizeConst(() => {\n const folder = lazyFolder();\n const children = folder.children.map(memoizeConfig);\n\n return {\n ...folder,\n children,\n };\n });\n}\n\nexport function canonicalizeAllowedFiles(files: string | string[] = ['*']): string[] {\n return alwaysArray(files);\n}\n\nexport function alwaysArray<T>(es: T | T[] = []): T[] {\n return Array.isArray(es) ? es : [es];\n}\n\nexport interface CanonicalFolder extends ParentFolder {\n children: LazyCanonicalFolder[];\n allowedFiles: string[];\n allowedExtensions: string[];\n ignore: boolean;\n}\n\nexport type LazyCanonicalFolder = () => CanonicalFolder;\n\nexport function inheritNamingConvention<T extends Folder>(\n parentNamingConvention: NamingConvention,\n child: T\n): RequiredProp<T, 'namingConvention'> {\n return {\n ...(child as any),\n namingConvention: child.namingConvention ?? parentNamingConvention,\n };\n}\n\nexport function inheritAllowedExtensions<T extends Folder>(\n parentAllowedExtensions: string[],\n child: T\n): RequiredProp<T, 'allowedExtensions'> {\n const overrideExtensions =\n child.overrideExtensions !== false && child.allowedExtensions !== undefined;\n\n const childAllowedExtensions = alwaysArray(child.allowedExtensions);\n\n const allowedExtensions = overrideExtensions\n ? childAllowedExtensions\n : [...parentAllowedExtensions, ...childAllowedExtensions];\n\n return {\n ...(child as any),\n allowedExtensions,\n };\n}\n\nexport function splitFilename(filename: string): string[] {\n const path = filename\n .replace(/\\\\/g, '/')\n .split('/')\n .filter(s => s.length > 0);\n\n if (path.length < 1) {\n return [''];\n }\n\n return path;\n}\n\nexport function isAllowedFolderName(pattern: string, folderName: string): boolean {\n return minimatch(folderName, pattern);\n}\n\nexport function checkFolder(\n cfg: CanonicalFolder,\n subPath: string[],\n folderName: string\n): Failure[] {\n if (cfg.ignore) {\n return [];\n }\n\n const isLastFolderInPath = subPath.length === 1;\n\n if (isLastFolderInPath) {\n const [fileName] = subPath;\n return [\n ...checkFileNamingConvention(cfg.namingConvention, fileName, folderName),\n ...checkFileName(cfg.allowedFiles, fileName, folderName),\n ...checkFileExt(cfg.allowedExtensions, fileName, folderName),\n ];\n }\n\n const [childFolderName, ...restPath] = subPath;\n\n const children = cfg.children\n .map(c => c()) // load children\n .sort(compareByMagicInName);\n\n const allowedChild = children.find(childCfg =>\n isAllowedFolderName(childCfg.name, childFolderName)\n );\n\n if (!allowedChild) {\n return [\n allowedFolderNameFailure({\n folderName: childFolderName,\n parentName: folderName,\n allowedNames: children.map(c => c.name),\n }),\n ];\n }\n\n return [\n ...checkFolderNamingConvention(cfg.namingConvention, childFolderName, folderName),\n ...checkFolder(allowedChild, restPath, childFolderName),\n ];\n}\n\nexport function checkFolderNamingConvention(\n namingConvention: NamingConvention,\n folderName: string,\n parentName: string\n): Failure[] {\n if (!NamingConvention.check(namingConvention, folderName)) {\n return [folderNamingConventionFailure({ folderName, parentName, namingConvention })];\n }\n\n return [];\n}\n\nexport function checkFileName(\n allowedFiles: string[],\n fileName: string,\n folderName: string\n): Failure[] {\n const isMatch = allowedFiles.some(af => minimatch(fileName, af));\n\n if (!isMatch) {\n return [allowedFilesFailure({ fileName, folderName, allowedFiles })];\n }\n\n return [];\n}\n\nexport function checkFileNamingConvention(\n namingConvention: NamingConvention,\n fileName: string,\n folderName: string\n): Failure[] {\n if (!NamingConvention.check(namingConvention, getFileBasename(fileName))) {\n return [fileNamingConventionFailure({ fileName, folderName, namingConvention })];\n }\n\n return [];\n}\n\nexport function checkFileExt(\n allowedExtensions: string[],\n fileName: string,\n folderName: string\n): Failure[] {\n const fileExt = getFileExtension(fileName);\n const isMatch = allowedExtensions.some(ae => minimatch(fileExt, ae));\n\n if (!isMatch) {\n return [allowedExtensionsFailure({ fileName, folderName, allowedExtensions })];\n }\n\n return [];\n}\n\nexport function compareByMagicInName<T extends { name: string }>(a: T, b: T) {\n return +new Minimatch(a.name).hasMagic() - +new Minimatch(b.name).hasMagic();\n}\n\n/**\n * Make K properties in T required\n */\ntype RequiredProp<T, K extends keyof T> = T & Required<Pick<T, K>>; // = T & { [P in K]-?: T[P]; };\n"],"names":["alwaysArray","canonicalizeAllowedFiles","canonicalizeConfig","checkFileExt","checkFileName","checkFileNamingConvention","checkFolder","checkFolderNamingConvention","checkPath","compareByMagicInName","inheritAllowedExtensions","inheritNamingConvention","isAllowedFolderName","memoizeConfig","splitFilename","rawCfg","cfg","alwaysLazy","memoCfg","filename","pathParts","lazyFolder","folder","allowedExtensions","children","map","lazyChild","namingConvention","ignore","allowedFiles","memoizeConst","files","es","Array","isArray","parentNamingConvention","child","parentAllowedExtensions","overrideExtensions","undefined","childAllowedExtensions","path","replace","split","filter","s","length","pattern","folderName","minimatch","subPath","isLastFolderInPath","fileName","childFolderName","restPath","c","sort","allowedChild","find","childCfg","name","allowedFolderNameFailure","parentName","allowedNames","NamingConvention","check","folderNamingConventionFailure","isMatch","some","af","allowedFilesFailure","getFileBasename","fileNamingConventionFailure","fileExt","getFileExtension","ae","allowedExtensionsFailure","a","b","Minimatch","hasMagic"],"mappings":";;;;;;;;;;;QAyHgBA;eAAAA;;QAJAC;eAAAA;;QApCAC;eAAAA;;QAuLAC;eAAAA;;QA1BAC;eAAAA;;QAcAC;eAAAA;;QAxEAC;eAAAA;;QA8CAC;eAAAA;;QA3JAC;eAAAA;;QAgNAC;eAAAA;;QAvIAC;eAAAA;;QAVAC;eAAAA;;QA0CAC;eAAAA;;QAvEAC;eAAAA;;QA0DAC;eAAAA;;;2BAnKqB;0BAQ9B;sBAC2C;sBACE;kCACnB;AA4D1B,SAASN,UAAUO,MAAkB;IACxC,MAAMC,MAAMd,mBAAmBe,IAAAA,gBAAU,EAACF;IAC1C,MAAMG,UAAUL,cAAcG;IAE9B,OAAO,CAACG;QACJ,MAAMC,YAAYN,cAAc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,OAAO,CAAC,IAAIC,oBAAS,CAACF,EAAEjB,IAAI,EAAEoB,QAAQ,KAAK,CAAC,IAAID,oBAAS,CAACD,EAAElB,IAAI,EAAEoB,QAAQ;AAC9E;CAKoE,+BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/namingConvention.ts"],"sourcesContent":["export enum NamingConvention {\n DashDelimitedLowercase = 'dash-delimited-lowercase',\n CamelCase = 'camelCase',\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace NamingConvention {\n export function check(conv: NamingConvention, name: string): boolean {\n if (name === '') {\n return true;\n }\n switch (conv) {\n case NamingConvention.DashDelimitedLowercase:\n return /^[a-z0-9_]+(-[a-z0-9_]+)*$/.test(name);\n case NamingConvention.CamelCase:\n return /^[a-z_][a-zA-Z0-9_]*$/.test(name);\n }\n }\n}\n"],"names":["NamingConvention","check","conv","name","test"],"mappings":";;;;+BAAYA;;;eAAAA;;;AAAL,IAAA,AAAKA
|
|
1
|
+
{"version":3,"sources":["../src/namingConvention.ts"],"sourcesContent":["export enum NamingConvention {\n DashDelimitedLowercase = 'dash-delimited-lowercase',\n CamelCase = 'camelCase',\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace NamingConvention {\n export function check(conv: NamingConvention, name: string): boolean {\n if (name === '') {\n return true;\n }\n switch (conv) {\n case NamingConvention.DashDelimitedLowercase:\n return /^[a-z0-9_]+(-[a-z0-9_]+)*$/.test(name);\n case NamingConvention.CamelCase:\n return /^[a-z_][a-zA-Z0-9_]*$/.test(name);\n }\n }\n}\n"],"names":["NamingConvention","check","conv","name","test"],"mappings":";;;;+BAAYA;;;eAAAA;;;AAAL,IAAA,AAAKA;;;;;UAMKA;IACN,SAASC,MAAMC,IAAsB,EAAEC,IAAY;QACtD,IAAIA,SAAS,IAAI;YACb,OAAO;QACX;QACA,OAAQD;YACJ;gBACI,OAAO,6BAA6BE,IAAI,CAACD;YAC7C;gBACI,OAAO,wBAAwBC,IAAI,CAACD;QAC5C;IACJ;qBAVgBF,QAAAA;AAWpB,GAZiBD,qBAAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/folder-lint",
|
|
3
|
-
"version": "40.
|
|
3
|
+
"version": "40.4.0",
|
|
4
4
|
"description": "Enum and types used to create an object with eslint-plugin-folder-schema configuration",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/uikit/folder-schema#servicetitanfolder-lint",
|
|
6
6
|
"repository": {
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"typings": "./dist/index.d.ts",
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
-
"src"
|
|
16
|
+
"src",
|
|
17
|
+
"!**/__tests__",
|
|
18
|
+
"!**/__mocks__",
|
|
19
|
+
"!**/__snapshots__",
|
|
20
|
+
"!**/*.test.*"
|
|
17
21
|
],
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"glob": "~13.0.6",
|
|
20
23
|
"minimatch": "~10.2.6"
|
|
21
24
|
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/glob": "~9.0.0"
|
|
24
|
-
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
package/src/folderSchema.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { minimatch } from 'minimatch';
|
|
1
|
+
import { minimatch, Minimatch } from 'minimatch';
|
|
3
2
|
import {
|
|
4
3
|
allowedExtensionsFailure,
|
|
5
4
|
allowedFilesFailure,
|
|
@@ -19,7 +18,7 @@ export interface Folder {
|
|
|
19
18
|
/**
|
|
20
19
|
* folder name, it is ignored for the root Folder
|
|
21
20
|
* supports Glob
|
|
22
|
-
* https://github.com/isaacs/
|
|
21
|
+
* https://github.com/isaacs/minimatch#features
|
|
23
22
|
*/
|
|
24
23
|
name: string;
|
|
25
24
|
|
|
@@ -39,7 +38,7 @@ export interface Folder {
|
|
|
39
38
|
* used to check full file name with extension
|
|
40
39
|
* no path before filename is captured
|
|
41
40
|
* supports Glob
|
|
42
|
-
* https://github.com/isaacs/
|
|
41
|
+
* https://github.com/isaacs/minimatch#features
|
|
43
42
|
*/
|
|
44
43
|
allowedFiles?: string | string[];
|
|
45
44
|
|
|
@@ -47,7 +46,7 @@ export interface Folder {
|
|
|
47
46
|
* defaults to value in previous node or empty array if no previous value
|
|
48
47
|
* used to check only the part that starts after first dot
|
|
49
48
|
* supports Glob
|
|
50
|
-
* https://github.com/isaacs/
|
|
49
|
+
* https://github.com/isaacs/minimatch#features
|
|
51
50
|
*/
|
|
52
51
|
allowedExtensions?: string | string[];
|
|
53
52
|
|
|
@@ -279,7 +278,7 @@ export function checkFileExt(
|
|
|
279
278
|
}
|
|
280
279
|
|
|
281
280
|
export function compareByMagicInName<T extends { name: string }>(a: T, b: T) {
|
|
282
|
-
return +
|
|
281
|
+
return +new Minimatch(a.name).hasMagic() - +new Minimatch(b.name).hasMagic();
|
|
283
282
|
}
|
|
284
283
|
|
|
285
284
|
/**
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getFileBasename, getFileExtension } from '../file';
|
|
2
|
-
|
|
3
|
-
describe('getFileBasename', () => {
|
|
4
|
-
test.each([
|
|
5
|
-
['file.ts', 'file'],
|
|
6
|
-
['file.store.ts', 'file'],
|
|
7
|
-
['file', 'file'],
|
|
8
|
-
['file.', 'file'],
|
|
9
|
-
['', ''],
|
|
10
|
-
])('%p -> %p', (filename, exp) => expect(getFileBasename(filename)).toBe(exp));
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('getFileExtension', () => {
|
|
14
|
-
test.each([
|
|
15
|
-
['file.ts', '.ts'],
|
|
16
|
-
['file.store.ts', '.store.ts'],
|
|
17
|
-
['file', ''],
|
|
18
|
-
['file.', '.'],
|
|
19
|
-
['', ''],
|
|
20
|
-
])('%p -> %p', (filename, exp) => expect(getFileExtension(filename)).toBe(exp));
|
|
21
|
-
});
|
|
@@ -1,518 +0,0 @@
|
|
|
1
|
-
import { Failure } from '../failures';
|
|
2
|
-
import {
|
|
3
|
-
alwaysArray,
|
|
4
|
-
canonicalizeAllowedFiles,
|
|
5
|
-
canonicalizeConfig,
|
|
6
|
-
checkFileExt,
|
|
7
|
-
checkFileName,
|
|
8
|
-
checkFileNamingConvention,
|
|
9
|
-
checkFolderNamingConvention,
|
|
10
|
-
checkPath,
|
|
11
|
-
compareByMagicInName,
|
|
12
|
-
Folder,
|
|
13
|
-
inheritAllowedExtensions,
|
|
14
|
-
inheritNamingConvention,
|
|
15
|
-
isAllowedFolderName,
|
|
16
|
-
LazyCanonicalFolder,
|
|
17
|
-
ParentFolder,
|
|
18
|
-
RootFolder,
|
|
19
|
-
splitFilename,
|
|
20
|
-
} from '../folderSchema';
|
|
21
|
-
import { NamingConvention } from '../namingConvention';
|
|
22
|
-
|
|
23
|
-
describe('splitFilename', () => {
|
|
24
|
-
// [fileName: string, expected: string[]][]
|
|
25
|
-
test.each([
|
|
26
|
-
['file.ts', ['file.ts']],
|
|
27
|
-
['/file.ts', ['file.ts']],
|
|
28
|
-
['\\file.ts', ['file.ts']],
|
|
29
|
-
|
|
30
|
-
['path/to/file.ts', ['path', 'to', 'file.ts']],
|
|
31
|
-
['/path/to/file.ts', ['path', 'to', 'file.ts']],
|
|
32
|
-
['\\path\\to\\file.ts', ['path', 'to', 'file.ts']],
|
|
33
|
-
['//path//to///file.ts', ['path', 'to', 'file.ts']],
|
|
34
|
-
|
|
35
|
-
['', ['']],
|
|
36
|
-
['/', ['']],
|
|
37
|
-
['\\', ['']],
|
|
38
|
-
['///', ['']],
|
|
39
|
-
])('(%p) -> %p', (filename, exp) => expect(splitFilename(filename)).toEqual(exp));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('allowedName(pattern, dirName) -> expected]', () => {
|
|
43
|
-
// [pattern: string, dirName: string, expected: boolean][]
|
|
44
|
-
test.each([
|
|
45
|
-
['utils', 'utils', true],
|
|
46
|
-
['api', 'utils', false],
|
|
47
|
-
|
|
48
|
-
['@(utils|api)', 'api', true],
|
|
49
|
-
['@(utils|api)', 'utils', true],
|
|
50
|
-
['@(utils|api)', 'utilsutils', false],
|
|
51
|
-
['@(utils|api)', 'stores', false],
|
|
52
|
-
|
|
53
|
-
['*', 'utils', true],
|
|
54
|
-
['*', 'api', true],
|
|
55
|
-
])('(%p, %p) -> %p', (pattern, dirName, expected) =>
|
|
56
|
-
expect(isAllowedFolderName(pattern, dirName)).toBe(expected)
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('checkFolderNamingConvention', () => {
|
|
61
|
-
// [namingConvention: NamingConvention, dirName: string, expectedFailures: Failure['type'][]][]
|
|
62
|
-
test.each([
|
|
63
|
-
[NamingConvention.DashDelimitedLowercase, 'module', []],
|
|
64
|
-
[NamingConvention.DashDelimitedLowercase, 'awesome-module', []],
|
|
65
|
-
[
|
|
66
|
-
NamingConvention.DashDelimitedLowercase,
|
|
67
|
-
'awesomeModule',
|
|
68
|
-
['folderNamingConventionFailure'],
|
|
69
|
-
],
|
|
70
|
-
[NamingConvention.DashDelimitedLowercase, '__tests__', []],
|
|
71
|
-
|
|
72
|
-
[NamingConvention.CamelCase, 'module', []],
|
|
73
|
-
[NamingConvention.CamelCase, 'awesomeModule', []],
|
|
74
|
-
[NamingConvention.CamelCase, 'awesome-module', ['folderNamingConventionFailure']],
|
|
75
|
-
[NamingConvention.CamelCase, '__tests__', []],
|
|
76
|
-
])('(%p, %p) -> %p', (convention, dirName, expected) =>
|
|
77
|
-
expectFailures(checkFolderNamingConvention(convention, dirName, 'foo'), expected)
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('checkFileName', () => {
|
|
82
|
-
// [allowedFiles: string[], fileName: string, expectedFailures: Failure['type'][]][]
|
|
83
|
-
test.each([
|
|
84
|
-
[['index.tsx'], 'index.tsx', []],
|
|
85
|
-
[['index.tsx'], '', ['allowedFilesFailure']],
|
|
86
|
-
[['index'], 'index.tsx', ['allowedFilesFailure']],
|
|
87
|
-
|
|
88
|
-
[['*'], 'awesome.tsx', []],
|
|
89
|
-
[['*'], '', ['allowedFilesFailure']],
|
|
90
|
-
|
|
91
|
-
[['index.@(tsx|ejs)'], 'index.tsx', []],
|
|
92
|
-
[['index.@(tsx|ejs)'], 'index.ejs', []],
|
|
93
|
-
[['index.@(tsx|ejs)'], 'index.ts', ['allowedFilesFailure']],
|
|
94
|
-
[['index.@(tsx|ejs)'], 'awesome.tsx', ['allowedFilesFailure']],
|
|
95
|
-
])('(%p, %p) -> %p', (allowedFiles, fileName, expected) =>
|
|
96
|
-
expectFailures(checkFileName(allowedFiles, fileName, 'foo'), expected)
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('checkFileNamingConvention', () => {
|
|
101
|
-
// [namingConvention: NamingConvention, fileName: string, expectedFailures: Failure['type'][]][]
|
|
102
|
-
test.each([
|
|
103
|
-
[NamingConvention.DashDelimitedLowercase, 'index.ts', []],
|
|
104
|
-
[NamingConvention.DashDelimitedLowercase, 'index', []],
|
|
105
|
-
[NamingConvention.DashDelimitedLowercase, 'awesome-store.ts', []],
|
|
106
|
-
[NamingConvention.DashDelimitedLowercase, 'awesome-store', []],
|
|
107
|
-
[NamingConvention.DashDelimitedLowercase, 'awesome-and-incredible.store.ts', []],
|
|
108
|
-
[
|
|
109
|
-
NamingConvention.DashDelimitedLowercase,
|
|
110
|
-
'awesomeStore.ts',
|
|
111
|
-
['fileNamingConventionFailure'],
|
|
112
|
-
],
|
|
113
|
-
[NamingConvention.DashDelimitedLowercase, 'awesomeStore', ['fileNamingConventionFailure']],
|
|
114
|
-
|
|
115
|
-
[NamingConvention.CamelCase, 'index.ts', []],
|
|
116
|
-
[NamingConvention.CamelCase, 'index', []],
|
|
117
|
-
[NamingConvention.CamelCase, 'awesome.store.ts', []],
|
|
118
|
-
[NamingConvention.CamelCase, 'awesome-store.ts', ['fileNamingConventionFailure']],
|
|
119
|
-
[NamingConvention.CamelCase, 'awesome-store', ['fileNamingConventionFailure']],
|
|
120
|
-
[NamingConvention.CamelCase, 'awesomeStore.ts', []],
|
|
121
|
-
[NamingConvention.CamelCase, 'awesomeAndIncredible.store.ts', []],
|
|
122
|
-
[NamingConvention.CamelCase, 'awesomeStore', []],
|
|
123
|
-
])('(%p, %p) -> %p', (convention, fileName, expected) =>
|
|
124
|
-
expectFailures(checkFileNamingConvention(convention, fileName, 'foo'), expected)
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('checkFileExt', () => {
|
|
129
|
-
// [allowedExtensions: string[], fileExt: string, expectedFailures: Failure['type'][]][]
|
|
130
|
-
test.each([
|
|
131
|
-
[['.ts'], '.ts', []],
|
|
132
|
-
[['.tsx'], '.ts', ['allowedExtensionsFailure']],
|
|
133
|
-
[['.ts'], '.api.ts', ['allowedExtensionsFailure']],
|
|
134
|
-
[['.ts', '.tsx'], '.ts', []],
|
|
135
|
-
[['.ts', '.tsx'], '.tsx', []],
|
|
136
|
-
[['.ts', '.tsx'], '.api.ts', ['allowedExtensionsFailure']],
|
|
137
|
-
|
|
138
|
-
[['.api.ts'], '.api.ts', []],
|
|
139
|
-
[['.api.ts'], '.store.ts', ['allowedExtensionsFailure']],
|
|
140
|
-
[['.api.ts'], '.ts', ['allowedExtensionsFailure']],
|
|
141
|
-
|
|
142
|
-
[['.*'], '.ts', []],
|
|
143
|
-
[['.*'], '.api.ts', []],
|
|
144
|
-
[['.*'], '.store.ts', []],
|
|
145
|
-
[['*'], '.ts', ['allowedExtensionsFailure']],
|
|
146
|
-
])('(%p, %p) -> %p', (allowedExtensions, fileExt, expected) =>
|
|
147
|
-
expectFailures(checkFileExt(allowedExtensions, fileExt, 'foo'), expected)
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('sort with compareByMagicInName', () => {
|
|
152
|
-
test.each([
|
|
153
|
-
[
|
|
154
|
-
[{ name: 'awesome.ts' }, { name: '*' }],
|
|
155
|
-
[{ name: 'awesome.ts' }, { name: '*' }],
|
|
156
|
-
],
|
|
157
|
-
[
|
|
158
|
-
[{ name: '*' }, { name: 'awesome.ts' }],
|
|
159
|
-
[{ name: 'awesome.ts' }, { name: '*' }],
|
|
160
|
-
],
|
|
161
|
-
[
|
|
162
|
-
[{ name: '*' }, { name: 'index.@(tsx|ejs)' }, { name: 'awesome.ts' }],
|
|
163
|
-
[{ name: 'awesome.ts' }, { name: '*' }, { name: 'index.@(tsx|ejs)' }],
|
|
164
|
-
],
|
|
165
|
-
])('%j -> %j', (strings, exp) => expect([...strings].sort(compareByMagicInName)).toEqual(exp));
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe('canonicalizeAllowedFiles', () => {
|
|
169
|
-
// [files: string | string[] | undefined, expected: string[]][]
|
|
170
|
-
test.each([
|
|
171
|
-
[undefined, ['*']],
|
|
172
|
-
['index.ts', ['index.ts']],
|
|
173
|
-
[['index.ts'], ['index.ts']],
|
|
174
|
-
[
|
|
175
|
-
['index.tsx', 'index.ejs'],
|
|
176
|
-
['index.tsx', 'index.ejs'],
|
|
177
|
-
],
|
|
178
|
-
[[], []],
|
|
179
|
-
])('%j -> %j', (allowedFiles, exp) =>
|
|
180
|
-
expect(canonicalizeAllowedFiles(allowedFiles)).toEqual(exp)
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe('alwaysArray', () => {
|
|
185
|
-
test.each([
|
|
186
|
-
[undefined, []],
|
|
187
|
-
|
|
188
|
-
[{ name: 'child' }, [{ name: 'child' }]],
|
|
189
|
-
[[{ name: 'child' }], [{ name: 'child' }]],
|
|
190
|
-
[
|
|
191
|
-
[{ name: 'child1' }, { name: 'child2' }],
|
|
192
|
-
[{ name: 'child1' }, { name: 'child2' }],
|
|
193
|
-
],
|
|
194
|
-
|
|
195
|
-
[[], []],
|
|
196
|
-
|
|
197
|
-
['.ts', ['.ts']],
|
|
198
|
-
[['.ts'], ['.ts']],
|
|
199
|
-
[
|
|
200
|
-
['.tsx', '.ejs'],
|
|
201
|
-
['.tsx', '.ejs'],
|
|
202
|
-
],
|
|
203
|
-
])('%j -> %j', (children, exp) => expect(alwaysArray(children)).toEqual(exp));
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
describe('inheritNamingConvention', () => {
|
|
207
|
-
test.each([
|
|
208
|
-
[
|
|
209
|
-
NamingConvention.DashDelimitedLowercase,
|
|
210
|
-
{ name: 'foo' },
|
|
211
|
-
NamingConvention.DashDelimitedLowercase,
|
|
212
|
-
],
|
|
213
|
-
[NamingConvention.CamelCase, { name: 'foo' }, NamingConvention.CamelCase],
|
|
214
|
-
[
|
|
215
|
-
NamingConvention.CamelCase,
|
|
216
|
-
{ name: 'foo', namingConvention: NamingConvention.DashDelimitedLowercase },
|
|
217
|
-
NamingConvention.DashDelimitedLowercase,
|
|
218
|
-
],
|
|
219
|
-
] as [NamingConvention, Folder, NamingConvention][])(
|
|
220
|
-
'(%p, %p) -> %p',
|
|
221
|
-
(convention: NamingConvention, dir: Folder, expected) =>
|
|
222
|
-
expect(inheritNamingConvention(convention, dir).namingConvention).toBe(expected)
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe('inheritAllowedExtensions', () => {
|
|
227
|
-
const cases: [
|
|
228
|
-
/* description */ string,
|
|
229
|
-
/* parent's allowedExtensions */ string[],
|
|
230
|
-
/* dir */ Folder,
|
|
231
|
-
/* expected */ string[],
|
|
232
|
-
][] = [
|
|
233
|
-
[
|
|
234
|
-
"use parent value when 'allowedExtensions' is undefined",
|
|
235
|
-
['.ts'],
|
|
236
|
-
{ name: 'foo' },
|
|
237
|
-
['.ts'],
|
|
238
|
-
],
|
|
239
|
-
|
|
240
|
-
[
|
|
241
|
-
"use value when 'allowedExtensions' is defined",
|
|
242
|
-
['.ts'],
|
|
243
|
-
{ name: 'foo', allowedExtensions: ['.*'] },
|
|
244
|
-
['.*'],
|
|
245
|
-
],
|
|
246
|
-
|
|
247
|
-
[
|
|
248
|
-
"'overrideExtensions' does not take effect when 'allowedExtensions' is undefined",
|
|
249
|
-
['.ts'],
|
|
250
|
-
{ name: 'foo', overrideExtensions: true },
|
|
251
|
-
['.ts'],
|
|
252
|
-
],
|
|
253
|
-
|
|
254
|
-
[
|
|
255
|
-
"'overrideExtensions' takes effect when 'allowedExtensions' is defined",
|
|
256
|
-
['.ts'],
|
|
257
|
-
{
|
|
258
|
-
name: 'foo',
|
|
259
|
-
overrideExtensions: true,
|
|
260
|
-
allowedExtensions: ['.*'],
|
|
261
|
-
},
|
|
262
|
-
['.*'],
|
|
263
|
-
],
|
|
264
|
-
|
|
265
|
-
[
|
|
266
|
-
"if 'overrideExtensions'=false then parent extensions are getting concatenated with current ones",
|
|
267
|
-
['.ts'],
|
|
268
|
-
{
|
|
269
|
-
name: 'foo',
|
|
270
|
-
overrideExtensions: false,
|
|
271
|
-
allowedExtensions: ['.*'],
|
|
272
|
-
},
|
|
273
|
-
['.ts', '.*'],
|
|
274
|
-
],
|
|
275
|
-
];
|
|
276
|
-
|
|
277
|
-
test.each(cases)(
|
|
278
|
-
'%s: (%p, %j) -> %p',
|
|
279
|
-
(_0, allowedExtensions: string[], dir: Folder, expected) =>
|
|
280
|
-
expect(inheritAllowedExtensions(allowedExtensions, dir).allowedExtensions).toEqual(
|
|
281
|
-
expected
|
|
282
|
-
)
|
|
283
|
-
);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
describe('canonicalizeConfig', () => {
|
|
287
|
-
const cases: [
|
|
288
|
-
/* description */ string,
|
|
289
|
-
/* raw */ ParentFolder,
|
|
290
|
-
/* expected */ LazyCanonicalFolder,
|
|
291
|
-
][] = [
|
|
292
|
-
[
|
|
293
|
-
'Fill defaults #1',
|
|
294
|
-
{ name: '<root>', namingConvention: NamingConvention.CamelCase },
|
|
295
|
-
() => ({
|
|
296
|
-
name: '<root>',
|
|
297
|
-
namingConvention: NamingConvention.CamelCase,
|
|
298
|
-
allowedFiles: ['*'],
|
|
299
|
-
allowedExtensions: [],
|
|
300
|
-
ignore: false,
|
|
301
|
-
children: [],
|
|
302
|
-
}),
|
|
303
|
-
],
|
|
304
|
-
|
|
305
|
-
[
|
|
306
|
-
'Fill defaults #2',
|
|
307
|
-
{
|
|
308
|
-
name: '<root>',
|
|
309
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
310
|
-
ignore: false,
|
|
311
|
-
children: [{ name: 'child', ignore: true }],
|
|
312
|
-
},
|
|
313
|
-
() => ({
|
|
314
|
-
name: '<root>',
|
|
315
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
316
|
-
allowedFiles: ['*'],
|
|
317
|
-
allowedExtensions: [],
|
|
318
|
-
ignore: false,
|
|
319
|
-
children: [
|
|
320
|
-
() => ({
|
|
321
|
-
name: 'child',
|
|
322
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
323
|
-
allowedFiles: ['*'],
|
|
324
|
-
allowedExtensions: [],
|
|
325
|
-
ignore: true,
|
|
326
|
-
children: [],
|
|
327
|
-
}),
|
|
328
|
-
],
|
|
329
|
-
}),
|
|
330
|
-
],
|
|
331
|
-
|
|
332
|
-
[
|
|
333
|
-
'Inherit parent values',
|
|
334
|
-
{
|
|
335
|
-
name: '<root>',
|
|
336
|
-
namingConvention: NamingConvention.CamelCase,
|
|
337
|
-
allowedFiles: 'index.ts',
|
|
338
|
-
allowedExtensions: '.*',
|
|
339
|
-
children: {
|
|
340
|
-
name: 'module',
|
|
341
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
342
|
-
allowedExtensions: ['.ts'],
|
|
343
|
-
children: [
|
|
344
|
-
() => ({
|
|
345
|
-
name: 'components',
|
|
346
|
-
overrideExtensions: false,
|
|
347
|
-
allowedExtensions: '.tsx',
|
|
348
|
-
}),
|
|
349
|
-
],
|
|
350
|
-
},
|
|
351
|
-
},
|
|
352
|
-
() => ({
|
|
353
|
-
name: '<root>',
|
|
354
|
-
namingConvention: NamingConvention.CamelCase,
|
|
355
|
-
allowedFiles: ['index.ts'],
|
|
356
|
-
allowedExtensions: ['.*'],
|
|
357
|
-
ignore: false,
|
|
358
|
-
children: [
|
|
359
|
-
() => ({
|
|
360
|
-
name: 'module',
|
|
361
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
362
|
-
allowedFiles: ['*'],
|
|
363
|
-
allowedExtensions: ['.ts'],
|
|
364
|
-
ignore: false,
|
|
365
|
-
children: [
|
|
366
|
-
() => ({
|
|
367
|
-
name: 'components',
|
|
368
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
369
|
-
allowedFiles: ['*'],
|
|
370
|
-
overrideExtensions: false,
|
|
371
|
-
allowedExtensions: ['.ts', '.tsx'],
|
|
372
|
-
ignore: false,
|
|
373
|
-
children: [],
|
|
374
|
-
}),
|
|
375
|
-
],
|
|
376
|
-
}),
|
|
377
|
-
],
|
|
378
|
-
}),
|
|
379
|
-
],
|
|
380
|
-
];
|
|
381
|
-
|
|
382
|
-
test.each(cases)('%s', (_0, rawFolder: ParentFolder, expected) =>
|
|
383
|
-
expectConfigsToEqual(
|
|
384
|
-
canonicalizeConfig(() => rawFolder),
|
|
385
|
-
expected
|
|
386
|
-
)
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
function expectConfigsToEqual(actual: LazyCanonicalFolder, expected: LazyCanonicalFolder) {
|
|
390
|
-
const { children: actualChildren, ...restActual } = actual();
|
|
391
|
-
const { children: expectedChildren, ...restExpected } = expected();
|
|
392
|
-
|
|
393
|
-
expect(restActual).toEqual(restExpected);
|
|
394
|
-
|
|
395
|
-
actualChildren.forEach((actualChild, index) => {
|
|
396
|
-
expectConfigsToEqual(actualChild, expectedChildren[index]);
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
describe('checkPath', () => {
|
|
402
|
-
describe('config#1', () => {
|
|
403
|
-
const config: RootFolder = {
|
|
404
|
-
name: '<root>',
|
|
405
|
-
namingConvention: NamingConvention.CamelCase,
|
|
406
|
-
allowedFiles: ['index.tsx'],
|
|
407
|
-
allowedExtensions: ['.*'],
|
|
408
|
-
children: [
|
|
409
|
-
{ name: '*' },
|
|
410
|
-
{
|
|
411
|
-
name: 'awesome',
|
|
412
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
413
|
-
allowedExtensions: ['.ts'],
|
|
414
|
-
children: [
|
|
415
|
-
{
|
|
416
|
-
name: 'components',
|
|
417
|
-
overrideExtensions: false,
|
|
418
|
-
allowedExtensions: ['.tsx'],
|
|
419
|
-
children: [{ name: '*' }],
|
|
420
|
-
},
|
|
421
|
-
{
|
|
422
|
-
name: 'stores',
|
|
423
|
-
allowedExtensions: ['.store.ts'],
|
|
424
|
-
},
|
|
425
|
-
],
|
|
426
|
-
},
|
|
427
|
-
{ name: 'legacy', ignore: true },
|
|
428
|
-
],
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
const cases: [/* path */ string, /* failures */ string[]][] = [
|
|
432
|
-
['index.tsx', []],
|
|
433
|
-
['/index.tsx', []],
|
|
434
|
-
['index.ts', ['allowedFilesFailure']],
|
|
435
|
-
['.index.ts', ['allowedFilesFailure']],
|
|
436
|
-
['awesome.tsx', ['allowedFilesFailure']],
|
|
437
|
-
[
|
|
438
|
-
'awesome-file',
|
|
439
|
-
['allowedFilesFailure', 'allowedExtensionsFailure', 'fileNamingConventionFailure'],
|
|
440
|
-
],
|
|
441
|
-
|
|
442
|
-
['awesome/index.ts', []],
|
|
443
|
-
['awesome/index.tsx', ['allowedExtensionsFailure']],
|
|
444
|
-
['awesomeModule/index.ts', []],
|
|
445
|
-
['awesome-module/index.ts', ['folderNamingConventionFailure']],
|
|
446
|
-
|
|
447
|
-
['awesome/components/awesome.tsx', []],
|
|
448
|
-
['awesome/components/awesome.ts', []],
|
|
449
|
-
['awesome/components/awesome/awesome.ts', []],
|
|
450
|
-
['awesome/components/awesome/awesome.tsx', []],
|
|
451
|
-
['awesome/components/awesome/awesome/awesome.tsx', ['allowedFolderNameFailure']],
|
|
452
|
-
|
|
453
|
-
['awesome/components/awesome-component/awesome.ts', []],
|
|
454
|
-
['awesome/components/awesomeComponent/awesome.ts', ['folderNamingConventionFailure']],
|
|
455
|
-
['awesome/components/awesomeComponent.tsx', ['fileNamingConventionFailure']],
|
|
456
|
-
|
|
457
|
-
['legacy/legacyFile.js', []],
|
|
458
|
-
['legacy/path-to/legacy-file.js', []],
|
|
459
|
-
|
|
460
|
-
['test.module/index.ts', ['folderNamingConventionFailure']],
|
|
461
|
-
['awesome/components/awesome.component/index.ts', ['folderNamingConventionFailure']],
|
|
462
|
-
|
|
463
|
-
['awesome/stores/awesome.store.ts', []],
|
|
464
|
-
['awesome/stores/awesome/awesome.store.ts', ['allowedFolderNameFailure']],
|
|
465
|
-
['awesome/stores/awesome.ts', ['allowedExtensionsFailure']],
|
|
466
|
-
['awesome/stores/awesome.tsx', ['allowedExtensionsFailure']],
|
|
467
|
-
|
|
468
|
-
['awesome/utils/some-util.ts', ['allowedFolderNameFailure']],
|
|
469
|
-
|
|
470
|
-
['\\index.tsx', []],
|
|
471
|
-
['awesome\\components\\awesome.tsx', []],
|
|
472
|
-
['\\awesome\\components\\awesome.tsx', []],
|
|
473
|
-
|
|
474
|
-
['', ['allowedFilesFailure', 'allowedExtensionsFailure']],
|
|
475
|
-
['/', ['allowedFilesFailure', 'allowedExtensionsFailure']],
|
|
476
|
-
['\\', ['allowedFilesFailure', 'allowedExtensionsFailure']],
|
|
477
|
-
['\\awesome/index.ts', []],
|
|
478
|
-
['//awesome///index.ts', []],
|
|
479
|
-
];
|
|
480
|
-
|
|
481
|
-
const check = checkPath(config);
|
|
482
|
-
|
|
483
|
-
test.each(cases)('%p -> %p', (path, expected) => expectFailures(check(path), expected));
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
describe('config#2 (recursive)', () => {
|
|
487
|
-
const recursiveConfigMock = jest.fn((level: number): RootFolder => () => ({
|
|
488
|
-
name: `level${level}`,
|
|
489
|
-
namingConvention: NamingConvention.DashDelimitedLowercase,
|
|
490
|
-
|
|
491
|
-
allowedFiles: ['index.tsx'],
|
|
492
|
-
allowedExtensions: ['.*'],
|
|
493
|
-
children: recursiveConfigMock(level + 1),
|
|
494
|
-
}));
|
|
495
|
-
|
|
496
|
-
const cases: [/* path */ string, /* failures */ string[]][] = [
|
|
497
|
-
['index.tsx', []],
|
|
498
|
-
['level1/index.tsx', []],
|
|
499
|
-
['level1/level2/index.tsx', []],
|
|
500
|
-
['level1/level2/level3/index.tsx', []],
|
|
501
|
-
['level1/level2/level3/level4/index.tsx', []],
|
|
502
|
-
['level1/level2/level3/level4/level5/index.tsx', []],
|
|
503
|
-
['level1/level2/level3/level4/awesome/index.tsx', ['allowedFolderNameFailure']],
|
|
504
|
-
];
|
|
505
|
-
|
|
506
|
-
const check = checkPath(recursiveConfigMock(0));
|
|
507
|
-
|
|
508
|
-
test.each(cases)('%p -> %p', (path, expected) => expectFailures(check(path), expected));
|
|
509
|
-
|
|
510
|
-
it('should not execute the recursive config more than once per level plus one', () => {
|
|
511
|
-
expect(recursiveConfigMock).toHaveBeenCalledTimes(7);
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
function expectFailures(actual: Failure[], expected: string[]) {
|
|
517
|
-
expect([...actual.map(f => f.type)].sort()).toEqual([...expected].sort());
|
|
518
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { alwaysLazy, isLazy, memoizeConst } from '../lazy';
|
|
2
|
-
|
|
3
|
-
describe('isLazy', () => {
|
|
4
|
-
test('should return false from a value', () => {
|
|
5
|
-
expect(isLazy(42)).toBeFalsy();
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('should return true from a lazy', () => {
|
|
9
|
-
expect(isLazy(() => 42)).toBeTruthy();
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('alwaysLazy', () => {
|
|
14
|
-
it('should return a lazy from a value', () => {
|
|
15
|
-
const lazyConst42 = alwaysLazy(42);
|
|
16
|
-
|
|
17
|
-
expect(typeof lazyConst42).toBe('function');
|
|
18
|
-
expect(lazyConst42()).toBe(42);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should return a lazy from a lazy', () => {
|
|
22
|
-
const lazyConst42 = alwaysLazy(() => 42);
|
|
23
|
-
|
|
24
|
-
expect(typeof lazyConst42).toBe('function');
|
|
25
|
-
expect(lazyConst42()).toBe(42);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('memoizeConst', () => {
|
|
30
|
-
const const42 = () => 42;
|
|
31
|
-
let const42Mock: typeof const42;
|
|
32
|
-
let memoizedConst42: typeof const42;
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
const42Mock = jest.fn(const42);
|
|
36
|
-
memoizedConst42 = memoizeConst(const42Mock);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should return the result of a function', () => {
|
|
40
|
-
expect(memoizedConst42()).toBe(42);
|
|
41
|
-
expect(memoizedConst42()).toBe(42);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should not execute the memoized function more than once', () => {
|
|
45
|
-
memoizedConst42();
|
|
46
|
-
memoizedConst42();
|
|
47
|
-
|
|
48
|
-
expect(const42Mock).toHaveBeenCalledTimes(1);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { NamingConvention } from '../namingConvention';
|
|
2
|
-
|
|
3
|
-
describe(NamingConvention.DashDelimitedLowercase, () => {
|
|
4
|
-
function check(name: string) {
|
|
5
|
-
return NamingConvention.check(NamingConvention.DashDelimitedLowercase, name);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// [fileName: string, isValid: boolean][]
|
|
9
|
-
test.each([
|
|
10
|
-
['', true],
|
|
11
|
-
|
|
12
|
-
['kebab', true],
|
|
13
|
-
['Kebab', false],
|
|
14
|
-
|
|
15
|
-
['kebab-case', true],
|
|
16
|
-
['Kebab-case', false],
|
|
17
|
-
['kebab-cAse', false],
|
|
18
|
-
|
|
19
|
-
['kebab0', true],
|
|
20
|
-
['kebab-78case', true],
|
|
21
|
-
['0kebab', true],
|
|
22
|
-
['0kebab-case0', true],
|
|
23
|
-
|
|
24
|
-
['kebab_', true],
|
|
25
|
-
['kebab-__case__', true],
|
|
26
|
-
['_kebab', true],
|
|
27
|
-
['_kebab-case_', true],
|
|
28
|
-
|
|
29
|
-
['k-e-b-a-b-c-a-s-e', true],
|
|
30
|
-
['kebab-c-a-s-e-', false],
|
|
31
|
-
['kebab-c-a-s-e--', false],
|
|
32
|
-
['-kebab-c-a-s-e', false],
|
|
33
|
-
['--kebab-c-a-s-e', false],
|
|
34
|
-
|
|
35
|
-
['kebab.case', false],
|
|
36
|
-
])('%p -> %p', (name, exp) => expect(check(name)).toBe(exp));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe(NamingConvention.CamelCase, () => {
|
|
40
|
-
function check(name: string) {
|
|
41
|
-
return NamingConvention.check(NamingConvention.CamelCase, name);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// [fileName: string, isValid: boolean][]
|
|
45
|
-
test.each([
|
|
46
|
-
['', true],
|
|
47
|
-
|
|
48
|
-
['camel', true],
|
|
49
|
-
['Pascal', false],
|
|
50
|
-
|
|
51
|
-
['camelCase', true],
|
|
52
|
-
['PascalCase', false],
|
|
53
|
-
['kebab-case', false],
|
|
54
|
-
['camel0', true],
|
|
55
|
-
['camel0Case9', true],
|
|
56
|
-
['0camel', false],
|
|
57
|
-
|
|
58
|
-
['camel_', true],
|
|
59
|
-
['camel_Case_', true],
|
|
60
|
-
['_camel', true],
|
|
61
|
-
|
|
62
|
-
['camel.case', false],
|
|
63
|
-
])('%p -> %p', (name, exp) => expect(check(name)).toBe(exp));
|
|
64
|
-
});
|