Skip to content

Refactor util.js #73

@macklinu

Description

@macklinu

Various rule files consume util.js by requiring the file multiple times:

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions