1 | @balena/lint
|
2 | ==========
|
3 |
|
4 | `@balena/lint` is a linter based on [coffeelint](https://github.com/clutchski/coffeelint),
|
5 | [coffeescope2](https://github.com/za-creature/coffeescope), [tslint](https://palantir.github.io/tslint/) and [prettier](https://github.com/prettier/prettier) to detect style errors based on balena.io coding guidelines.
|
6 |
|
7 | Overview
|
8 | --------
|
9 |
|
10 | `@balena/lint` uses balena's `coffeelint.json`, `tslint.json` and `.prettierrc`.
|
11 | If a `coffeelint.json` or `tslint.json` is found in the to-be-linted project
|
12 | directory or its parents then the rules found in it will be merged with the default `@balena/lint` ones.
|
13 | Another way to to override the default balena lint rules is by specifying a configuration
|
14 | file with the `-f` parameter.
|
15 |
|
16 | ## Typescript
|
17 |
|
18 | By default, only `.coffee` files will be linted. `.ts` and `.tsx` files can be
|
19 | linted by using the `--typescript` parameter.
|
20 |
|
21 | ## Prettier
|
22 |
|
23 | You can reference the prettier configuration file to your consumer project
|
24 | from `./config/.prettierrc`.
|
25 | You can disable the prettier format checks by using the `--no-prettier` parameter.
|
26 |
|
27 | Usage
|
28 | -----
|
29 |
|
30 | You can use this module as:
|
31 |
|
32 | 1. A standalone project by installing it with `npm install -g @balena/lint`:
|
33 |
|
34 | ```
|
35 | kostas@macbook:~/balena/test$ balena-lint src/
|
36 | ✓ src/test.coffee
|
37 |
|
38 | ✓ Ok! » 0 errors and 0 warnings in 1 file
|
39 | ```
|
40 |
|
41 | 2. A development dependency in `package.json` with ```npm install --save-dev @balena/lint```. Then
|
42 | you can use the module in your build/testing process:
|
43 |
|
44 | ```
|
45 | package.json
|
46 | ------------
|
47 | ...
|
48 | "scripts": {
|
49 | "lint": "balena-lint src/ && echo \"Done!\""
|
50 | },
|
51 | ...
|
52 |
|
53 | kostas@macbook:~/balena/test$ npm run lint
|
54 |
|
55 | > test@1.0.0 lint /Users/kostas/balena/test
|
56 | > balena-lint src/ && echo "Done!"
|
57 |
|
58 | ✓ src/test.coffee
|
59 |
|
60 | ✓ Ok! » 0 errors and 0 warnings in 1 file
|
61 |
|
62 | Done!
|
63 |
|
64 | ```
|
65 |
|
66 | 3. A development dependency, that will get picked up by your IDE/Editor coffeelint/tslint/prettier.
|
67 |
|
68 | Manually create these config files in your project root:
|
69 |
|
70 | `tslint.json`
|
71 |
|
72 | ```json
|
73 | // if using prettier in your project
|
74 | {
|
75 | "extends": [
|
76 | "balena-lint/config/tslint-prettier.json"
|
77 | ]
|
78 | }
|
79 |
|
80 | // plain TypeScript
|
81 | {
|
82 | "extends": [
|
83 | "balena-lint/config/tslint.json"
|
84 | ]
|
85 | }
|
86 | ```
|
87 |
|
88 | For coffeelint create `coffeelint.json`
|
89 |
|
90 | ```json
|
91 | {
|
92 | "extends": [
|
93 | "balena-lint/config/coffeelint.json"
|
94 | ]
|
95 | }
|
96 | ```
|
97 |
|
98 | For prettier config create `.prettierrc.js`
|
99 |
|
100 | ```js
|
101 | const fs = require('fs');
|
102 |
|
103 | module.exports = JSON.parse(fs.readFileSync('./node_modules/balena-lint/config/.prettierrc', 'utf8'));
|
104 | ```
|
105 |
|
106 | Support
|
107 | -------
|
108 |
|
109 | If you're having any problem, please [raise an issue](https://github.com/balena-io-modules/node-balena-lint/issues/new) on GitHub and the balena.io team will be happy to help.
|
110 |
|
111 | Tests
|
112 | -----
|
113 |
|
114 | Run the test suite by doing:
|
115 |
|
116 | ```sh
|
117 | $ npm install && npm test
|
118 | ```
|
119 |
|
120 | Contribute
|
121 | ----------
|
122 |
|
123 | - Issue Tracker: [github.com/balena-io-modules/node-balena-lint/issues](https://github.com/balena-io-modules/node-balena-lint/issues)
|
124 | - Source Code: [github.com/balena-io-modules/node-balena-lint](https://github.com/balena-io-modules/node-balena-lint)
|
125 |
|
126 | Before submitting a PR, please make sure that you include tests, and that `npm run lint` runs without a warning.
|
127 |
|
128 | License
|
129 | -------
|
130 |
|
131 | The project is licensed under the Apache 2.0 license.
|