|
1 | | -# eslint-plugin-logdna |
| 1 | +# `eslint-plugin-logdna` |
2 | 2 |
|
| 3 | +> ESlint plugin containing a collection of rules for enforcing code style at LogDNA |
| 4 | +
|
| 5 | +## Installation |
| 6 | + |
| 7 | +**Requires eslint also** |
| 8 | + |
| 9 | +We do not use peer dependencies, so make sure that `eslint` is also installed as a dev dependency. |
| 10 | + |
| 11 | +```shell |
| 12 | +npm install eslint-plugin-logdna eslint --save-dev |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Add `logdna` to the plugins section of your ESLint configuration. You can omit |
| 18 | +the `eslint-plugin-` prefix. Then you can configure the rules you want to use: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "plugins": [ |
| 23 | + "logdna" |
| 24 | + ], |
| 25 | + "rules": { |
| 26 | + "logdna/grouped-require": "error", |
| 27 | + "logdna/require-file-extension": "error", |
| 28 | + "logdna/tap-consistent-assertions": { |
| 29 | + "preferredMap": { |
| 30 | + "equal": "strictEqual" |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## Rules |
| 38 | + |
| 39 | +### `logdna/grouped-require` |
| 40 | + |
| 41 | +Enforce sorted require declarations within modules |
| 42 | + |
| 43 | +```js |
| 44 | +// Bad |
| 45 | +const foo = require('./lib/foo.js') //local |
| 46 | +const http = require('http') // builtin |
| 47 | +require('foo') // static |
| 48 | +const logger = require('@logdna/logger') // scoped |
| 49 | +const tap = require('tap') // contrib |
| 50 | + |
| 51 | +// Good |
| 52 | +require('foo') // static |
| 53 | +const http = require('http') // builtin |
| 54 | +const tap = require('tap') // contrib |
| 55 | +const logger = require('@logdna/logger') // scoped |
| 56 | +const foo = require('./lib/foo.js') //local |
| 57 | +``` |
| 58 | + |
| 59 | +#### Options |
| 60 | + |
| 61 | +* `typeOrder` [`<Array>`][] - sort order of require types |
| 62 | +(default: `['static', 'builtin', 'contrib', 'scoped', 'local']`) |
| 63 | + |
| 64 | +### `logdna/tap-consistent-assertions` |
| 65 | + |
| 66 | +Enforce consistent aliases for tap assertions |
| 67 | + |
| 68 | +```js |
| 69 | +// { |
| 70 | +// "plugins": [ |
| 71 | +// "logdna" |
| 72 | +// ], |
| 73 | +// "rules": { |
| 74 | +// "logdna/tap-consistent-assertions": { |
| 75 | +// "preferredMap": { |
| 76 | +// "equal": "strictEqual" |
| 77 | +// } |
| 78 | +// } |
| 79 | +// } |
| 80 | +// } |
| 81 | + |
| 82 | +// Bad |
| 83 | +test('foo', async (t) => { |
| 84 | + t.is_equal(1, 1) |
| 85 | + t.equal(1, 1) |
| 86 | + t.identical(1, 1) |
| 87 | +}) |
| 88 | + |
| 89 | +// Good |
| 90 | +test('foo', async (t) => { |
| 91 | + t.strictEqual(1, 1) |
| 92 | + t.strictEqual(1, 1) |
| 93 | + t.strictEqual(1, 1) |
| 94 | +}) |
| 95 | +``` |
| 96 | + |
| 97 | +#### Options |
| 98 | +* `preferredMap` [`<Object>`][] - maps the "primary" assertion method to the preferred alias |
| 99 | +* `calleePattern` [`<String>`][] - pattern to match for tap's `Test` object (default: `/^t+$/`) |
| 100 | + |
| 101 | +### `logdna/require-file-extension` |
| 102 | + |
| 103 | +Enforce file extension for local modules/files |
| 104 | + |
| 105 | +```js |
| 106 | +// Bad |
| 107 | +const foo = require('./lib/foo') |
| 108 | + |
| 109 | +// Good |
| 110 | +const foo = require('./lib/foo.js') |
| 111 | +``` |
| 112 | + |
| 113 | +## License |
| 114 | + |
| 115 | +Copyright © [LogDNA](https://logdna.com), released under an MIT license. See the [LICENSE](./LICENSE) file and https://opensource.org/licenses/MIT |
| 116 | + |
| 117 | +*Happy Logging!* |
| 118 | + |
| 119 | +[`<Object>`]: https://mdn.io/object |
| 120 | +[`<String>`]: https://mdn.io/string |
| 121 | +[`<Array>`]: https://mdn.io/array |
0 commit comments