Files
NapCatQQ/.pnpm-store/v3/files/ab/35c5a15b91a1f40858b31df3026d1d8f5c14be9aa4e339c0c49efa775588f06e8ba0ffcca3e1b4954a0ee4a976fdb696d51a112bfa30364f6abc6fa85db806
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

49 lines
1.5 KiB
Plaintext

import { createRule } from '../utils/index.js';
const findLastIndex = (array, predicate) => {
let i = array.length - 1;
while (i >= 0) {
if (predicate(array[i])) {
return i;
}
i--;
}
return -1;
};
function isNonExportStatement({ type }) {
return (type !== 'ExportDefaultDeclaration' &&
type !== 'ExportNamedDeclaration' &&
type !== 'ExportAllDeclaration');
}
export default createRule({
name: 'exports-last',
meta: {
type: 'suggestion',
docs: {
category: 'Style guide',
description: 'Ensure all exports appear after other statements.',
},
schema: [],
messages: {
end: 'Export statements should appear at the end of the file',
},
},
defaultOptions: [],
create(context) {
return {
Program({ body }) {
const lastNonExportStatementIndex = findLastIndex(body, isNonExportStatement);
if (lastNonExportStatementIndex !== -1) {
for (const node of body.slice(0, lastNonExportStatementIndex)) {
if (!isNonExportStatement(node)) {
context.report({
node,
messageId: 'end',
});
}
}
}
},
};
},
});
//# sourceMappingURL=exports-last.js.map