ls-lint
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesels-lint v2.3
ls-lint v2.3
Version Notice: This skill documents ls-lint v2.3 specifically. Before proceeding, verify the installed version matches:bashls-lint --version # or npx @ls-lint/ls-lint --versionIf a different version is installed, stop and consult the official documentation for that version at https://ls-lint.org or the GitHub repository at https://github.com/loeffel-io/ls-lint. Configuration syntax and available rules may differ between versions.
An extremely fast directory and filename linter that enforces naming conventions across project filesystems.
Official Resources:
- GitHub: https://github.com/loeffel-io/ls-lint
- Documentation: https://ls-lint.org/2.3/getting-started/introduction.html
Key features:
- Processes thousands of files in milliseconds
- Minimal configuration via
.ls-lint.yml - Cross-platform: Windows, macOS, Linux
- Full Unicode support
- Minimal dependencies (go-yaml, doublestar)
版本说明: 本Skill专门针对ls-lint v2.3版本编写。开始操作前,请确认已安装的版本是否匹配:bashls-lint --version # 或 npx @ls-lint/ls-lint --version如果安装的是其他版本,请停止操作并查阅对应版本的官方文档,地址为https://ls-lint.org或GitHub仓库https://github.com/loeffel-io/ls-lint。不同版本的配置语法和可用规则可能存在差异。
这是一款极速的目录与文件名检查工具,可在项目文件系统中强制统一命名规范。
官方资源:
- GitHub:https://github.com/loeffel-io/ls-lint
- 官方文档:https://ls-lint.org/2.3/getting-started/introduction.html
核心特性:
- 毫秒级处理数千个文件
- 通过实现极简配置
.ls-lint.yml - 跨平台支持:Windows、macOS、Linux
- 完整Unicode支持
- 依赖极少(仅go-yaml、doublestar)
Installation
安装
bash
undefinedbash
undefinedNPM (recommended)
NPM(推荐方式)
npm install -D @ls-lint/ls-lint
npm install -D @ls-lint/ls-lint
NPX (no install)
NPX(无需安装)
npx @ls-lint/ls-lint
npx @ls-lint/ls-lint
Homebrew (macOS/Linux)
Homebrew(macOS/Linux)
brew install ls-lint
brew install ls-lint
Direct download (Linux amd64)
直接下载(Linux amd64)
curl -sL -o ls-lint https://github.com/loeffel-io/ls-lint/releases/download/v2.3.1/ls-lint-linux-amd64
chmod +x ls-lint
undefinedcurl -sL -o ls-lint https://github.com/loeffel-io/ls-lint/releases/download/v2.3.1/ls-lint-linux-amd64
chmod +x ls-lint
undefinedConfiguration Basics
配置基础
Create in the project root with two main sections:
.ls-lint.ymlyaml
ls:
# Rules for directories and file extensions
.js: kebab-case
.ts: kebab-case
ignore:
# Paths to exclude from linting
- .git
- node_modules在项目根目录创建文件,包含两个核心部分:
.ls-lint.ymlyaml
ls:
# 针对目录和文件扩展名的规则
.js: kebab-case
.ts: kebab-case
ignore:
# 排除检查的路径
- .git
- node_modulesRunning ls-lint
运行ls-lint
bash
undefinedbash
undefinedRun with default config (.ls-lint.yml)
使用默认配置文件(.ls-lint.yml)运行
npx @ls-lint/ls-lint
npx @ls-lint/ls-lint
Custom config path
指定自定义配置文件路径
ls-lint --config path/to/.ls-lint.yml
ls-lint --config path/to/.ls-lint.yml
Custom working directory
指定自定义工作目录
ls-lint --workdir /path/to/project
undefinedls-lint --workdir /path/to/project
undefinedBuilt-in Rules
内置规则
Six naming convention rules are available:
| Rule | Description | Example |
|---|---|---|
| All lowercase letters, ignores non-letters | |
| camelCase, letters and digits only | |
| PascalCase, letters and digits only | |
| Lowercase with underscores | |
| Uppercase with underscores | |
| Lowercase with hyphens | |
提供六种命名规范规则:
| 规则 | 描述 | 示例 |
|---|---|---|
| 全小写字母,忽略非字母字符 | |
| 小驼峰命名,仅允许字母和数字 | |
| 大驼峰命名,仅允许字母和数字 | |
| 小写字母加下划线分隔 | |
| 大写字母加下划线分隔 | |
| 小写字母加连字符分隔 | |
Combining Rules
组合规则
Use the pipe operator to allow multiple conventions:
|yaml
ls:
.ts: camelCase | PascalCase # Either is valid
.js: kebab-case | snake_case使用管道符允许同时应用多种命名规范:
|yaml
ls:
.ts: camelCase | PascalCase # 两种规范均有效
.js: kebab-case | snake_caseExtensions & Sub-extensions
扩展名与子扩展名
Standard Extensions
标准扩展名
Apply rules to specific file types:
yaml
ls:
.js: kebab-case
.ts: kebab-case
.json: kebab-case
.md: SCREAMING_SNAKE_CASE # README.md, CHANGELOG.md为特定文件类型应用规则:
yaml
ls:
.js: kebab-case
.ts: kebab-case
.json: kebab-case
.md: SCREAMING_SNAKE_CASE # README.md、CHANGELOG.mdSub-extensions
子扩展名
Handle compound extensions like , , :
.d.ts.test.js.module.cssyaml
ls:
.d.ts: kebab-case # Type definition files
.test.ts: kebab-case # Test files
.module.css: kebab-case # CSS modules
.config.js: kebab-case # Config files处理复合扩展名,如、、:
.d.ts.test.js.module.cssyaml
ls:
.d.ts: kebab-case # TypeScript类型定义文件
.test.ts: kebab-case # 测试文件
.module.css: kebab-case # CSS模块
.config.js: kebab-case # 配置文件Wildcard Extension
通配符扩展名
Match all extensions with :
.*yaml
ls:
.*: kebab-case # All files must be kebab-case使用匹配所有扩展名:
.*yaml
ls:
.*: kebab-case # 所有文件必须使用kebab-case命名Directory Naming
目录命名规则
Use to enforce directory name conventions:
.diryaml
ls:
.dir: kebab-case # All directories must be kebab-case使用强制目录命名规范:
.diryaml
ls:
.dir: kebab-case # 所有目录必须使用kebab-case命名Path Patterns
路径模式
Global Rules
全局规则
Rules at the top level apply project-wide:
yaml
ls:
.js: kebab-case # Applies everywhere
.ts: kebab-case
ignore:
- node_modules顶层规则将应用于整个项目:
yaml
ls:
.js: kebab-case # 全局生效
.ts: kebab-case
ignore:
- node_modulesDirectory-Specific Rules
目录特定规则
Override global rules for specific directories:
yaml
ls:
.js: kebab-case # Global default
components: # Override for components/
.js: PascalCase
src/models: # Override for src/models/
.js: PascalCaseDirectory rules apply to the specified directory and all its subdirectories.
为特定目录覆盖全局规则:
yaml
ls:
.js: kebab-case # 全局默认规则
components: # 覆盖components/目录下的规则
.js: PascalCase
src/models: # 覆盖src/models/目录下的规则
.js: PascalCase目录规则将应用于指定目录及其所有子目录。
Glob Patterns
通配符模式
Use wildcards for flexible path matching:
yaml
ls:
# Single wildcard: matches one directory level
packages/*/src:
.ts: kebab-case
# Double wildcard: matches any depth
packages/**/components:
.tsx: PascalCase使用通配符实现灵活的路径匹配:
yaml
ls:
# 单通配符:匹配一级目录
packages/*/src:
.ts: kebab-case
# 双通配符:匹配任意层级目录
packages/**/components:
.tsx: PascalCaseAlternative Patterns
多选项模式
Use curly braces for multiple alternatives:
yaml
ls:
packages/*/{src,tests}:
.ts: kebab-case
src/{components,pages}:
.tsx: PascalCase使用大括号指定多个可选路径:
yaml
ls:
packages/*/{src,tests}:
.ts: kebab-case
src/{components,pages}:
.tsx: PascalCaseAdvanced Rules
高级规则
Regex Patterns
正则表达式模式
For custom naming patterns, use regex with format:
regex:^pattern$yaml
ls:
# Files must start with uppercase letter
.ts: regex:^[A-Z].*$
# Allow files starting with underscore or letter
.js: regex:^[_a-z][a-zA-Z0-9]*$Combine regex with built-in rules:
yaml
ls:
.ts: PascalCase | regex:^index$ # PascalCase OR "index"如需自定义命名模式,使用格式:
regex:^pattern$yaml
ls:
# 文件必须以大写字母开头
.ts: regex:^[A-Z].*$
# 允许以下划线或小写字母开头的文件
.js: regex:^[_a-z][a-zA-Z0-9]*$可将正则规则与内置规则组合使用:
yaml
ls:
.ts: PascalCase | regex:^index$ # 允许PascalCase命名或文件名是"index"Directory Substitution
目录替换
Reference parent directory names in patterns:
yaml
ls:
# File must match parent directory name
components/*/:
.tsx: regex:^${0}$ # ${0} = parent directory name在模式中引用父目录名称:
yaml
ls:
# 文件名必须与父目录名称一致
components/*/:
.tsx: regex:^${0}$ # ${0} 代表父目录名称Exists Rule
存在性规则
Enforce file quantity constraints:
yaml
ls:
# Exactly one index file required
src/:
index.ts: exists:1
# Between 1-5 test files allowed
tests/:
.test.ts: exists:1-5
# No image files allowed
src/:
.png: exists:0
.jpg: exists:0Combine with naming rules:
yaml
ls:
.ts: kebab-case | exists:1 # Must be kebab-case AND exactly one强制约束文件数量:
yaml
ls:
# 必须存在且仅存在一个index文件
src/:
index.ts: exists:1
# 允许存在1-5个测试文件
tests/:
.test.ts: exists:1-5
# 不允许存在图片文件
src/:
.png: exists:0
.jpg: exists:0可与命名规则组合使用:
yaml
ls:
.ts: kebab-case | exists:1 # 必须使用kebab-case命名且仅存在一个Common Configurations
常见配置示例
JavaScript/TypeScript Project
JavaScript/TypeScript项目
yaml
ls:
.dir: kebab-case
.js: kebab-case
.ts: kebab-case
.tsx: PascalCase # React components
.d.ts: kebab-case
.json: kebab-case
.md: SCREAMING_SNAKE_CASE
src/components:
.tsx: PascalCase
ignore:
- .git
- node_modules
- dist
- coverageyaml
ls:
.dir: kebab-case
.js: kebab-case
.ts: kebab-case
.tsx: PascalCase # React组件
.d.ts: kebab-case
.json: kebab-case
.md: SCREAMING_SNAKE_CASE
src/components:
.tsx: PascalCase
ignore:
- .git
- node_modules
- dist
- coverageMonorepo Pattern
单仓库多项目(Monorepo)模式
yaml
ls:
.dir: kebab-case
.*: kebab-case
packages/*/src:
.ts: kebab-case
.tsx: PascalCase
packages/*/{src,tests}:
.dir: kebab-case
ignore:
- .git
- node_modules
- "**/dist"
- "**/coverage"
- "**/build"yaml
ls:
.dir: kebab-case
.*: kebab-case
packages/*/src:
.ts: kebab-case
.tsx: PascalCase
packages/*/{src,tests}:
.dir: kebab-case
ignore:
- .git
- node_modules
- "**/dist"
- "**/coverage"
- "**/build"GitHub Actions Integration
GitHub Actions集成
Basic workflow configuration:
yaml
undefined基础工作流配置:
yaml
undefined.github/workflows/lint.yml
.github/workflows/lint.yml
name: Lint
on: [push, pull_request]
jobs:
ls-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ls-lint/action@v2
undefinedname: Lint
on: [push, pull_request]
jobs:
ls-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ls-lint/action@v2
undefinedAction Configuration Options
Action配置选项
yaml
- uses: ls-lint/action@v2
with:
config: .ls-lint.yml # Config file path
workdir: . # Working directory
error-output-format: text # text or json
warn: false # Output to stdout, exit 0
debug: false # Enable debug outputyaml
- uses: ls-lint/action@v2
with:
config: .ls-lint.yml # 配置文件路径
workdir: . # 工作目录
error-output-format: text # 输出格式:text或json
warn: false # 输出到标准输出,退出码为0
debug: false # 启用调试输出Troubleshooting
故障排除
Common Issues
常见问题
No files matched: Verify path patterns match actual directory structure.
Rule not applying: Check for more specific rules that might override.
Ignore not working: Ensure ignore patterns use correct glob syntax.
无文件匹配:请检查路径模式是否与实际目录结构匹配。
规则未生效:检查是否存在更具体的规则覆盖了当前规则。
忽略规则不生效:确保忽略模式使用了正确的通配符语法。
Debug Mode
调试模式
Run with verbose output to diagnose issues:
bash
ls-lint --debug运行时启用详细输出来诊断问题:
bash
ls-lint --debugExternal Resources
外部资源
For features not covered in this skill, consult:
- GitHub Repository: https://github.com/loeffel-io/ls-lint
- Official Documentation: https://ls-lint.org/2.3/getting-started/introduction.html
- GitHub Action: https://github.com/ls-lint/action
The official documentation covers additional features like:
- Multiple configuration files
- Bazel integration
- Docker usage
- Complete regex syntax
如需了解本Skill未涵盖的功能,请查阅:
- GitHub仓库:https://github.com/loeffel-io/ls-lint
- 官方文档:https://ls-lint.org/2.3/getting-started/introduction.html
- GitHub Action:https://github.com/ls-lint/action
官方文档还涵盖了以下额外功能:
- 多配置文件
- Bazel集成
- Docker使用
- 完整正则表达式语法