loeffel-io / ls-lint

An extremely fast directory and filename linter - Bring some structure to your project filesystem
https://ls-lint.org
MIT License
1.73k stars 32 forks source link

Feature request: ignore abbreviations #167

Closed soc221b closed 11 months ago

soc221b commented 11 months ago

I'm wondering if this is useful to anyone else 🤔:

ls:
  packages/*/{src,__tests__}:
    .js: kebab-case
    .ts: camelCase | PascalCase
    .d.ts: camelCase
    .spec.ts: camelCase | PascalCase
    .mock.ts: camelCase

ignore:
  - node_modules
+
+ abbr:
+  - HTTP
+  - SMS

Thank you~

loeffel-io commented 11 months ago

Hey @iendeavor, could you please provide more context

thank you

soc221b commented 11 months ago

Hi, @loeffel-io Thanks for your quick reply.

For example, we might have some files containing the abbreviation "SMS", but it violates the PascalCase rule:

ls:
  .ts: PascalCase
path/
│
└─ to/
  │
  ├─ EmailService.ts # valid
  │
  └─ SMSService.ts # invalid
loeffel-io commented 11 months ago

Hey @iendeavor

for this you can use the regex rule and allow only specific values or the negative of them with something like

ls:
    to:
         .ts: regex:(Email|Foo|Bla)Service # allow EmailService, FooService, BlaService

the negative could be this, but this isn't supported by re2 and go

ls:
    to:
         .ts: regex:(?!HTTP|SMS).*Service # do not allow HTTPService, SMSService

for this a not_regex rule could make sense

soc221b commented 11 months ago

Yes, this makes sense for the example mentioned earlier, but we might have any name anywhere in the filename, and we also want to validate it based on specific rules, like:

Example 1: https://github.com/facebook/react-native/tree/6e42c98aa3423cfbc389e4fe877b5c6b559c8a81/packages/community-cli-plugin/src/commands/bundle

ls:
  .js: camelCase
../
│
└─ bundle/
  │
  ├─ assetCatalogIOS.js
  │
  ├─ getAssetDestPathIOS.js
  │
  └─ __tests__/
    │
    └─ getAssetDestPathIOS-test.js

Example 2: https://github.com/apple/swift/tree/main/lib/AST

ls:
  .cpp: PascalCase
../
│
├─ AST/
│ │
│ ├─ ASTScope.cpp
│ │
│ ├─ ASTScopePrinting.cpp
│ │
│ └─ ASTScopeSourceRange.cpp
│
└─ RemoteAST/
  │
  └─ RemoteAST.cpp
loeffel-io commented 11 months ago

what about

ls:
    to:
         .ts: regex:(Email|Foo|Bla)Service | camelCase # allow EmailService, FooService, BlaService and all camelCase

filenames like getAssetDestPathIOS-test.js are an anti pattern imo

loeffel-io commented 11 months ago

Closing this for now - please let me know if you have any further questions