-
Notifications
You must be signed in to change notification settings - Fork 243
Closed
Description
Various rule files consume util.js by requiring the file multiple times:
eslint-plugin-jest/rules/prefer-to-have-length.js
Lines 2 to 6 in 38f8ca0
| const expectCase = require('./util').expectCase; | |
| const expectNotCase = require('./util').expectNotCase; | |
| const expectResolveCase = require('./util').expectResolveCase; | |
| const expectRejectCase = require('./util').expectRejectCase; | |
| const method = require('./util').method; |
I'm wondering if we could clean this up, either by how we require the files, or how we organize these util methods. Some options I can think of:
// require the util file once
const util = require('./util')
// use methods in the util namespace
util.expectCase()
util.expectNotCase()or:
// extract functions out into their own files
const expectCase = require('./lib/expect-case')
const expectNotCase = require('./lib/expect-not-case')I also wonder if we could have more specifically named util files, like is.js, which exports functions that take a node and return a boolean:
// is.js
function isFunction(node) {
// ...
}
function isDescribe(node) {
// ...
}
module.exports = {
function: isFunction,
describe: isDescribe,
}
// usage in another file
const is = require('./is')
if (is.describe(node)) {
// do something
}I'm just throwing out a few ideas that have different levels of difficulty in terms of the refactoring involved. Wondering what you think about these, if it's time to refactor any part of this, and (if so) how we can help make that happen. 👍
Metadata
Metadata
Assignees
Labels
No labels