Path: blob/main/src/rules/exports-last.js
829 views
import docsUrl from '../docsUrl';12function isNonExportStatement({ type }) {3return type !== 'ExportDefaultDeclaration' &&4type !== 'ExportNamedDeclaration' &&5type !== 'ExportAllDeclaration';6}78module.exports = {9meta: {10type: 'suggestion',11docs: {12url: docsUrl('exports-last'),13},14schema: [],15},1617create(context) {18return {19Program({ body }) {20const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {21if (isNonExportStatement(item)) {22return index;23}24return acc;25}, -1);2627if (lastNonExportStatementIndex !== -1) {28body.slice(0, lastNonExportStatementIndex).forEach(function checkNonExport(node) {29if (!isNonExportStatement(node)) {30context.report({31node,32message: 'Export statements should appear at the end of the file',33});34}35});36}37},38};39},40};414243