eslint-plugin-typescript
Version:
TypeScript plugin for ESLint
47 lines (40 loc) • 1.51 kB
JavaScript
/**
* @fileoverview Disallows the declaration of empty interfaces.
* @author Patricio Trevino
*/
;
const util = require("../util");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: "Disallow the declaration of empty interfaces",
extraDescription: [util.tslintRule("no-empty-interface")],
category: "TypeScript",
url:
"https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-empty-interface.md"
},
schema: []
},
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
create(context) {
return {
TSInterfaceDeclaration(node) {
const heritage = node.heritage.length;
if (node.body.body.length === 0 && heritage < 2) {
context.report({
node: node.id,
message:
heritage === 0
? "An empty interface is equivalent to `{}`"
: "An interface declaring no members is equivalent to its supertype."
});
}
}
};
}
};