Skip to content

mattferrin/folders-lint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

folders-lint

About

Many aspects of this project are shamelessly borrowed form FoldersLint, the best equivalent I was able to find before writing this module.

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 readable documentation for the folder structure.

Built With

This is a Node.js module written in Rust and created using Neon. The underlying Glob implementation is the glob crate. The underlying Regex implementation is the regex crate.

Getting Started

Warning: Cloning this repo and building with Neon might work better for you, but please help fix if normal installation fails.

(The first step is Windows only.)

npm install --global windows-build-tools

npm install -g node-gyp

npm i -D mattferrin/folders-lint

(If installation has a cargo error hiccup try Installing Rust.)

Create your custom .folderslintrc.json file:

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

    "common/hooks/use*.*",
    "common/components/Render*.*",
    "common/handlers/handle*.*",

    "features/*/index.*",
    "features/*/hooks/use*.*",
    "features/*/components/Render*.*",
    "features/*/handlers/handle*.*",

    "__tests__/*/*.test.tsx"
  ]
}

Add this to your package.json:

{
  "scripts": {
    "fslint": "folders-lint"
  }
}

Run the linter:

npm run fslint

Optionally

npm install husky --save-dev

And add this to your package.json:

{
  "scripts": {
    "fslint": "folders-lint"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run fslint"
    }
  }
}

Usage

Glob

The glob rules are matched with:

case_sensitive: true,
require_literal_leading_dot: false,
require_literal_separator: true`,

Example .folderslintrc.json glob rule:

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

Regex

Warning: Most of us mere mortals find regex unreadable. (But it's so powerful.)

Example .folderslintrc.json regex rule:

{
  "root": "src",
  "rules": ["/index\\.tsx/"]
}

Or Both

Example .folderslintrc.json rules:

{
  "root": "src",
  "rules": ["legacy/**", "/index\\.tsx/"]
}

Note: Regex escape character \ needs double escaped in JSON: \\

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published