eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Require/first rule ?

Open edi9999 opened this issue 1 year ago • 1 comments

Hello,

I have following code :

const Docxtemplater = require("docxtemplater");
const {
	xml2str,
	str2xml,
	traits,
	chunkBy,
	isParagraphStart,
	isParagraphEnd,
	isContent,
} = require("docxtemplater").DocUtils;
const { ensureDirectChild, dropTags } = require("./xml-utils.js");

const createScope = require("docxtemplater/js/scope-manager.js");
const normalizePath = require("./normalize-path.js");

const ELEMENT_NODE = 1;

function getExtension(path) {
	return path.replace(/[^.]+\.([^.]+)/, "$1");
}

const Pizzip = require("pizzip");

I wanted to fix it by placing all require before other code, however, when I used the "import/first" rule, it didn't seem to apply to the require calls.

Do you have any other rules or would you be open to have the import/first rule also apply to require ?

Best,

Edgar

edi9999 avatar Jul 12 '24 07:07 edi9999

The usual reason to have imports first is that they’re hoisted there anyways - it’s not meant to be a style choice.

That said, i think it’d be reasonable to add an option that allows it to apply to top-level requires also.

ljharb avatar Jul 12 '24 15:07 ljharb