β¬ οΈ Back to Table of Contents
π no-useless-empty-export¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 3 |
| π¦ Imports | 4 |
| π Variables & Constants | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/rules/no-useless-empty-export.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'no-useless-empty-export' |
meta.type |
'suggestion' |
meta.docs.description |
"Disallow empty exports that don't change anything in a module file" |
meta.fixable |
'code' |
meta.hasSuggestions |
false |
meta.messages.uselessExport |
'Empty export does nothing and can be removed.' |
meta.schema |
[] |
defaultOptions |
[] |
Entry point: create β documented under Functions.
π¦ Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
createRule |
../util |
isDefinitionFile |
../util |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
exportOrImportNodeTypes |
Set<any> |
const | new Set([ AST_NODE_TYPES.ExportAllDeclaration, AST_NODE_TYPES.ExportDefaultDe... |
β |
Functions¶
create(context: any): { Program?: undefined; TSModuleDeclaration?: undefined; } |⦶
Parameters:
contextany
Returns: { Program?: undefined; TSModuleDeclaration?: undefined; } | { Program: (node: TSESTree.Program | TSESTree.TSModuleDeclaration) => void; TSModuleDeclaration: (node: TSESTree.Program | TSESTree.TSModuleDeclaration) => void; }
Calls:
isDefinitionFile (from ../util)Array.isArrayisEmptyExportemptyExports.pushexportOrImportNodeTypes.hascontext.reportfixer.remove
Internal Comments:
// In a definition file, export {} is necessary to make the module properly
// encapsulated, even when there are other exports
// https://github.com/typescript-eslint/typescript-eslint/issues/4975
Code
create(context) {
// In a definition file, export {} is necessary to make the module properly
// encapsulated, even when there are other exports
// https://github.com/typescript-eslint/typescript-eslint/issues/4975
if (isDefinitionFile(context.filename)) {
return {};
}
function checkNode(
node: TSESTree.Program | TSESTree.TSModuleDeclaration,
): void {
if (!Array.isArray(node.body)) {
return;
}
const emptyExports: TSESTree.ExportNamedDeclaration[] = [];
let foundOtherExport = false;
for (const statement of node.body) {
if (isEmptyExport(statement)) {
emptyExports.push(statement);
} else if (exportOrImportNodeTypes.has(statement.type)) {
foundOtherExport = true;
}
}
if (foundOtherExport) {
for (const emptyExport of emptyExports) {
context.report({
node: emptyExport,
messageId: 'uselessExport',
fix: fixer => fixer.remove(emptyExport),
});
}
}
}
return {
Program: checkNode,
TSModuleDeclaration: checkNode,
};
}
isEmptyExport(node: TSESTree.Node): node is TSESTree.ExportNamedDeclaration¶
Parameters:
nodeTSESTree.Node
Returns: node is TSESTree.ExportNamedDeclaration
Code
Internal helpers¶
Declared inside another function in this file.
checkNode(node: TSESTree.Program | TSESTree.TSModuleDecβ¦): void¶
Parameters:
nodeTSESTree.Program | TSESTree.TSModuleDeclaration
Returns: void
Calls:
Array.isArrayisEmptyExportemptyExports.pushexportOrImportNodeTypes.hascontext.reportfixer.remove
Code
function checkNode(
node: TSESTree.Program | TSESTree.TSModuleDeclaration,
): void {
if (!Array.isArray(node.body)) {
return;
}
const emptyExports: TSESTree.ExportNamedDeclaration[] = [];
let foundOtherExport = false;
for (const statement of node.body) {
if (isEmptyExport(statement)) {
emptyExports.push(statement);
} else if (exportOrImportNodeTypes.has(statement.type)) {
foundOtherExport = true;
}
}
if (foundOtherExport) {
for (const emptyExport of emptyExports) {
context.report({
node: emptyExport,
messageId: 'uselessExport',
fix: fixer => fixer.remove(emptyExport),
});
}
}
}
Generated by Syntax Scribe