Skip to content

Improve folder structure by only allowing safe-listed file paths

License

Notifications You must be signed in to change notification settings

mattferrin/folder-structure-lint

Repository files navigation

folder-structure-lint

About

Many aspects of this project are shamelessly borrowed from FoldersLint, the best equivalent I was able to find before writing a Rust version named folders-lint. This is a TypeScript version because TypeScript is easier to package and collaborate with.

Purpose

This module aims to improve folder structure by only allowing safe-listed file paths. As a byproduct, the configuration file can be thought of as reliable and readable documentation for the folder structure.

Getting Started

Install

npm i -D @clowd/fsl

Create your config .folder-structure-lint.json file:

I recommend grouping by both feature (/*/ below) and file type (hooks, components, etc.):

{
  "root": "src",
  "rules": [
    "src/App.*",
    "src/index.*",

    "src/*/index.*",
    "src/*/hooks/use*.*",
    "src/*/components/*.*",
    "src/*/others/*.*",
  ]
}

Add this to your package.json:

{
  "scripts": {
    "fsl": "fsl"
  }
}

Run the linter:

npm run fsl

Optionally

Use husky and lint-staged in combination, 2 great NPM packages. Husky lets you check rules on commit. Lint Staged only checks changed files.

Usage

Glob

Example .folder-structure-lint.json glob rule:

{
  "root": "src",
  "rules": ["src/legacy/**"]
}

Regex

Regex is not supported in the TypeScript version. See the Rust version if interested or submit a pull-request.

About

Improve folder structure by only allowing safe-listed file paths

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published