# The Rules

# Overview

ls-lint provides multiple rules out of the box:

Rule Alias Description
lowercase - Every letter must be lowercase
Ignore non letters
camelcase camelCase String must be camelCase
Only letters and digits allowed
pascalcase PascalCase String must be Pascalcase
Only letters and digits allowed
snakecase snake_case String must be snake*case
Only lowercase letters, digits and * allowed
screamingsnakecase SCREAMING_SNAKE_CASE String must be snake*case
Only uppercase letters, digits and * allowed
kebabcase kebab-case String must be kebab-case
Only lowercase letters, digits and - allowed
regex - Matches regex pattern: ^{pattern}$
exists - Allow or disallow the existence of N or N-M files. Also works for directories.

# Regex

The regex rule provides full flexibility for your configuration and matches your file and directory names by the ^{pattern}$ pattern

# Example

.ls-lint.yml
ls:
  .js: regex:[a-z0-9]+ # the final regex pattern will be ^[a-z0-9]+$

# Negation

You can negate the regex rule by adding a ! prefix

.ls-lint.yml
ls:
  .js: regex:![0-9]+ # the final regex pattern will be ^[0-9]+$

# Using multiple regex rules

Multiple regex rules are supported by the | operator

.ls-lint.yml
ls:
  .js: regex:Schema(\_test)? | regex:Resolver(\_test)?

# Using multiple regex rules with regex alternation (opens new window)

With regex alternation, you can simplify the above example

ls:
  .js: regex:(Schema|Resolver)(\_test)?

# Directory substitutions

The regex rule exposes the directory tree as substitution variables that can be referenced in the regex pattern. For instance, you can use ${0} to substitute the parent directory, ${1} for the parent parent, and so on.

Directory tree
components
└── button
    ├── button.ts
    └── tests
        └── button.test.ts
.ls-lint.yml
ls:
  components/*: # e.g.: components/button
    .ts: regex:${0} # e.g.: components/button/button.ts
    .*.scss: regex:${0} # e.g.: components/button/button.module.scss

    tests:
      .test.ts: regex:${1} # e.g.: components/button/tests/button.test.ts

# Exists

Allow or disallow N or N-M files for a given extension. The exists rule only applies to the directory itself, not to subdirectories.

Imagine you want to restrict all component directories to only having one .ts and one .test.ts file:

ls:
  components/*:
    .dir: kebab-case
    .*: exists:0
    .ts: kebab-case | exists:1
    .test.ts: kebab-case | exists:1

exists also works for directories:

ls:
  components/{auth,account}:
    dir: exists:1
    .*: ...

    "*":
      .dir: exists:0 # no subdirectories allowed

and ranges:

ls:
  .js: exists:1-10