@sshkeda/check 1.0.0 → 1.0.1

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.
@@ -37,7 +37,7 @@ These names need no reason:
37
37
  - `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
38
38
  - `pollsWithADeadline`: Allows `Effect.repeat` with `Schedule.spaced`, under a deadline.
39
39
  - `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
40
- - `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `vendor`.
40
+ - `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `.github`. Check doesn't apply its directory-shape rules inside it, but files there still need their own `hasAnUnlistedFileType` grant.
41
41
  - `patchesADependency`: Allows a patch file from `bun patch`.
42
42
 
43
43
  These names need a reason, written as `{ name: "reason" }`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -408,6 +408,19 @@ const PACKAGE_ROOT_DIRECTORIES: ReadonlySet<string> = new Set([
408
408
  DOCS_DIRECTORY,
409
409
  ]);
410
410
 
411
+ const isRootDirectoryOutsideTheLayout = (directory: string) =>
412
+ !directory.includes("/") && !PACKAGE_ROOT_DIRECTORIES.has(directory);
413
+
414
+ const directoriesExemptFromShapeRules = (
415
+ directories: Iterable<string>,
416
+ grants: Effect.Success<ReturnType<typeof loadedLintConfigIn>>,
417
+ ) =>
418
+ [...directories].filter(
419
+ (directory) =>
420
+ isRootDirectoryOutsideTheLayout(directory) &&
421
+ grants.some((grant) => grant.path === directory && grant.allow.includes(DIRECTORY)),
422
+ );
423
+
411
424
  export const directoriesHoldingOnlyADirectory = (
412
425
  paths: readonly string[],
413
426
  nestedPackageDirectories: readonly string[],
@@ -589,8 +602,8 @@ export const permissionGrantViolations = (
589
602
  ]),
590
603
  ...outermostPackageDirectories,
591
604
  ]);
592
- const directoriesNeedingGrants = [...ownedDirectories].filter(
593
- (directory) => !directory.includes("/") && !PACKAGE_ROOT_DIRECTORIES.has(directory),
605
+ const directoriesNeedingGrants = [...ownedDirectories].filter((directory) =>
606
+ isRootDirectoryOutsideTheLayout(directory),
594
607
  );
595
608
  const violations: (
596
609
  | CannotImportTargetMissing
@@ -770,6 +783,12 @@ export const findFileLayoutViolations = (directory: string) =>
770
783
  const ownedDirectories = new Set(
771
784
  distinctDirectoriesOf([...ownedPaths, ...nestedPackageDirectories]),
772
785
  );
786
+ const shapeExemptDirectories = Option.match(grants, {
787
+ onNone: () => [],
788
+ onSome: (found) => directoriesExemptFromShapeRules(ownedDirectories, found),
789
+ });
790
+ const isShapeChecked = ({ location }: { readonly location: string }) =>
791
+ !shapeExemptDirectories.some((exempt) => isWithin(location, exempt));
773
792
  const grantViolations = Option.match(grants, {
774
793
  onNone: () => [],
775
794
  onSome: (found) => [
@@ -812,11 +831,13 @@ export const findFileLayoutViolations = (directory: string) =>
812
831
  const violations = [
813
832
  ...fileViolations.flat(),
814
833
  ...directoryNameViolations(ownedPaths),
815
- ...directoryShapeViolations(ownedPaths),
834
+ ...directoryShapeViolations(ownedPaths).filter((violation) => isShapeChecked(violation)),
816
835
  ...directoriesHoldingOnlyADirectory(
817
836
  [...new Set([...paths, ...generated])],
818
837
  nestedPackageDirectories,
819
- ).filter(({ location }) => ownedDirectories.has(location)),
838
+ ).filter(
839
+ (violation) => ownedDirectories.has(violation.location) && isShapeChecked(violation),
840
+ ),
820
841
  ...packageRootViolations(ownedPaths),
821
842
  ...duplicateFileNameViolations(ownedPaths),
822
843
  ...grantViolations,