ESlint plugin containing a collection of rules for enforcing code style at LogDNA
- ESLint >= 9.0.0
Requires eslint also
We do not use peer dependencies, so make sure that eslint is also installed as a dev dependency.
npm install eslint-plugin-logdna eslint --save-devImport the plugin and use it in your flat config:
// eslint.config.js
const logdna = require('eslint-plugin-logdna')
module.exports = [
{
plugins: {
logdna
},
rules: {
'logdna/grouped-require': 'error',
'logdna/require-file-extension': 'error',
'logdna/tap-no-deprecated-aliases': 'error'
}
}
]Or use the recommended configuration:
// eslint.config.js
const logdna = require('eslint-plugin-logdna')
module.exports = [
logdna.configs.recommended
]Enforce sorted require declarations within modules
// Bad
const foo = require('./lib/foo.js') //local
const http = require('http') // builtin
require('foo') // static
const logger = require('@logdna/logger') // scoped
const tap = require('tap') // contrib
// Good
require('foo') // static
const http = require('http') // builtin
const tap = require('tap') // contrib
const logger = require('@logdna/logger') // scoped
const foo = require('./lib/foo.js') //localtypeOrder<Array>- sort order of require types (default:['static', 'builtin', 'contrib', 'scoped', 'local'])
Prevent usage of deprecated tap aliases (>= [email protected])
Tap deprecated assertion aliases as of version 15.0.0.
This rule supersedes logdna/tap-consistent-assertions and will enforce the use of unaliased
assertion methods.
// Bad
test('foo', async (t) => {
t.is_equal(1, 1)
t.strictEqual(1, 1)
t.identical(1, 1)
})
// Good
test('foo', async (t) => {
t.equal(1, 1)
t.equal(1, 1)
t.equal(1, 1)
})calleePattern<String>- pattern to match for tap'sTestobject (default:/^t+$/)
Enforce consistent aliases for tap assertions
// eslint.config.js
const logdna = require('eslint-plugin-logdna')
module.exports = [
{
plugins: {
logdna
},
rules: {
'logdna/tap-consistent-assertions': ['error', {
preferredMap: {
equal: 'strictEqual'
}
}]
}
}
]
// Bad
test('foo', async (t) => {
t.is_equal(1, 1)
t.equal(1, 1)
t.identical(1, 1)
})
// Good
test('foo', async (t) => {
t.strictEqual(1, 1)
t.strictEqual(1, 1)
t.strictEqual(1, 1)
})preferredMap<Object>- maps the "primary" assertion method to the preferred aliascalleePattern<String>- pattern to match for tap'sTestobject (default:/^t+$/)
Enforce file extension for local modules/files
// Bad
const foo = require('./lib/foo')
// Good
const foo = require('./lib/foo.js')Thanks goes to these wonderful people (emoji key):
Mike Del Tito 💻 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Copyright © LogDNA, released under an MIT license. See the LICENSE file and https://opensource.org/licenses/MIT
Happy Logging!