One linter to rule them all.
Metalint is a tool for analyzing all the files in your project. Analysis is delegated to linters (static source code analysis tools):
Language / Technology | Linters |
---|---|
CoffeeScript | CoffeeLint |
CSS | DoIUse, Prettier, PurgeCSS, Stylelint |
HTML | HTMLHint, htmllint, markuplint, Prettier |
JavaScript | ESLint, JSHint, JavaScript Standard Style, Prettier |
JSON | Ajv, @mapbox/JSON Lint lines-primitives, @prantlf/JSON Lint, JSON Lint (mod), Prettier |
Less | Prettier, Stylelint |
Markdown | MarkdownLint |
package.json | Depcheck, npm-check-updates, npm-package-json-lint, publint, Sort Package.json |
SCSS | Prettier, Stylelint |
SugarSS | Stylelint |
SVG | Prettier, SVGLint |
WebExtension | Add-ons Linter |
YAML | YAML Lint, Prettier |
Secretlint |
You can install Metalint using npm:
npm install --save-dev metalint
All configuration files are grouped together in the .metalint/
directory,
which should be placed at the root of the project. The metalint.config.js
file
exports a JSON object indicating the linters to be used for each file. The other
files contain the specific options for the linters.
In this example of configuration files, Metalint analyzes JavaScript (non-minified), HTML and CSS files; with ESLint, HTMLHint and Stylelint linters respectively.
// .metalint/metalint.config.js
export default {
patterns: ["**", "!/.git/**", "!/node_modules/**"],
checkers: [
{
patterns: ["*.js", "!*.min.js"],
linters: "eslint",
},
{
patterns: "*.html",
linters: "htmlhint",
},
{
patterns: "*.css",
linters: "stylelint",
},
],
};
// .metalint/eslint.config.js
export default {
rules: {
quotes: ["error", "double"],
semi: ["error", "always"],
},
};
// .metalint/htmlhint.config.js
export default {
"attr-value-not-empty": false,
};
// .metalint/stylelint.config.js
export default {
rules: {
"color-no-invalid-hex": true,
},
};
If you want to see real configurations, you've got the Metalint configuration itself; or the Cast Kodi configuration (a browser WebExtension developed in JavaScript, HTML, CSS).
After installing Metalint and the linters in your npm project, you can add the
following script to your package.json
:
{
"scripts": {
"lint": "metalint",
"lint:fix": "metalint --fix"
}
}
Metalint can now be used with the following commands: npm run lint
and
npm run lint:fix
.
To launch Metalint in your GitHub Actions, you can use the github
formatter to
report problems in pull requests.
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
- name: Install dependencies
run: npm ci
- name: Lint files
run: npm run lint -- --formatter github