0.1.1 • Published 9 months ago

eslint-plugin-repo-structure v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Repo Structure - Eslint Plugin

A plugin that allows you to define rules for the folder and file structure of your repository, as well as naming constraints that must be followed.

Installation

$ yarn add -D eslint-plugin-repo-structure

or

$ npm i --dev eslint-plugin-repo-structure

Getting started

  1. Define the log level that you want and the repo structure config path, Example:
{
  "plugins": ["repo-structure"],
  "rules": {
    "repo-structure/file-structure": "warn", // warn | error
  }
  "settings": {
    "repo-structure/config-path": ".repo-structurerc"
  }
}
  1. Create a JSON file with the folder and file structure that should be followed. For each module, you can also define rules for naming patterns, case and extensions that are allowed.

    To exclude files from validation, you can pass them to ignorePatterns attribute.

Example:

{
  "ignorePatterns": ["path/to/ignore-module/**.js", "**/.*Models.js"],
  "root": {
    "children": [
      {
        "name": "src",
        "children": [
          {
            "name": "controllers",
            "children": [
              {
                "case": "PascalCase",
                "name": "/^.*Controller$/",
                "extension": ".ts"
              }
            ]
          },
          // you can also reference rules ids created inside rules object
          { "id": "services-folder" }
          // ...
        ]
      },
      {
        "name": "tests",
        "children": [
          {
            "type": "file",
            "name": "/^.*\\.test$/",
            "extension": ".ts"
          }
        ]
      }
    ]
  },
  "rules": {
    "services-folder": {
      "name": "services",
      "children": [
        {
          "case": "PascalCase",
          "name": "/^.*Service$/",
          "extension": ".ts"
        }
      ]
    }
  }
}

You can also define it as a yaml file, example:

ignorePatterns:
  - path/to/ignore-module/**.js
  - "**/.*Models.js"

root:
  children:
    - name: src
      children:
        - name: controllers
          children:
            - case: PascalCase
              name: "/^.*Controller$/"
              extension: ".ts"
        - id: services-folder

    - name: tests
      children:
        - type: file
          name: "/^.*\\.test$/"
          extension: ".ts"

rules:
  services-folder:
    name: services
    children:
      - case: PascalCase
        name: "/^.*Service$/"
        extension: ".ts"
  1. Rules

    Here is the list of attributes that can be created inside of a rule object:

ruletypeexampledescription
namestring"components" or "/*.Controllers$/"It's a fixed name or a regex pattern (must start and end with /)
casestring"PascalCase" or "camelCase" or "snake_case" or "kebab-case" or "dash-case"
typestring"folder" or "file"Indicates if the rule must apply only for files or folders (when empty will apply for both)
extensionstring or string[]".ts" or ".ts", ".js", ".tsx"Specify that a file must have one of the given extensions
childrenRule[] or IdRule[]This attribute is used to define folders and the rules that their children nodes must follow

When defining a list of rules for a folder children, an error or warning is raised if a given file or folder does not satisfy any of the listed rules.

Validating multiple file extensions.

Eslint uses JS parsers to interpret the written code, this means that its main purpose is not to run on other file extensions. However, if you want to validate the naming and casing for non js files, you can do this by using this hacky command:

$ npm eslint --parser ./node_modules/eslint-plugin-repo-structure/parser.js \
  --rule repo-structure/file-structure:warn \
  --ext .js,.ts,.tsx,.css,.svg,.yml,.png .

In this command, we override eslint parser so it can read files with other extensions, like .svg, .yml or even .png. We also have to specify it to run only the repo structure rule.

0.1.1

9 months ago

0.1.0

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago