# 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}$
not_regex - Does not match 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]+$

# 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)?

# 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