@sp-packages/lintrc
v2.0.0
Published
A lightweight CLI tool for running multiple linters efficiently.
Maintainers
Readme
LintRC
✨ Features
- 🔍 Detects file types and applies appropriate linters automatically
- 🛠 Supports multiple linters (ESLint, Prettier, PHPStan, PHPCS, Markdownlint, etc.)
- 🚀 Parallel execution for improved performance
- 📜 Customizable config file (
lintrc.json) - ✅ Runs only on Git-tracked files by default
- 🏗 Ideal for CI/CD pipelines and local development
📦 Installation
Global Installation (For system-wide CLI use)
npm install -g @sp-packages/lintrcThis allows you to use lintrc globally in your terminal.
Local Installation (For project-specific use)
npm install @sp-packages/lintrc --save-devThen, run it via:
npx lintrc🚀 CLI Usage
Basic Usage
lintrc [options]Options:
lintrc -h
Usage: LintRC [options] [files...]
LintRC - A CLI tool for running linters based on file extensions.
Arguments:
files List of files to lint. If omitted, uses Git-tracked files.
Options:
-V, --version output the version number
--skip-composer Skip processing Composer dependencies
--skip-npm Skip processing NPM dependencies
-c, --config <config> Path to the configuration file (default: lintrc.json)
-e, --ext <ext...> Optionally limit the linter to specific extensions
-s, --strict Strict Mode (return exit code 1 even for warnings)
-q, --quiet Disable output
-m, --minimal Essential output
-v, --verbose Enable verbose logging
-h, --help display help for commandExamples:
lintrc --ext js,ts,php
lintrc --config custom-lintrc.json --verbose📜 Programmatic Usage (Inside Node.js)
You can also use lintrc inside your JavaScript/TypeScript projects.
Import and Use in Your Project
import { lintrc } from '@sp-packages/lintrc';
lintrc({ verbose: true });⚙️ Configuration (lintrc.json)
By default, lintrc will look for a lintrc.json or .lintrc.json file in your project's root directory. You can customize it as follows:
The lintrc.json configuration file allows you to define the tools and file type mappings for lintrc. Below is an example configuration and explanation of its keys:
TOOLS
The TOOLS section defines the linters and their configurations. Each tool has the following properties:
title: The display name of the tool.type: The type of package manager used (npmorcomposer).prefix: Specifies how the tool is invoked:"npm": For npm subcommands (can be omitted iftypeis"npm", as it's the default)."npx": For npm custom binaries (installed innode_modules/.bin)."composer": For composer subcommands (can be omitted iftypeis"composer", as it's the default)."vendor": For composer custom binaries (installed invendor/bin).
command: The command to run the linter.args: An array of arguments to pass to the command.behavior: The behavior of the tool (errororwarn).priority: The priority of the tool execution (lower number means higher priority).
Example:
{
"TOOLS": {
"CSPELL": {
"title": "cSpell",
"type": "npm",
"prefix": "npx",
"command": "cspell",
"args": ["--no-progress", "--no-summary"],
"behavior": "warn",
"priority": 4
},
"ESLINT": {
"title": "ESLint",
"type": "npm",
"prefix": "npx",
"command": "eslint",
"args": ["--fix"],
"behavior": "error",
"priority": 2
},
"PHPCS": {
"title": "PHP Code Sniffer",
"type": "composer",
"prefix": "vendor",
"command": "phpcs",
"behavior": "error",
"priority": 3
},
"PRETTIER": {
"title": "Prettier",
"type": "npm",
"prefix": "npx",
"command": "prettier",
"args": ["--write"],
"behavior": "error",
"priority": 1
}
}
}MAPPING
The MAPPING section defines which tools to run based on file extensions. Each key is a file extension, and the value is an array of tool identifiers from the TOOLS section.
Example:
{
"MAPPING": {
"php": ["PHPCS"],
"js": ["ESLINT", "PRETTIER"],
"jsx": ["ESLINT", "PRETTIER"],
"ts": ["ESLINT", "PRETTIER"],
"*": ["CSPELL"]
}
}In this example:
- PHP files (
.php) will be checked withPHPCS. - JavaScript files (
.js) and TypeScript files (.ts) will be checked withESLINTandPRETTIER. - All files (
*) will be checked withCSPELL.
This configuration allows lintrc to automatically apply the appropriate linters based on the file types in your project.
🎯 Example Outputs
lintrc
------------------------------
cSpell
------------------------------
❌ [ERROR] package.json:112:32 - Unknown word (lintrc)
------------------------------
LintRC Results
------------------------------
✅ [SUCCESS] Prettier: Passed
✅ [SUCCESS] ESLint: Passed
✅ [SUCCESS] Markdown Lint: Passed
✅ [SUCCESS] Commit Lint: Passed
✅ [SUCCESS] DepCheck: Passed
❌ [ERROR] cSpell: Failed💡 Use Cases
- CI/CD Pipelines – Automate code quality checks in your workflows.
- Pre-Commit Hooks – Integrate with
huskyto enforce coding standards. - Local Development – Run linters before pushing code changes.
🤝 Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
