flaviostutz / monolint

Linter for monorepos. Checks folder structure, module contents, file contents and naming conventions
MIT License
7 stars 4 forks source link

Create rule "module-folder-structure" #2

Closed flaviostutz closed 1 year ago

flaviostutz commented 2 years ago

Check if the modules have a set of folders. It can be "strict" or not (permit more than the specified folders on the module or not).

.monolinter.json:

{
  "rules": {
    "module-folder-structure": true
  }
}
{
  "rules": {
    "module-folder-structure": {
      "strict":true,
      "folders": ["src", "sls"]
    }
  }
}
sergioflores-j commented 1 year ago

As suggested in #12, I can get this one to start contributing!

Could you assign it to me?


Q: should this rule care about nested folders as well?

e.g.

{
  "rules": {
    "module-folder-structure": {
      "folders": ["src/utils", "src/libs"]
    }
  }
}
sergioflores-j commented 1 year ago

Perhaps a better naming strategy if we want to add more features to this rule in the future:

folders -> allowedFolders

Or even patterns, following serverless' framework package.patterns idea. (if we're gonna support nested folder checks)

flaviostutz commented 1 year ago

As suggested in #12, I can get this one to start contributing!

Could you assign it to me?

Q: should this rule care about nested folders as well?

e.g.

{
  "rules": {
    "module-folder-structure": {
      "folders": ["src/utils", "src/libs"]
    }
  }
}

yes!

flaviostutz commented 1 year ago

Perhaps a better naming strategy if we want to add more features to this rule in the future:

folders -> allowedFolders

Or even patterns, following serverless' framework package.patterns idea. (if we're gonna support nested folder checks)

I like the idea of using patterns as the spec, but I think the name "folder" makes it easier to understand that this rule is only about "folders", not files. If we have something like this, we can create another rule. Let's try to make the rules as small as possible, so we can combine them in different scenarios.

For the patterns, maybe we can follow the "gitignore" glob pattern style, something like we did on https://github.com/flaviostutz/monolint/blob/main/src/lint.ts#L106 while discovering modules and ignoring .monolintignore entries. The lib used is "fast-glob".

By my understanding, then we would have something like:

{
  "rules": {
    "module-folder-structure": {
      "strict": true,
      "folders": ["src/test", "src/**/utils", "src/libs/**/release"]
    }
  }
}

Which means, only folders that matches one of those patterns are allowed to be present (because of strict==true). If strict==false, at least one folder that follow each one of those patterns should be found.

What do you think?

sergioflores-j commented 1 year ago

closed by #36