UNPKG

7.9 kBMarkdownView Raw
1# Metalint
2
3<!-- Utiliser du HTML (avec l'attribut "align" obsolète) pour faire flotter
4 l'image à droite. -->
5<!-- markdownlint-disable-next-line no-inline-html-->
6<img src="asset/logo.svg" align="right" alt="">
7
8[![npm][img-npm]][link-npm]
9[![build][img-build]][link-build]
10[![coverage][img-coverage]][link-coverage]
11[![semver][img-semver]][link-semver]
12
13> _Un linter pour les gouverner tous._
14
15## Description
16
17**Metalint** est un outil pour analyser tous les fichiers de votre projet.
18L'analyse est déléguée à des linters (outils d'analyse statique de code
19source) :
20
21<!-- markdownlint-disable no-inline-html -->
22<table>
23 <tr>
24 <th>Langage / Technologie</th>
25 <th>Linters</th>
26 </tr>
27 <tr>
28 <td>CoffeeScript</td>
29 <td>
30 <a title="@coffeelint/cli"
31 href="https://www.npmjs.com/package/@coffeelint/cli">CoffeeLint</a>
32 </td>
33 </tr>
34 <tr>
35 <td>CSS</td>
36 <td>
37 <a title="csslint"
38 href="https://www.npmjs.com/package/csslint">CSSLint</a>,
39 <a title="doiuse" href="https://www.npmjs.com/package/doiuse">DoIUse</a>,
40 <a title="prettier"
41 href="https://www.npmjs.com/package/prettier">Prettier</a>,
42 <a title="purgecss"
43 href="https://www.npmjs.com/package/purgecss">PurgeCSS</a>,
44 <a title="stylelint"
45 href="https://www.npmjs.com/package/stylelint">Stylelint</a>
46 </td>
47 </tr>
48 <tr>
49 <td>HTML</td>
50 <td>
51 <a title="htmlhint"
52 href="https://www.npmjs.com/package/htmlhint">HTMLHint</a>,
53 <a title="htmllint"
54 href="https://www.npmjs.com/package/htmllint">htmllint</a>,
55 <a title="markuplint"
56 href="https://www.npmjs.com/package/markuplint">markuplint</a>,
57 <a title="prettier"
58 href="https://www.npmjs.com/package/prettier">Prettier</a>
59 </td>
60 </tr>
61 <tr>
62 <td>JavaScript</td>
63 <td>
64 <a title="eslint" href="https://www.npmjs.com/package/eslint">ESLint</a>,
65 <a title="jshint" href="https://www.npmjs.com/package/jshint">JSHint</a>,
66 <a title="standard"
67 href="https://www.npmjs.com/package/standard">JavaScript Standard
68 Style</a>,
69 <a title="prettier"
70 href="https://www.npmjs.com/package/prettier">Prettier</a>
71 </td>
72 </tr>
73 <tr>
74 <td>JSON</td>
75 <td>
76 <a title="ajv" href="https://www.npmjs.com/package/ajv">Ajv</a>,
77 <a title="@prantlf/jsonlint"
78 href="https://www.npmjs.com/package/@prantlf/jsonlint">@prantlf/JSON
79 Lint</a>,
80 <a title="jsonlint-mod"
81 href="https://www.npmjs.com/package/jsonlint-mod">JSON Lint (mod)</a>,
82 <a title="prettier"
83 href="https://www.npmjs.com/package/prettier">Prettier</a>
84 </td>
85 </tr>
86 <tr>
87 <td>Less</td>
88 <td>
89 <a title="prettier"
90 href="https://www.npmjs.com/package/prettier">Prettier</a>,
91 <a title="stylelint"
92 href="https://www.npmjs.com/package/stylelint">Stylelint</a>
93 </td>
94 </tr>
95 <tr>
96 <td>Markdown</td>
97 <td>
98 <a title="markdownlint"
99 href="https://www.npmjs.com/package/markdownlint">MarkdownLint</a>
100 </td>
101 </tr>
102 <tr>
103 <td>package.json</td>
104 <td>
105 <a title="depcheck"
106 href="https://www.npmjs.com/package/depcheck">Depcheck</a>,
107 <a title="npm-check-updates"
108 href="https://www.npmjs.com/package/npm-check-updates"
109 >npm-check-updates</a>,
110 <a title="npm-package-json-lint"
111 href="https://www.npmjs.com/package/npm-package-json-lint"
112 >npm-package-json-lint</a>,
113 <a title="publint"
114 href="https://www.npmjs.com/package/publint">publint</a>,
115 <a title="sort-package-json"
116 href="https://www.npmjs.com/package/sort-package-json">Sort
117 Package.json</a>
118 </td>
119 </tr>
120 <tr>
121 <td>SCSS</td>
122 <td>
123 <a title="prettier"
124 href="https://www.npmjs.com/package/prettier">Prettier</a>,
125 <a title="stylelint"
126 href="https://www.npmjs.com/package/stylelint">Stylelint</a>
127 </td>
128 </tr>
129 <tr>
130 <td>SugarSS</td>
131 <td>
132 <a title="stylelint"
133 href="https://www.npmjs.com/package/stylelint">Stylelint</a>
134 </td>
135 </tr>
136 <tr>
137 <td>SVG</td>
138 <td>
139 <a title="prettier"
140 href="https://www.npmjs.com/package/prettier">Prettier</a>,
141 <a title="svglint"
142 href="https://www.npmjs.com/package/svglint">SVGLint</a>
143 </td>
144 </tr>
145 <tr>
146 <td>WebExtension</td>
147 <td>
148 <a title="addons-linter"
149 href="https://www.npmjs.com/package/addons-linter">Add-ons Linter</a>
150 </td>
151 </tr>
152 <tr>
153 <td>YAML</td>
154 <td>
155 <a title="yaml-lint"
156 href="https://www.npmjs.com/package/yaml-lint">YAML Lint</a>,
157 <a title="prettier"
158 href="https://www.npmjs.com/package/prettier">Prettier</a>
159 </td>
160 </tr>
161</table>
162<!-- markdownlint-enable no-inline-html -->
163
164## Installation
165
166Vous pouvez installer Metalint en utilisant [npm][link-npm] :
167
168```Shell
169npm install --save-dev --save-exact metalint
170```
171
172## Configuration
173
174Tous les fichiers de configuration sont à regrouper dans le répertoire
175`.metalint/` qui doit être placé à la racine du projet. Le fichier
176`metalint.config.js` export un objet JSON indiquant les linters à utiliser pour
177chaque fichier. Les autres fichiers contiennent les options spécifiques pour les
178linters.
179
180## Exemple
181
182Dans cet exemple des fichiers de configuration, Metalint analyse les fichiers
183JavaScript (non-minifiés), HTML et CSS ; avec respectivement les linters ESLint,
184HTMLHint et Stylelint.
185
186```JavaScript
187// .metalint/metalint.config.js
188export default {
189 patterns: ["**", "!/.git/**", "!/node_modules/**"],
190 checkers: [
191 {
192 patterns: ["*.js", "!*.min.js"],
193 linters: "eslint",
194 }, {
195 patterns: "*.html",
196 linters: "htmlhint",
197 }, {
198 patterns: "*.css",
199 linters: "stylelint",
200 },
201 ],
202};
203```
204
205```JavaScript
206// .metalint/eslint.config.js
207export default {
208 rules: {
209 quotes: ["error", "double"],
210 semi: ["error", "always"],
211 },
212};
213```
214
215```JavaScript
216// .metalint/htmlhint.config.js
217export default {
218 "attr-value-not-empty": false,
219};
220```
221
222```JavaScript
223// .metalint/stylelint.config.js
224export default {
225 rules: {
226 "color-no-invalid-hex": true,
227 },
228};
229```
230
231## Intégration
232
233### npm
234
235Après avoir installé Metalint et les linters dans votre projet npm, vous pouvez
236ajouter le script suivant dans votre `package.json` :
237
238```JSON
239{
240 "scripts": {
241 "lint": "metalint"
242 }
243}
244```
245
246Metalint est maintenant utilisable avec la commande : `npm run lint`
247
248### GitHub Actions
249
250Pour lancer Metalint dans vos GitHub Actions, vous pouvez utiliser le formateur
251`github` pour rapporter les problèmes dans les pull requests.
252
253```YAML
254jobs:
255 lint:
256 runs-on: ubuntu-latest
257 steps:
258 - uses: actions/setup-node@v4
259 - uses: actions/checkout@v4
260 with:
261 persist-credentials: false
262 - name: Install dependencies
263 run: npm ci
264 - name: Lint files
265 run: npm run lint -- --formatter github
266```
267
268[img-npm]: https://img.shields.io/npm/dm/metalint?label=npm&logo=npm&logoColor=whitesmoke
269[img-build]: https://img.shields.io/github/actions/workflow/status/regseb/metalint/ci.yml?branch=main&logo=github&logoColor=whitesmoke
270[img-coverage]: https://img.shields.io/endpoint?label=coverage&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fregseb%2Fmetalint%2Fmain
271[img-semver]: https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&logoColor=whitesmoke
272[link-npm]: https://www.npmjs.com/package/metalint
273[link-build]: https://github.com/regseb/metalint/actions/workflows/ci.yml?query=branch%3Amain
274[link-coverage]: https://dashboard.stryker-mutator.io/reports/github.com/regseb/metalint/main
275[link-semver]: https://semver.org/spec/v2.0.0.html "Semantic Versioning 2.0.0"